1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! A typed LR(1) parser generator for Rust with runtime operator precedence
//! and a push-based API for natural lexer feedback.
//!
//! # Quick start
//!
//! Define a grammar with the [`gazelle_macros::gazelle!`] macro, implement the
//! generated `Types` trait to choose your output types, and implement
//! [`Action`] for any node you want to fold:
//!
//! ```rust
//! use gazelle_macros::gazelle;
//!
//! gazelle! {
//! grammar calc {
//! start expr;
//! terminals { NUM: _, PLUS }
//! expr = expr PLUS NUM => add | NUM => num;
//! }
//! }
//!
//! struct Eval;
//!
//! impl calc::Types for Eval {
//! type Error = gazelle::ParseError;
//! type Num = i64;
//! type Expr = i64;
//! }
//!
//! impl gazelle::Action<calc::Expr<Self>> for Eval {
//! fn build(&mut self, node: calc::Expr<Self>) -> Result<i64, gazelle::ParseError> {
//! Ok(match node {
//! calc::Expr::Add(left, right) => left + right,
//! calc::Expr::Num(n) => n,
//! })
//! }
//! }
//! ```
//!
//! Then push tokens and collect the result:
//!
//! ```rust,ignore
//! let mut parser = calc::Parser::<Eval>::new();
//! let mut actions = Eval;
//! for tok in tokens {
//! parser.push(tok, &mut actions).map_err(|e| parser.format_error(&e, None, None))?;
//! }
//! let result = parser.finish(&mut actions).map_err(|(p, e)| p.format_error(&e, None, None))?;
//! ```
//!
//! See `examples/hello.rs` for a complete runnable version.
//!
//! # Key features
//!
//! - **Runtime operator precedence**: `prec` terminals carry [`Precedence`] at
//! parse time, so one grammar rule handles any number of operator levels —
//! including user-defined operators.
//! - **Push-based parsing**: you drive the loop, so the lexer can inspect
//! parser state between tokens (solves C's typedef problem).
//! - **CST/AST continuum**: set associated types to the generated enum for a
//! full CST, to a custom type for an AST, or to [`Ignore`] to discard.
//! - **Library API**: build [`CompiledTable`]s programmatically for dynamic
//! grammars, analyzers, or conflict debuggers.
// Core grammar types (AST)
pub use ;
// Parse table types
pub use ;
// Runtime parser types
pub use ;
// Lexer DFA
pub use LexerDfa;
// Meta-grammar parser
pub use parse_grammar;