Grammar.LRTable.Captures (IchorRuntime v0.1.0)

Copy Markdown View Source

Builds the raw-capture map Ichor.Actions expects ({:token,...}/ {:rule,...}/{:text,...}) from one reduced production's own RHS entries -- shared by Grammar.LR (a single linear stack) and Grammar.GLR (a graph-structured one): both reduce the same kind of production, against the same kind of token stream, needing the exact same per-position classification (see Grammar.LRTable.Production's own moduledoc for what each capture kind means), so this logic has exactly one place to live rather than two copies drifting apart.

Summary

Types

One popped RHS position: value is the shifted %Token{} (a terminal position) or the already-built captures map of a reduced nonterminal; start_pos/end_pos are the token-stream span it covers, needed for a :text-kind capture regardless of which RHS position it sits at (not just the whole production's own span).

Functions

Builds the raw-capture map for production, given its popped RHS entries in order.

The first/second/third+ list-promotion rule every raw-capture builder in Ichor uses (Grammar.VM.TokenInterpreter's own merge_capture/3, mirrored here): a name captured more than once naturally becomes a list without knowing the eventual count in advance.

Types

entry()

@type entry() ::
  {value :: Grammar.VM.Token.t() | map(), start_pos :: non_neg_integer(),
   end_pos :: non_neg_integer()}

One popped RHS position: value is the shifted %Token{} (a terminal position) or the already-built captures map of a reduced nonterminal; start_pos/end_pos are the token-stream span it covers, needed for a :text-kind capture regardless of which RHS position it sits at (not just the whole production's own span).

Functions

build(production, entries, stream)

@spec build(Grammar.LRTable.Production.t(), [entry()], tuple()) :: map()

Builds the raw-capture map for production, given its popped RHS entries in order.

merge(captures, name, value)

@spec merge(map(), atom(), term()) :: map()

The first/second/third+ list-promotion rule every raw-capture builder in Ichor uses (Grammar.VM.TokenInterpreter's own merge_capture/3, mirrored here): a name captured more than once naturally becomes a list without knowing the eventual count in advance.