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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! 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 [`gazelle_macros::gazelle!`]. A `prec` terminal carries
//! [`Precedence`] at parse time, so one rule handles all operator levels:
//!
//! ```rust
//! use gazelle_macros::gazelle;
//!
//! gazelle! {
//! grammar calc {
//! start expr;
//! terminals { NUM: _, prec OP: _ }
//! expr = expr OP expr => binop | NUM => num;
//! }
//! }
//!
//! struct Eval;
//!
//! impl gazelle::ErrorType for Eval {
//! type Error = core::convert::Infallible;
//! }
//!
//! impl calc::Types for Eval {
//! type Num = i64;
//! type Op = char;
//! type Expr = i64;
//! }
//!
//! impl gazelle::Action<calc::Expr<Self>> for Eval {
//! fn build(&mut self, node: calc::Expr<Self>) -> Result<i64, Self::Error> {
//! Ok(match node {
//! calc::Expr::Binop(l, op, r) => match op {
//! '+' => l + r, '-' => l - r, '*' => l * r, '/' => l / r,
//! _ => unreachable!(),
//! },
//! calc::Expr::Num(n) => n,
//! })
//! }
//! }
//! ```
//!
//! Then push tokens with precedence and collect the result:
//!
//! ```rust,ignore
//! use gazelle::Precedence;
//!
//! let mut parser = calc::Parser::<Eval>::new();
//! let mut actions = Eval;
//! // Precedence is supplied per-token — the grammar stays flat:
//! parser.push(calc::Terminal::Num(1), &mut actions)?;
//! parser.push(calc::Terminal::Op('+', Precedence::Left(1)), &mut actions)?;
//! parser.push(calc::Terminal::Num(2), &mut actions)?;
//! parser.push(calc::Terminal::Op('*', Precedence::Left(2)), &mut actions)?;
//! parser.push(calc::Terminal::Num(3), &mut actions)?;
//! let result = parser.finish(&mut actions).map_err(|(p, gazelle::ParseError::Syntax { terminal })| p.format_error(terminal, None, None))?;
//! assert_eq!(result, 7); // 1 + (2 * 3)
//! ```
//!
//! See `examples/expr_eval.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.
extern crate alloc;
extern crate std;
// -- Core modules (always available) --
// -- Construction modules --
// Core grammar types (AST)
pub use ;
// Parse table types
pub use ;
// Runtime parser types
pub use ;
// Lexer DFA
pub use ;
// Meta-grammar parser
pub use parse_grammar;