Minipeg.Input (Minipeg v0.7.9)

Copy Markdown View Source

An input wrapper

Summary

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_arg_t()

@type input_arg_t() ::
  {:col, pos_integer()} | {:lnb, pos_integer()} | {:context, any()}

input_args_t()

@type input_args_t() :: [input_arg_t()]

input_t()

@type input_t() :: binary() | [binary()] | 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() :: (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()

t()

@type t() :: %Minipeg.Input{
  col: pos_integer(),
  context: map(),
  input: binary(),
  lnb: pos_integer()
}

take_and_rest_t()

@type take_and_rest_t() :: {binary(), t()}

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()]

Functions

drop(inp, str_or_count \\ 1)

@spec drop(t(), str_or_count_t()) :: t()

empty?(input)

@spec empty?(t()) :: boolean()

make(source, opts \\ [])

@spec make(String.t(), input_args_t()) :: t()

The preferred syntax to create Input structs

iex(3)> make("world", col: 2)
%Input{col: 2, lnb: 1, context: %{}, input: "world"}

Of course we can overwrite more defaults

iex(4)> make("world", lnb: 42, col: 2)
%Input{col: 2, lnb: 42, context: %{}, input: "world"}

Or none at all

iex(5)> make("world")
%Input{col: 1, lnb: 1, context: %{}, input: "world"}

new(source, col \\ 1, lnb \\ 1, context \\ %{})

new just generates an Input struct with default values

iex(1)> new("hello")
%Input{col: 1, lnb: 1, context: %{}, input: "hello"} # Input is aliased in these doctests

But the defaults can be overwritten

iex(2)> new("hello", 1, 2, []) 
%Input{col: 1, lnb: 2, context: [], input: "hello"}

The keyword syntax is preferred to overwrite default values, for backward compatibility reasons we still support the old syntax, and implement make/2 as shown below

position(input)

@spec position(t()) :: position_t()

report_position(input, name \\ nil)

@spec report_position(t(), binary?()) :: binary()

take(input, str_or_count \\ 1)

@spec take(t(), str_or_count_t()) :: take_and_rest_t()