marser
marser is a parser-combinator library for writing PEG-style grammars in Rust with a focus on useful errors, error recovery and good performance.
It supports:
- Zero-copy parsing for faster parsers
-
Multiple input formats - use
&strand&[u8]/&[T]or implement theInputtrait yourself. -
Packrat-style caching - just wrap your parsers in
.memoized()to cache results at each position. - Simple debugging of your parsers using a custom TUI
Quickstart
To add this library to your Rust project run:
cargo add marser
This library has a couple of optional features. You can find them below.
Example
This example parses dice notation like 2d6 into a struct:
use marser::capture;
use marser::matcher::one_or_more;
use marser::parser::Parser;
// the struct we want to parse into
struct Roll {
count: u32,
sides: u32,
}
// A parser…