7 releases (breaking)
| new 0.8.0 | Feb 19, 2026 |
|---|---|
| 0.7.1 | Feb 17, 2026 |
| 0.6.0 | Feb 8, 2026 |
| 0.5.0 | Feb 7, 2026 |
| 0.3.0 | Feb 3, 2026 |
#386 in Parser tooling
Used in syn-grammar
26KB
547 lines
grammar-kit
grammar-kit is the runtime support library for parsers generated by syn-grammar. It provides essential utilities for backtracking, error recovery, and testing syn-based parsers.
Features
1. Speculative Parsing (Backtracking)
The attempt function allows parsers to try a parsing branch and revert the stream cursor if it fails, without consuming tokens. This enables LL(k) lookahead and backtracking logic.
2. Intelligent Error Reporting
grammar-kit implements a "Deepest Error" heuristic. When multiple parsing branches fail, it preserves the error that occurred furthest into the token stream. This prevents generic "unexpected token" errors at the start of a block when a specific syntax error occurred deep inside it.
3. Testing Framework
The testing module provides a fluent API for unit testing your parsers.
Installation
Add this to your Cargo.toml:
[dependencies]
grammar-kit = "0.4.0"
Runtime Helpers
The library exposes several helper functions used by generated parsers:
attempt: Forks the input, runs a closure, and advances only on success.parse_ident: Parses identifiers, accepting Rust keywords (viaIdentExt).parse_int: Parses integer literals into typed Rust integers.skip_until: Skips tokens until a specific condition is met (used for error recovery).
Dependencies
~130–510KB
~12K SLoC