module
from.types
local Types = require "ion7.grammar.from.types"
local b = Types.from_type({ name = "string", age = "integer?" })
print(b:compile())
Functions
Types.to_schema
Convert a Lua type annotation to a JSON Schema table. Maps the simplified ion7 type syntax to a JSON Schema draft-07 subset that can be fed into the full JSON Schema → GBNF pipeline. Handles primitives, optional markers (?), arrays, and nested objects. Type string values: "string" → { type = "string" } "number" → { type = "number" } "integer" → { type = "integer" } "boolean" → { type = "boolean" } "null" → { type = "null" } "any" → {} (unconstrained) "T?" → { oneOf = { to_schema("T"), { type="null" } } } Table values: { "T" } → array items schema (single-element array) { key = "T", ... } → object with typed properties { ["key?"] = "T" } → object with optional field (key ending with ?)
Types.from_type
Build a Builder from a Lua type annotation. Avoids the circular dep of calling Grammar.from_json_schema() by going directly to json_m.to_rules() + Builder — same pipeline, no middle layer.
Types.from_function
Build a Builder for a named function signature. Generates a JSON object grammar for calling a function with typed args. Equivalent to `from_type` but documents the semantic intent.