Grammar.Native.Lossless (Ichor v0.7.3)

Copy Markdown View Source

What lossless: true adds to a generated LR or GLR parser (design/lossless-mode.md): parse_lossless/1,2 and run_lossless/1,2, over a shift-reduce run that records the rules (Grammar.LR.Lossless, or Grammar.GLR.Runtime.run/7 building with Ichor.Syntax.Record.reduced/3).

The two engines differ only in that run, so it is handed in as quoted code; the rest -- trimming, placing an error against the input, weaving the tree, evaluating the value -- is one definition for both, and the same as each engine's ordinary parse/2 and run/2 do.

Summary

Functions

fn_name/2 clauses answering a state and a lookahead terminal with the table's list of actions ([] for none) -- the lookup Grammar.LR.Lossless takes, which the generated LR parser otherwise has no need of, its states being compiled into functions.

The generated functions. run is quoted code evaluating, with stream_var/0 bound to the trimmed token tuple, to {:ok, pos, raw_captures} with the records inside, or {:error, error}.

The variable the trimmed token tuple is bound to, for run to read: unhygienic, since run is quoted in another module.

Functions

action_defs(table, fn_name)

@spec action_defs(Grammar.LRTable.t(), atom()) :: [Macro.t()]

fn_name/2 clauses answering a state and a lookahead terminal with the table's list of actions ([] for none) -- the lookup Grammar.LR.Lossless takes, which the generated LR parser otherwise has no need of, its states being compiled into functions.

shift_reduce_defs(grammar, actions_module, run)

@spec shift_reduce_defs(Aether.Grammar.t(), module(), Macro.t()) :: Macro.t()

The generated functions. run is quoted code evaluating, with stream_var/0 bound to the trimmed token tuple, to {:ok, pos, raw_captures} with the records inside, or {:error, error}.

stream_var()

@spec stream_var() :: Macro.t()

The variable the trimmed token tuple is bound to, for run to read: unhygienic, since run is quoted in another module.