13 releases (5 breaking)
Uses new Rust 2024
| 0.6.1 | Jun 1, 2026 |
|---|---|
| 0.6.0 | Jun 1, 2026 |
| 0.5.2 | May 25, 2026 |
| 0.4.0 | May 22, 2026 |
| 0.1.3 | May 21, 2026 |
#520 in Programming languages
70KB
595 lines
vpratt
If you can read a precedence table, you can write a parser.
vpratt is a product of pushing Vaughan Pratt's 1973 algorithm to its very limits to fully harness its potential for modern applications.
Where most implementations stop at simple arithmetic, vpratt keeps going — structural constructs, juxtaposition, enclosed expressions, complex grammars — all handled natively, without leaving the safety of the framework.
Not all grammars are purely precedence-based, so how do you parse bindings, conditionals or a list of arguments?
That is where recursive descent parsers excel and Pratt parsers stall.
vpratt bridges the two, allowing you to design and implement virtually any expression-based language and DSL natively, courtesy of the ancient algorithm.
vpratt can comfortably do everything the pure Pratt algorithm is capable of and more — with compile-time safety, correctness guarantees, minimal boilerplate, and an uncompromising developer experience.
vpratt is extremely lightweight and follows a strict zero-allocation rule. The framework completely gets out of the way so you can approach your domain however you see fit. That means you choose your memory management model, AST, and error types — reporting and diagnostics all integrated intuitively.
who is vpratt for?
vpratt is for:
- Compiler and interpreter authors
- DSL and query language designers
- Nerds
- Anyone who has hand-rolled a Pratt parser and felt the absence of a safety net
vpratt is not:
- a lexer
- a code generator
- a regex replacement
- a parser combinator
- opinionated — at least not about your domain
Examples
-
calc — An arithmetic parser covering the full range of regular operators: addition, subtraction, multiplication, division, negation, power, factorial. The foundations, done right.
-
math-lang — A mathematical expression language pushing juxtaposition and implied operators to their limits. Syntax just like how you write math on paper —
sin x,2x,(a + b)(a + b). -
query — A search query DSL with boolean logic, field syntax, and grouping. A practical example of
vprattbeyond compiler territory. -
mincaml compiler — A complete frontend for MinCaml, a real ML-family language. Let bindings, tuples, arrays, and function application in under 300 lines.
Installation
cargo add vpratt
Artwork. Yay!
Dependencies
~95–440KB
~10K SLoC