An input wrapper
Summary
Functions
The preferred syntax to create Input structs
new just generates an Input struct with default values
Just take without returning drop too
Types
@type ast_list_t() :: [ast_t()]
@type ast_t() :: any()
@type atoms() :: [atom()]
@type binaries() :: [binary()]
@type continue_fun_t() :: (t(), ast_t() -> continue_return_t())
@type either(success_t, error_t) :: {:ok, success_t} | {:error, error_t}
@type input_arg_t() :: {:col, pos_integer()} | {:lnb, pos_integer()} | {:context, any()}
@type input_args_t() :: [input_arg_t()]
@type maybe(t) :: nil | t
@type parser_function_t() :: (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 satisfier2_t() :: (any(), t() -> satisfier_result_t())
@type satisfier_t() :: (any() -> satisfier_result_t())
@type str_or_count_t() :: binary() | non_neg_integer()
@type t() :: %Minipeg.Input{ col: pos_integer(), context: map(), input: binary(), lnb: pos_integer() }
@type token_comp_t() :: [token1_comp_t()]
@type token_spec_t() :: [token1_spec_t()]
Functions
@spec drop(t(), str_or_count_t()) :: t()
@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 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 doctestsBut 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
@spec peek(t(), pos_integer()) :: String.t()
Just take without returning drop too
iex(6)> peek(new("alpha"))
"a"
iex(7)> peek(new(""))
""
iex(8)> peek(new("alpha"), 2)
"al"
iex(9)> peek(new("alpha"), 9)
"alpha"
@spec position(t()) :: position_t()
@spec take(t(), str_or_count_t()) :: take_and_rest_t()