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
//! Context-free grammar engine with Earley-parser-based constrained decoding.
//!
//! This module provides:
//!
//! * A **BNF text parser** ([`parse_bnf`]) that converts a grammar string into
//! an in-memory [`Grammar`] representation.
//! * An **Earley chart-parser recognizer** ([`EarleyRecognizer`]) that
//! processes a byte stream against the grammar incrementally, supporting:
//! - Left-recursive and right-recursive grammars
//! - Nullable (ε) productions
//! - Any context-free grammar (not just LL(k) or LR(k))
//! * A **[`GrammarConstraint`]** that wraps the recognizer and implements the
//! [`crate::constrained_decoding::TokenConstraint`] trait so it can be
//! dropped into any token-generation pipeline.
//! * Pre-built **[example grammars]** for testing and demonstration.
//!
//! # Quick start
//!
//! ```rust,no_run
//! use oxibonsai_runtime::grammar::{parse_bnf, GrammarConstraint};
//! use oxibonsai_runtime::constrained_decoding::TokenConstraint;
//!
//! let grammar = parse_bnf(r#"
//! <expr> ::= <term> "+" <expr> | <term>
//! <term> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
//! "#).expect("valid BNF");
//!
//! let mut constraint = GrammarConstraint::new(grammar, |id| {
//! if id < 128 { vec![id as u8] } else { vec![] }
//! }, 128);
//!
//! // Check which tokens are allowed at the start.
//! let mask = constraint.allowed_tokens(&[], 128).unwrap();
//! assert!(mask[b'0' as usize]);
//! assert!(!mask[b'+' as usize]);
//! ```
//!
//! [example grammars]: examples
// ── Public re-exports ─────────────────────────────────────────────────────────
pub use ;
pub use ;
pub use AllowedTokensCache;
pub use GrammarConstraint;
pub use EarleyRecognizer;
pub use ;
pub use ;
pub use ;
pub use ;