syn-grammar-model
Shared semantic model and parser for syn-grammar.
This crate provides the core logic for parsing the grammar! { ... } DSL, validating it, and transforming it into a semantic model. It is designed to be reusable for different backends (e.g., a winnow generator or a documentation generator).
Architecture
The processing pipeline consists of four stages:
- Parsing (
parser): Converts the rawTokenStreaminto a syntactic AST (parser::GrammarDefinition). This handles the concrete syntax of the DSL. - Transformation (
model): Converts the syntactic AST into a semantic model (model::GrammarDefinition). This simplifies the structure (e.g., flattening groups, resolving inheritance placeholders). - Validation (
validator): Checks the semantic model for errors, such as undefined rules, argument mismatches, or invalid token usage. - Analysis (
analysis): Provides helper functions to query the model, such as detecting left-recursion, collecting custom keywords, or finding "Cut" operators.
Usage
If you are building a custom backend for syn-grammar, use the pipeline as follows:
use ;
use parse_macro_input;
use TokenStream;