pest is a PEG parser generator with simplicity and speed in mind.
Documentation
Elegant
pest uses PEG syntax to enable expressive grammar creation.
impl_rdp!
let mut parser = new);
assert!;
assert!;
Fast
pest generates a fast parser at compile time through the use of macros, without forcing you to use nightly. Yes, it works on stable (1.9.0+).
| Parser generator | Time to parse 272.5 KB of JSON | pest speedup |
|---|---|---|
| ANTRL 4 | 153,000 μs (+/- 15,000) | 48.12x |
| Bison + Flex | 8,761.9 μs (+/- 697) | 2.76x |
| pest | 3,178.9 μs (+/- 40.6) | 1.00x |
Tests have been run on an Intel Q8200, 4GB DDR2, Linux 4.6.2 as follows:
- ANTLR 4 [JSON grammar] (https://github.com/antlr/grammars-v4/blob/master/json/JSON.g4) measured with JMH SingleShotTime
- Bison + Flex JSON grammar with string capturing and printing removed
- pest JSON grammar measured with
cargo bench
Features
- simple PEG grammar
- smart error reporting with
atomicandsilentrules - precedence climbing rule
- no generation step (one-step compilation)
- fast macro-generated recursive descent parser
- runs on stable Rust
- elegant functional-style
Tokenprocessing
Comparison
Short comparison with other parsing tools. Please take into consideration that pest is the youngest among them, but is continuously improving.
| nom | LALRPOP | pest | |
|---|---|---|---|
| type | combinator | generator | generator (macros) |
| goals | speed, extensibility | usability | simplicity, speed |
| grammar | specialized | LR(1) / LALR(1) | PEG |
| steps | 1 | 2 | 1 |
| code | separate / mixed | mixed | separate |
| extensibility | great | great | little |
| great for | binary formats | any text | languages |
| error reporting | yes | yes | yes |
| GitHub additions | ~10K | ~500K | ~6K |