Minipeg.Combinators (Minipeg v0.7.6)

View Source

All public functions in this module take a parser and potentially more parameters and return a new parser

Summary

Functions

Just parses with parser but displays, input and result to stderr ALternatively, if a function is provided the function is called and nothing is printed to stderr

This parser, iff it succeeds returns a special Ignore result that is ignored inside a sequence combinator

Parsers a string that would be parsed by parser but ignoring leading whitespace, if you also want to ignore whitespace after the parsed string use tokenized

Unwrapps a wrapped parser and parses with it. This is used for recursive rules, e.g.

Parses a list defined by an element_parser and a seperator_parser

Applies a parser as many times as possible, can use min_count (defaulting to 0) to fail unless the parser could parse min_count times

many_sel([...]) is just a convenience for many(select([...]))

many_seq([...]) is just a convenience for many(sequence([...]))

Succeeds if parser succeeds, but maps the ast with mapper_fun. If parser fails, it fails

If parser fails, it fails with the error mapped by error_fun If parser succeeds, it just passes the result along

parses iff parser parses then maps the ast to a string with IO.chardata_to_string/1 The ast must therefore be of type IO data

Like map, but this also provides a second argument, the position in form of a tuple {col, lnb} to the mapper function

Returns a parser that only succeeds if the original parser succeeds and the satisfier function that is called with the ast of the original result returns {:ok, value}. It also changes the original ast with value in the final result.

Looks into the cache (for this parsing position) before parsing, if no result found parses and puts the result into the cache (for this parsing position)

succeeds with the first parser that succeeds in parsers, otherwise fails

Consume chars until parser parses and return them as parsed ast, fails if parser never succeeds can add the delimiter to the ast or leave it on the input stream

