View Source Minipeg.Parsers (Minipeg v0.5.0)

A collection of basic parsers

Summary

Functions

Parses any character in the specified set, defaulting to all characters

Parser that only succeeds on empty input / end of input

Succeeds if any of the given keywords parse

Parses only an exact occurrance of the literal string

Parses any character but delimiter, unless it is escpaed by escape_char or doubled in case allow_doubles is true.

Parses any char with the exception of chars in the forbidden set

parses only if parser parses a string with a prefix that is discarded

This parser always succeeds. N.B. It does not advance the input

parses a string up to the first char in charset fails iff less then min_count chars are parsed. If a character from charset is encountered it is removed from the input stream, but is not returned in the ast.

Parses a sequence of at least min_count whitespaces. min_count defaults to 0

Types

@type ast_list_t() :: [ast_t()]
@type ast_t() :: any()
@type binaries() :: [binary()]
@type binary?() :: maybe(binary())
@type char_class_t() ::
  :alnum
  | :alpha
  | :blank
  | :cntrl
  | :digit
  | :graph
  | :lower
  | :print
  | :punct
  | :space
  | :upper
  | :word
  | :xdigit
@type char_set_t() :: [binary()] | binary()
Link to this type

either(success_t, error_t)

View Source
@type either(success_t, error_t) :: {:ok, success_t} | {:error, error_t}
@type input_t() :: binary() | [binary()] | Minipeg.Input.t()
@type maybe(t) :: nil | t
@type parser_function_t() ::
  (Minipeg.Input.t(), Minipeg.Cache.t(), binary() -> result_t())
@type position_t() :: {pos_integer(), pos_integer()}
@type result_t() :: Minipeg.Failure.t() | Minipeg.Ignore.t() | Minipeg.Success.t()
@type satisfier_result_t() :: either(any(), binary())
@type satisfier_t() :: (any() -> satisfier_result_t())
@type str_or_count_t() :: binary() | non_neg_integer()

Functions

Link to this function

char_parser(specified_set \\ nil, name \\ nil)

View Source
@spec char_parser(maybe(atom() | binary() | list()), binary?()) :: Minipeg.Parser.t()

Parses any character in the specified set, defaulting to all characters

Succeeds if next char in input is in the specified set Fails if input is empty or next char is not in the specified set

If the specified charset is an atom it is interpreted as a POSIX character class described in the docs of the Regex module, here are the currently supported values:

  :alnum | :alpha | :blank | :cntrl | :digit | :graph | :lower | :print | :punct | :space | :upper | :word | :xdigit
Link to this function

delimited_string_parser(delimiter, escape_char \\ "\\", allow_double_escapes \\ true, name \\ nil)

View Source
@spec delimited_string_parser(binary(), binary(), boolean(), binary?()) ::
  Minipeg.Parser.t()
@spec end_parser(binary?()) :: Minipeg.Parser.t()

Parser that only succeeds on empty input / end of input

Link to this function

escaped_char_parser(escape_char \\ "\\", name \\ nil, allowed_set \\ nil)

View Source
@spec escaped_char_parser(binary?(), binary?(), char_set_spec_t()) ::
  Minipeg.Parser.t()

parses an escape char and then any char

Link to this function

failure_parser(reason \\ nil, name \\ nil)

View Source
@spec failure_parser(binary?(), binary?()) :: Minipeg.Parser.t()

This parser always fails

Link to this function

ident_parser(name \\ nil, opts \\ [])

View Source
@spec ident_parser(binary?(), Keyword.t()) :: Minipeg.Parser.t()
@spec int_parser(binary?()) :: Minipeg.Parser.t()
Link to this function

keywords_parser(keywords, name \\ nil)

View Source
@spec keywords_parser([binary()], binary?()) :: Minipeg.Parser.t()

Succeeds if any of the given keywords parse

Link to this function

literal_parser(literal, name \\ nil)

View Source
@spec literal_parser(binary(), binary?()) :: Minipeg.Parser.t()

Parses only an exact occurrance of the literal string

Link to this function

maybe_escaped_char_parser(delimiter, escape_char \\ "\\", allow_doubles \\ true, name \\ nil)

View Source
@spec maybe_escaped_char_parser(binary(), binary(), boolean(), binary?()) ::
  Minipeg.Parser.t()

Parses any character but delimiter, unless it is escpaed by escape_char or doubled in case allow_doubles is true.

Link to this function

not_char_parser(forbidden, name \\ nil)

View Source
@spec not_char_parser(char_set_t(), binary?()) :: Minipeg.Parser.t()

Parses any char with the exception of chars in the forbidden set

Link to this function

prefixed_parser(prefix, parser, name \\ nil)

View Source
@spec prefixed_parser(char_set_t(), Minipeg.Parser.t(), binary?()) ::
  Minipeg.Parser.t()

parses only if parser parses a string with a prefix that is discarded

Link to this function

rgx_capture_parser(rgx_string, name \\ nil, options \\ [])

View Source
@spec rgx_capture_parser(binary(), binary?(), [atom()]) :: Minipeg.Parser.t()
Link to this function

rgx_match_parser(rgx_string, name \\ nil, options \\ [])

View Source
@spec rgx_match_parser(binary(), binary?(), [atom()]) :: Minipeg.Parser.t()
Link to this function

rgx_parser(rgx_string, name \\ nil, options \\ [])

View Source
@spec rgx_parser(binary(), binary?(), [atom()]) :: Minipeg.Parser.t()
Link to this function

string_parser(paren_chars \\ ["\"", "'"], escape_char \\ "\\", allow_double_escapes \\ true, name \\ nil)

View Source
@spec string_parser(char_set_t(), binary?(), boolean(), binary?()) ::
  Minipeg.Parser.t()

A classic string parser which parses input like

  • ""
  • '"a\\'b"c'
  • "ab""c"

but not

  • 'ab
  • "abc'
  • "ad"e (e not parsed)
Link to this function

success_parser(return_ast \\ nil, name \\ nil)

View Source
@spec success_parser(ast_t(), binary?()) :: Minipeg.Parser.t()

This parser always succeeds. N.B. It does not advance the input

Link to this function

unsigned_int_parser(name \\ nil)

View Source
@spec unsigned_int_parser(binary?()) :: Minipeg.Parser.t()
Link to this function

upto_parser(charset, min_count \\ 0, name \\ nil)

View Source
@spec upto_parser(char_set_t(), non_neg_integer(), binary?()) :: Minipeg.Parser.t()

parses a string up to the first char in charset fails iff less then min_count chars are parsed. If a character from charset is encountered it is removed from the input stream, but is not returned in the ast.

Link to this function

ws_parser(allow_newline \\ false, min_count \\ 0, name \\ nil)

View Source
@spec ws_parser(boolean(), non_neg_integer(), binary?()) :: Minipeg.Parser.t()

Parses a sequence of at least min_count whitespaces. min_count defaults to 0