Compiles every rule in a grammar into quoted Elixir function
definitions run against the lexer's token stream (never raw
characters -- Aether's own two-stage split), mirroring
Grammar.VM.RuleCompiler's own semantics exactly (bare-reference
implicit self-capture, Indent/@samecol, capture-shape rules) but
producing direct function calls instead of bytecode.
Every generated function has the shape (stream :: tuple(), pos :: non_neg_integer(), ref_stack :: [integer()], context :: term()) -> {:ok, new_pos, new_ref_stack, raw_captures} | :fail, where
raw_captures is exactly the map shape Ichor.Actions expects
({:token, name, text} / {:rule, name, sub_captures} / {:text, text}). context is read-only, threaded through purely so a
Grammar.IR.Custom @native(...) leaf can hand it to
Ichor.CustomRule.match/4 -- nothing else in this module ever reads
it, only passes it along. A RuleRef compiles to a call into that
other rule/token's own compiled function; the grammar's own token/rule
namespaces (passed in as token_names) are what tell the two apart,
exactly as in the VM.
Summary
Functions
Compiles every rule into a list of quoted defp definitions, one named rule_fn_name/1 per rule plus one per anonymous sub-expression.
The generated function name for a given rule name -- exposed so Grammar.Native can reference the root rule's own matcher.
Functions
@spec compile(Aether.Grammar.t()) :: [Macro.t()]
Compiles every rule into a list of quoted defp definitions, one named rule_fn_name/1 per rule plus one per anonymous sub-expression.
The generated function name for a given rule name -- exposed so Grammar.Native can reference the root rule's own matcher.