pest
The elegant general-purpose Rust parser built on parsing expression grammars (PEG)
Repository Health
Technical Analysis
pest is a general-purpose parser for Rust with a focus on accessibility, correctness, and performance. It uses parsing expression grammars (PEGs) as input, which are similar in spirit to regular expressions but offer the enhanced expressivity needed to parse complex languages.
Grammars are written in a dedicated .pest file and compiled at build time by the companion pest_derive procedural macro, which generates a strongly typed parser from your rules. The runtime pest crate then produces an iterator of tokens and pairs you can walk to build ASTs, interpreters, config loaders, and more.
What You Get
- A general-purpose PEG parser with a readable, dedicated grammar syntax
- A
pest_derivemacro that generates a typed parser from a.pestfile at compile time - Iterators over
Pairs/Pairwith precise spans and positions for error reporting - Built-in helpers like a Pratt parser and precedence climber for expressions
- no_std support and optional features for pretty-printing and miette-style errors
Common Use Cases
- Building parsers for domain-specific languages and configuration formats
- Implementing interpreters or compilers that need a clear, maintainable grammar
- Parsing structured text into typed ASTs for further processing
- Prototyping language grammars quickly using the online pest fiddle
Under The Hood
Architecture - The workspace splits responsibilities across crates: the runtime pest/ crate provides Parser, ParserState, Position, Span, and the Pairs/Pair token iterators in src/lib.rs and neighboring modules; derive/ and generator/ implement the pest_derive proc-macro that reads a .pest grammar and emits a typed parser; meta/ validates and optimizes grammars; and vm/, debugger/, and grammars/ support tooling and reuse. At parse time your generated rules drive a ParserState that walks the input with backtracking, producing a flat token stream you re-materialize as a nested pair tree.
Tech Stack - Pure Rust (2021 edition, rustc 1.83+), dual-licensed MIT OR Apache-2.0. The runtime depends on ucd-trie for Unicode character classes and optional memchr, serde/serde_json (pretty-print), and miette (rich errors). The derive side pulls in syn, quote, and proc-macro2. Extensive helper modules cover Pratt parsing and precedence climbing.
Code Quality - pest is a mature, heavily used project (hundreds of millions of downloads) with strong CI, code coverage, fuzzing (see FUZZING.md), a security policy, and a large contributor base. Grammar handling is factored into dedicated meta/generator/vm crates, and the codebase is well documented against the official pest book.
API Design - The headline ergonomic win is separating grammar from code: you write rules in a .pest file, derive a parser, and consume Pairs with spans that line up with your rules. The API favors clarity and good error messages over raw combinator flexibility, making it approachable for newcomers while scaling to full language grammars.