ion7-grammar / ast.nodes

module

ast.nodes

local ast = require "ion7.grammar.ast.nodes"
local node = ast.seq(ast.literal("{"), ast.ref("ws"), ast.literal("}"))

Functions

ast.literal

Exact string literal node.

ast.literal(s)
sstringLiteral value.
→ node{ kind="literal", value=s }

ast.char

Character class node.

ast.char(spec, negated)
specstringCharacter class spec, e.g. "a-zA-Z0-9_" or "\\n\\t".
negatedboolean?When true the class is negated: [^spec]. Default: false.
→ node{ kind="char", spec=spec, negated=negated }

ast.ref

Reference to a named rule.

ast.ref(name)
namestringRule name to reference.
→ node{ kind="ref", name=name }

ast.seq

Sequence: all nodes must match in left-to-right order. Single-node form unwraps (passthrough) for ergonomic use.

ast.seq(...)
...nodeOne or more AST nodes.
→ node{ kind="seq", items={...} } or unwrapped node when only one.

ast.alt

Alternation: first matching branch wins. Single-node form unwraps (passthrough) for ergonomic use.

ast.alt(...)
...nodeOne or more alternative AST nodes.
→ node{ kind="alt", items={...} } or unwrapped node when only one.

ast.rep

Repetition with explicit bounds.

ast.rep(node, min, max)
nodenodeInner node to repeat.
minnumber?Minimum repetitions (>= 0). Default: 0.
maxnumber?Maximum repetitions (-1 = unlimited). Default: -1.
→ node{ kind="rep", node=node, min=min, max=max }

ast.star

Zero or more repetitions.

ast.star(node)
nodenode
→ node

ast.plus

One or more repetitions.

ast.plus(node)
nodenode
→ node

ast.opt

Zero or one (optional).

ast.opt(node)
nodenode
→ node

ast.exactly

Exactly N repetitions.

ast.exactly(node, n)
nodenode
nnumber
→ node

ast.group

Explicit grouping (for readability / precedence).

ast.group(node)
nodenode
→ node{ kind="group", node=node }

ast.any_except

Negated character class shorthand: [^spec].

ast.any_except(spec)
specstringCharacters to exclude.
→ node{ kind="char", spec=spec, negated=true }

ast.rule

Named rule node (used internally by Builder). Rule names must match [a-z][a-z0-9-]*.

ast.rule(name, body)
namestringRule name.
bodynodeRule body.
→ node{ kind="rule", name=name, body=body }