A shortcut for mapp(parser, &{&1, &2}...

Types

ast_list_t()

@type ast_list_t() :: [ast_t()]

ast_t()

@type ast_t() :: any()

atoms()

@type atoms() :: [atom()]

binaries()

@type binaries() :: [binary()]

binary?()

@type binary?() :: maybe(binary())

char_set_spec_t()

@type char_set_spec_t() :: maybe(binary() | list())

char_set_t()

@type char_set_t() :: [binary()] | binary()

either(success_t, error_t)

@type either(success_t, error_t) :: {:ok, success_t} | {:error, error_t}

input_t()

@type input_t() :: binary() | [binary()] | Minipeg.Input.t()

maybe(t)

@type maybe(t) :: nil | t

name_t()

@type name_t() :: atom() | binary()

name_t?()

@type name_t?() :: maybe(name_t())

parser_function_t()

@type parser_function_t() :: (Minipeg.Input.t(), Minipeg.Cache.t(), binary() ->
                          result_t())

position_t()

@type position_t() :: {pos_integer(), pos_integer()}

result_t()

@type result_t() :: Minipeg.Failure.t() | Minipeg.Ignore.t() | Minipeg.Success.t()

satisfier_result_t()

@type satisfier_result_t() :: either(any(), binary())

satisfier_t()

@type satisfier_t() :: (any() -> satisfier_result_t())

str_or_count_t()

@type str_or_count_t() :: binary() | non_neg_integer()

token1_comp_t()

@type token1_comp_t() ::
  {atom(), token_parse_part2()}
  | {atom(), token_parse_part2(), (binary() -> any())}

token1_spec_t()

@type token1_spec_t() ::
  {atom(), token_parse_part1()}
  | {atom(), token_parse_part1(), (binary() -> any())}

token_comp_t()

@type token_comp_t() :: [token1_comp_t()]

token_spec_t()

@type token_spec_t() :: [token1_spec_t()]

wrapped_parser_t()

@type wrapped_parser_t() :: (-> Minipeg.Parser.t())

Functions

debug(parser, name \\ nil, fun \\ nil)

@spec debug(
  Minipeg.Parser.t(),
  binary?(),
  maybe((Minipeg.Input.t(), result_t() -> any()))
) ::
  Minipeg.Parser.t()

Just parses with parser but displays, input and result to stderr ALternatively, if a function is provided the function is called and nothing is printed to stderr

ignore(parser, name \\ nil)

@spec ignore(Minipeg.Parser.t(), maybe(binary())) :: Minipeg.Parser.t()

This parser, iff it succeeds returns a special Ignore result that is ignored inside a sequence combinator

ignore_ws(parser, name \\ nil, skip_newlines \\ false)

@spec ignore_ws(Minipeg.Parser.t(), binary?(), boolean()) :: Minipeg.Parser.t()

Parsers a string that would be parsed by parser but ignoring leading whitespace, if you also want to ignore whitespace after the parsed string use tokenized

in_between_parser(ignored_start_parser, inside_parser, ignored_end_parser, name \\ nil)

@spec in_between_parser(
  Minipeg.Parser.t(),
  Minipeg.Parser.t(),
  Minipeg.Parser.t(),
  binary?()
) ::
  Minipeg.Parser.t()

lazy(wrapped_parser, name \\ nil)

@spec lazy(wrapped_parser_t(), binary?()) :: Minipeg.Parser.t()

Unwrapps a wrapped parser and parses with it. This is used for recursive rules, e.g.

```elixir
  def my_parser...
      sequence([...
          lazy(fn -> my_parser() end)
```

list_parser(element_parser, seperator_parser, name \\ nil, min_count \\ 0)

Parses a list defined by an element_parser and a seperator_parser

many(parser, name \\ nil, min_count \\ 0)

Applies a parser as many times as possible, can use min_count (defaulting to 0) to fail unless the parser could parse min_count times

many_as_string(parser, name \\ nil, min_count \\ 0)

@spec many_as_string(Minipeg.Parser.t(), maybe(binary()), non_neg_integer()) ::
  Minipeg.Parser.t()

See Minipeg.Combinators.Convenience.many_as_string/3.

many_sel(parsers, name \\ nil, min_count \\ 0)

@spec many_sel([Minipeg.Parser.t()], binary?(), non_neg_integer()) ::
  Minipeg.Parser.t()

many_sel([...]) is just a convenience for many(select([...]))

many_seq(parsers, name \\ nil, min_count \\ 0)

@spec many_seq([Minipeg.Parser.t()], binary?(), non_neg_integer()) ::
  Minipeg.Parser.t()

many_seq([...]) is just a convenience for many(sequence([...]))

map(parser, mapper_fun, name \\ nil)

@spec map(Minipeg.Parser.t(), (ast_t() -> ast_t()), maybe(binary())) ::
  Minipeg.Parser.t()

Succeeds if parser succeeds, but maps the ast with mapper_fun. If parser fails, it fails

map_error(parser, error_fun, name \\ nil)

If parser fails, it fails with the error mapped by error_fun If parser succeeds, it just passes the result along

map_to_string(parser, name \\ nil)

@spec map_to_string(Minipeg.Parser.t(), binary?()) :: Minipeg.Parser.t()

parses iff parser parses then maps the ast to a string with IO.chardata_to_string/1 The ast must therefore be of type IO data

mapp(parser, mapper_fun, name \\ nil)

@spec mapp(Minipeg.Parser.t(), (ast_t(), position_t() -> ast_t()), maybe(binary())) ::
  Minipeg.Parser.t()

Like map, but this also provides a second argument, the position in form of a tuple {col, lnb} to the mapper function

maybe(parser, name \\ nil)

@spec maybe(Minipeg.Parser.t(), binary?()) :: Minipeg.Parser.t()

See Minipeg.Combinators.Base.maybe/2.

maybe_as_empty(parser, name \\ nil)

@spec maybe_as_empty(Minipeg.Parser.t(), binary?()) :: Minipeg.Parser.t()

option(parsers, name \\ nil)

@spec option([Minipeg.Parser.t()], binary?()) :: Minipeg.Parser.t()

See Minipeg.Combinators.select/2.

satisfy(parser, satisfier, name \\ nil)

Returns a parser that only succeeds if the original parser succeeds and the satisfier function that is called with the ast of the original result returns {:ok, value}. It also changes the original ast with value in the final result.

savepoint(parser, sp_name \\ nil, name \\ nil)

@spec savepoint(Minipeg.Parser.t(), binary?(), binary?()) :: Minipeg.Parser.t()

Looks into the cache (for this parsing position) before parsing, if no result found parses and puts the result into the cache (for this parsing position)

select(parsers, name \\ nil)

@spec select([Minipeg.Parser.t()], binary?()) :: Minipeg.Parser.t()

succeeds with the first parser that succeeds in parsers, otherwise fails

sequence(parsers, name \\ nil)

@spec sequence([Minipeg.Parser.t()], binary?()) :: Minipeg.Parser.t()

See Minipeg.Combinators.Base.sequence/2.

set_error(parser, reason, parser_name \\ nil)

@spec set_error(Minipeg.Parser.t(), binary?(), binary?()) :: Minipeg.Parser.t()

tokenize(parser)

@spec tokenize(Minipeg.Parser.t()) :: Minipeg.Parser.t()

upto_parser_parser(parser, name \\ nil, parse_behavior \\ :keep)

@spec upto_parser_parser(Minipeg.Parser.t(), binary?(), upto_behavior_t()) ::
  Minipeg.Parser.t()

Consume chars until parser parses and return them as parsed ast, fails if parser never succeeds can add the delimiter to the ast or leave it on the input stream

with_pos(parser, name \\ nil)

@spec with_pos(Minipeg.Parser.t(), binary?()) :: Minipeg.Parser.t()

A shortcut for mapp(parser, &{&1, &2}...