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:
[]
= "0.3.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).