View Source Minipeg.Mappers (Minipeg v0.4.2)
Define some useful functions for Minipeg.Combinators.map
Summary
Functions
A mapper for parsers that return not empty lists, it removes the first element from the mapper
A mapper for parsers that return not empty lists, it removes the first element from the mapper and then flattens the rest
Types
@type ast_list_t() :: [ast_t()]
@type ast_t() :: any()
@type binaries() :: [binary()]
@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 result_t() :: Minipeg.Failure.t() | Minipeg.Success.t()
@type satisfier_t() :: (any() -> satisfier_result_t())
@type str_or_count_t() :: binary() | non_neg_integer()
Functions
@spec ignore_first(ast_list_t()) :: ast_t()
A mapper for parsers that return not empty lists, it removes the first element from the mapper
Ex.:
sequence([
char_parser("%"),
some_parser() # --> some_ast
]) |> map(&ignore_first/1) # --> [some_ast]
sequence([
char_parser("%"),
some_parser() # --> some_ast
other_parser() # --> other_ast
]) |> map(&ignore_first/1) # --> [some_ast, other_ast]
@spec ignore_first_and_flatten(ast_list_t()) :: ast_list_t()
A mapper for parsers that return not empty lists, it removes the first element from the mapper and then flattens the rest
Ex.:
sequence([
char_parser("%"),
sequence([
some_parser() # --> some_ast
other_parser() # --> other_ast
])
]) |> map(&ignore_first/1) # --> [some_ast, other_ast] and not [[..., ...]]