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
child_info_for_telemetry(children)
combinator(type, label, parser_fn, meta \\ [])
Create a new combinator parser with the given label, parsing function, and optional metadata.
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.
pop_entry_point(ctx)
push_entry_point(ctx)
terminal(type, label, parser_fn, meta \\ [])
Create a new terminal parser with the given label, parsing function, and optional metadata.
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)