High-level static analysis and careful low-level implementation build a solid foundation on which serious performance tuning is possible.

Grammars offer better correctness guarantees, and issues can be solved declaratively in the grammar itself. Rust's memory safety further limits the amount of damage bugs can do.

Grammar-generated parsers are both easier to use and maintain than their hand-written counterparts.

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.

Example

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:

alpha = { 'a' .. 'z' | 'A' .. 'Z' } digit = { '0' .. '9' } ident = { ( alpha | digit ) + } ident_list = _ { ! digit ~ ident ~ ( " " ~ ident ) + }

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:

thread 'main' panicked at ' --> 1:1 1 123 = unexpected digit ', src/main.rs:12

while "ab *" will result in: