# `Grammar.Native.RuleCompiler`
[🔗](https://github.com/joetjen/ichor/blob/v0.3.0/lib/grammar/native/rule_compiler.ex#L1)

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 ordered-list shape `Ichor.Actions`
expects (`{:token, name, text}` / `{:rule, name, sub_captures}` /
`{:text, text}` values, keyed by name, in first-occurrence RHS
order -- see `Ichor.Capture.raw_captures/0`). `context` is read-only,
threaded through purely so a
`Grammar.IR.Custom` `@native(...)` leaf can hand it to
`c: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.

# `compile`

```elixir
@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.

# `rule_fn_name`

```elixir
@spec rule_fn_name(atom()) :: atom()
```

The generated function name for a given rule name -- exposed so `Grammar.Native` can reference the root rule's own matcher.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
