pest. The Elegant Parser
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 following is an example of a grammar for a list of alpha-numeric identifiers where the first identifier does not start with a digit:
Grammars are saved in separate .pest files which are never mixed with procedural code. This results in an always up-to-date formalization of a language that is easy to read and maintain.
Meaningful error reporting
Based on the grammar definition, the parser also includes automatic error
reporting. For the example above, the input
"123" will result in:
"ab *" will result in:
The grammar can be used to derive a
Parser implementation automatically.
Parsing returns an iterator of nested token pairs:
This produces the following output:
- Precedence climbing
- Input handling
- Custom errors
- Runs on stable Rust
Projects using pest
- pest_meta (bootstrapped)
- caith (a dice roller crate)
A special round of applause goes to prof. Marius Minea for his guidance and all pest contributors, some of which being none other than my friends.