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
// Copyright (c) 2026 Richard Rodger and other contributors, MIT License
//! The shared compiler behind the BNF-family grammar front-ends for the
//! `tabnas` parsing engine.
//!
//! This crate holds no notation of its own. It defines an intermediate
//! representation (a [`Grammar`] of [`Production`]s over [`Element`]s)
//! and compiles that IR into a tabnas grammar document. A front-end
//! parses one concrete syntax (ABNF, GBNF, EBNF) into the IR and calls
//! [`emit_grammar_spec`]:
//!
//! ```text
//! ABNF / GBNF / EBNF text ──front-end──▶ Grammar ──emit_grammar_spec──▶ GrammarSpec
//! ```
//!
//! Everything hard about that second arrow lives here, and is shared:
//! desugaring repetition into helper rules, left-recursion elimination
//! (including the recursion hidden behind nullable sugar and the
//! suffix-debt counters that keep the generated tail loop from eating a
//! token the enclosing alternative still owes), tail-repeat rewriting,
//! probe dispatch for optional prefixes beyond the engine's bounded
//! lookahead, literal lifting into named lexer tokens, token allocation,
//! first-set analysis, and chain emission through synthetic `$stepN`
//! continuation rules.
//!
//! This is the Rust port of the canonical TypeScript implementation; the
//! TypeScript compiler is authoritative and this crate tracks it.
//!
//! ```
//! use tabnas_bnf::{emit_grammar_spec, ConvertOptions, Element, Grammar, Production};
//!
//! let grammar = Grammar::new(vec![
//! Production::new("val", vec![vec![Element::reference("add")]]),
//! Production::new("add", vec![vec![Element::token("#NR")]]),
//! ]);
//! let spec = emit_grammar_spec(&grammar, &ConvertOptions::tag("demo")).unwrap();
//! assert!(spec.rule.contains_key("val"));
//! ```
/// The README's Rust examples run as doctests, so a stale one fails the
/// gate rather than misleading the reader. Its `toml` and `bash` fences
/// are skipped; rustdoc runs only the `rust` ones.
/// This crate's version. It MUST equal `ts/package.json` "version": the
/// release orchestrator rewrites both, and `tests/version_test.rs` fails
/// the build if they drift. Mirrors `VERSION` in `ts/src/bnf.ts` and
/// `const VERSION` in `go/bnf.go`.
pub const VERSION: &str = "0.1.26";
pub use emit_grammar_spec;
pub use ;
pub use eliminate_left_recursion;
pub use ;