YAPCoL
Yet Another Parser Combinator Library.
yapcol is a flexible and simple-to-use parser combinator library for Rust. It allows you to build complex parsers by
combining smaller, simpler ones. The library is designed to be easy to understand and use, while still providing
powerful features like arbitrary lookahead and nested parsers.
Features
- Arbitrary Lookahead: easily backtrack and try alternative parsers using
attemptandlook_ahead. - Generic Input: works with any iterator whose items implement the
Tokentrait. - Zero Dependencies:
yapcolhas no dependencies besides Rust's standard library.
Supported Combinators
yapcol provides a wide range of built-in combinators:
- Basic:
is,satisfy,any,end_of_input. - Choice and Optional:
choice,option,maybe. - Repetition:
many0,many1,count,many_until,separated_by0,separated_by1. - Lookahead and Backtracking:
attempt,look_ahead,not_followed_by. - Grouping:
between. - Associativity:
chain_left,chain_right.
Usage
Using Combinators
The most convenient approach to YAPCoL is to use the built-in combinators to create your parsers:
use Input;
use ;
let input = new;
// Combine 'is' and 'many0' to parse multiple 'a's
let is_a = is;
let mut parser = many0;
let result = parser;
assert_eq!;
Using Custom Parsers
You might also define your own custom parsers as functions. Any function of the following Fn trait
automatically implements the Parser trait:
Fn
For example:
use Input;
use Error;
use is;
let mut input = new;
assert_eq!;
Examples
Real-world examples are available in the examples/ directory, including an arithmetic expression evaluator. There are
two different implementations:
- String-based: parses text directly from a stream of characters.
- Token-based: sses a lexer to tokenize the input before parsing.
For more details on how to run and understand these examples, check the Examples README.
Contributing
If you would like to report a bug, please create an issue. If you would like to contribute with bug fixing or small improvements, please open a Pull Request. If you would like to contribute with a new feature (regardless if it's in the roadmap or not), contact the developer.
License
YAPCoL is distributed under the terms of the MIT license. For more information, check the LICENSE file in this repository.