ion7-grammar / grammar_obj

class

Grammar_obj

Functions

Grammar_obj.new

Construct a Grammar_obj wrapping a Builder.

Grammar_obj.new(b)
banyBuilder instance (required).
→ Grammar_obj

Grammar_obj:to_gbnf

Compile to GBNF string ready for llama.cpp.

Grammar_obj:to_gbnf(root)
rootstring?Override root rule name.
→ string

Grammar_obj:builder

Return the underlying Builder for manual rule manipulation.

Grammar_obj:builder()
→ anyBuilder

Grammar_obj:merge

Merge rules from another Grammar_obj into this one. Rules from other are added only if not already defined in self. Returns self (fluent, composable).

Grammar_obj:merge(other)
otherGrammar_obj
→ Grammar_objself

Grammar_obj:rules

List all defined rule names in definition order.

Grammar_obj:rules()
→ tableArray of strings.

Grammar_obj:union

Compose: match either this grammar or another (union). Returns a new Grammar_obj.

Grammar_obj:union(other)
otherGrammar_obj
→ Grammar_obj

Grammar_obj:then_

Compose: match this grammar followed by another (sequence).

Grammar_obj:then_(other, sep)
otherGrammar_obj
sepany?Optional separator AST node.
→ Grammar_obj

Grammar_obj:trigger_words

Derive the set of string prefixes that can start a valid match of this grammar, suitable as trigger_words for ion7_csampler grammar_lazy (CRANE).

Grammar_obj:trigger_words(opts)
optstable?
→ tableSorted array of trigger strings.

Grammar_obj:fuzz

Fuzz: generate random valid strings from this grammar.

Grammar_obj:fuzz(opts)
optstable?{ count, seed, max_rep, max_depth }
→ tablesamples Array of generated strings.
→ numberseed RNG seed used (for reproduction).

Grammar_obj:inspect

Debug: return annotated GBNF with rule stats.

Grammar_obj:inspect()
→ string

RawGrammar.new

RawGrammar.new(gbnf)
gbnfstringRaw GBNF string.
→ Grammar_obj