Ergo.Parser (Ergo v0.9.9)

Ergo.Parser contains the Parser record type. Ergo parsers are anonymous functions but we embed them in a Parser record that can hold arbitrary metadata. The primary use for the metadata is the storage of debugging information.

Link to this section Summary

Functions

Create a new combinator parser with the given label, parsing function, and optional metadata.

invoke/2 invokes the parsing function of the given parser on the specified %Context{} structure. It maintains housekeeping for the parser generally.

Create a new terminal parser with the given label, parsing function, and optional metadata.

track_parser first checks if the parser has already been tracked for the current input index and, if it has, raises a CycleError to indicate the parser is in a loop. Otherwise it adds the parser at the current index.

Link to this section Functions

Link to this function

child_info_for_telemetry(children)

Link to this function

combinator(type, label, parser_fn, meta \\ [])

Create a new combinator parser with the given label, parsing function, and optional metadata.

Link to this function

invoke(ctx, parser)

invoke/2 invokes the parsing function of the given parser on the specified %Context{} structure. It maintains housekeeping for the parser generally.

Link to this function

pop_entry_point(ctx)

Link to this function

push_entry_point(ctx)

Link to this function

terminal(type, label, parser_fn, meta \\ [])

Create a new terminal parser with the given label, parsing function, and optional metadata.

Link to this function

track_parser(ctx)

track_parser first checks if the parser has already been tracked for the current input index and, if it has, raises a CycleError to indicate the parser is in a loop. Otherwise it adds the parser at the current index.

Examples

iex> alias Ergo.{Context, Parser} iex> import Ergo.{Terminals, Combinators} iex> parser = many(char(?H)) iex> context = ...> Context.new("Hello World") ...> |> Map.put(:parser, parser) ...> |> Parser.track_parser() iex> assert Context.parser_tracked?(context, parser.ref)