whitehole
A simple, fast, intuitive parser combinator framework for Rust.
Features
- Simple: only a handful of combinators to remember:
eat,take,next,till,wrap,recur. - Operator overloading: use
+and|to compose combinators, use*to repeat a combinator. - Almost zero heap allocation: this framework only uses stack memory, except
recurwhich uses some pointers for recursion. - Re-usable heap memory: store accumulated values in a parser-managed heap, instead of re-allocation for each iteration.
- Stateful-able: control the parsing flow with an optional custom state.
- Safe by default, with
unsafevariants for performance. - Provide both string (
&str) and bytes (&[u8]) support.
Installation
Examples
See the examples directory for more examples.
Here is a simple example to parse hexadecimal color codes:
use ;
let double_hex = ;
// Concat multiple combinators with `+`.
// Tuple values will be concatenated into a single tuple.
// Here `() + (u8,) + (u8,) + (u8,)` will be `(u8, u8, u8)`.
let entry = eat + double_hex + double_hex + double_hex;
let mut parser = builder.entry.build;
let output = parser.next.unwrap;
assert_eq!;
assert_eq!;
Documentation
See docs.rs.
It's recommended to starts from the combinator chapter.
Benchmarks
Related
in_str: a procedural macro to generate a closure that checks if a character is in the provided literal string.
Credits
This project is inspired by: