ion7-grammar / dev.debug

module

dev.debug

local Grammar = require "ion7.grammar"

local g = Grammar.from_type({ name = "string", age = "integer" })

-- Annotated GBNF with rule stats
print(Grammar.debug(g))

-- Structured analysis
local a = Grammar.analyze(g)
print(a.n_rules, a.root, #a.unreferenced)

-- ASCII dependency tree
print(Grammar.tree(g))

-- Diff two grammars
local g2 = Grammar.from_type({ name = "string" })
print(Grammar.diff(g, g2))

Functions

debug_m.inspect

Pretty-print a grammar as annotated GBNF with rule statistics.

debug_m.inspect(grammar, opts)
grammaranyGrammar_obj or Builder.
optstable?
→ string

debug_m.analyze

Analyze a grammar and return structured statistics.

debug_m.analyze(grammar)
grammaranyGrammar_obj or Builder.
→ table{ n_rules, root, unreferenced, recursive, gbnf_length }

debug_m.diff

Compare two grammars and show what changed.

debug_m.diff(g1, g2)
g1anyOriginal grammar.
g2anyUpdated grammar.
→ stringDiff-style output.

debug_m.tree

Generate an ASCII tree representation of grammar rule dependencies.

debug_m.tree(grammar, root)
grammarany
rootstring?Root rule (default: grammar's root or "root").
→ string