ion7-grammar / from.dynamic

module

from.dynamic

local Dynamic = require "ion7.grammar.from.dynamic"

-- Only allow values that exist in the DB right now
local b = Dynamic.from_enum("table-name", db:get_table_names())
local gbnf = b:compile()

Functions

Dynamic.from_enum

Build a grammar that matches exactly one value from a list. Deduplicates and sorts longest-first to prevent prefix ambiguity.

Dynamic.from_enum(rule_name, values)
rule_namestringName for the generated GBNF rule.
valuestableNon-empty array of string values to allow.
→ Builder

Dynamic.from_schema

Build a grammar from a table of named value sets.

Dynamic.from_schema(schema, opts)
schematableMap of { rule_name = { value1, ... }, ... }.
optstable?
→ Builder

Dynamic.from_json_enum

Build a grammar that matches a quoted JSON string from a whitelist.

Dynamic.from_json_enum(rule_name, values)
rule_namestringRule name for the generated GBNF rule.
valuestableNon-empty array of unquoted string values.
→ Builder

Dynamic.from_values_with_pattern

Build a grammar restricted to a whitelist (pattern param is documentation only). GBNF cannot express the intersection of a regex and a whitelist directly. The whitelist is the stronger constraint and is used directly.

Dynamic.from_values_with_pattern(rule_name, values, _pattern)
rule_namestringName for the generated GBNF rule.
valuestableAllowed string values.
_patternstring?Regex pattern (documentation only; not applied).
→ Builder

Dynamic.from_tools

Build a function-call grammar from a registry of tool definitions. Each tool produces a JSON object: { "name": "...", "arguments": { ... } }. Tools are combined in an alternation under a `tool-call` root rule.

Dynamic.from_tools(tools)
toolstableNon-empty array of { name, schema? } tables.
→ Builder