pest is a general purpose parser written in Rust with a focus on accessibility, correctness, and performance. It uses parsing expression grammars (or PEG) as input, which are similar in spirit to regular expressions, but which offer the enhanced expressivity needed to parse complex languages.
The recommended way to start parsing with pest is to read the official book.
Other helpful resources:
- API reference on docs.rs
- play with grammars and share them on our fiddle
- leave feedback, ask questions, or greet us on Gitter
The core of pest is the trait
Parser, which provides an interface to the parsing
Grammar definitions reside in custom
.pest files located in the crate
Parsers are automatically generated from these files using
#[derive(Parser)] and a special
#[grammar = "..."] attribute on a dummy struct.
#[derive(Parser)] #[grammar = "path/to/my_grammar.pest"] // relative to src struct MyParser;
The syntax of
.pest files is documented in the
Grammars can also be inlined by using the
#[grammar_inline = "..."] attribute.
Types for different kinds of parsing failures.
Types and iterators for parser output.
Constructs useful in infix operator parsing with the precedence climbing method.
Testing tool that compares produced errors.
Testing tool that compares produced tokens.
A cursor position in a
&str which provides useful methods to manually parse that string.
Match direction for the stack. Used in
A token generated by a
A trait with a single method that parses strings.
A trait which parser rules must implement.
Sets the maximum call limit for the parser state to prevent stack overflows or excessive execution times in some grammars. If set, the calls are tracked as a running total over all non-terminal rules that can nest closures (which are passed to transform the parser state).
ParserState from a
&str, supplying it to a closure
Type alias to simplify specifying the return value of chained closures.