Skip to main content

emit_gbnf

Function emit_gbnf 

Source
pub fn emit_gbnf(
    grammar: &Grammar,
) -> Result<(String, EmitReport), GrammarEmitError>
Expand description

Emits GGML BNF text for grammar-constrained LLM decoding.

The output is deterministic, starts with the mandatory GBNF root rule, and uses GBNF’s native alternation, grouping, character classes, and counted repetition operators. The IR’s AnyChar wildcard is emitted as the documented full Unicode scalar range class [\x00-\U0010FFFF].

§Errors

Returns GrammarEmitError when the grammar contains a construct GBNF cannot faithfully represent, such as general PEG lookahead predicates, empty character classes, descending ranges, invalid repeat bounds, or a configured start rule that is not present in the grammar.