pelecanus v0.4.0 Pelecanus.Util
Utilities
Link to this section Summary
Functions
Starts linked task and crashes when given parser can’t return in the time
Returns parser which returns error if there are characters not consumed
Returns parser which return {:ok, state}
even if given parser return {:ok, state, value}
Returns parser which invoke given function and apply state
to parser the function returned
Returns parser which map value
given parser returned
Returns parser which unwrap list contains just 1 item
Returns the parser which validate value
that given parser returns
Similiar to validate/2
, but this one invokes given function with state
and value
Link to this section Functions
deadline(Pelecanus.parser(), timeout()) :: Pelecanus.parser()
Starts linked task and crashes when given parser can’t return in the time
This may be used as fuse.
Returns parser which returns error if there are characters not consumed
Returns parser which return {:ok, state}
even if given parser return {:ok, state, value}
Returns parser which invoke given function and apply state
to parser the function returned
Given function is invoked at parsing time and expected to return a parser.
map(Pelecanus.parser(), (Pelecanus.value() -> Pelecanus.value())) :: Pelecanus.parser()
Returns parser which map value
given parser returned
Note that the parser succeeds when given parser succeeds and returns no value
.
Example
iex> use Pelecanus, sigil_p: true
iex> state = State.init("777")
iex> {:ok, _state, value} = map(~p(\d+), fn d -> String.to_integer(d) end).(state)
iex> value
777
Returns parser which unwrap list contains just 1 item
Given parser is expected to return {:ok, state, [value]}
if it return value
.
When it return other pattern, this crash.
Example
iex> use Pelecanus, sigil_p: true
iex> state = State.init("x98")
iex> {:ok, _state, value} = stlip(sequence([ignore(~p(x)), ~p(\d\d)])).(state)
iex> value
"98"
validate(Pelecanus.parser(), (Pelecanus.value() -> boolean())) :: Pelecanus.parser()
Returns the parser which validate value
that given parser returns
Given function will passed the value
when given parser returns some value
.
If the function return true this suceeds, on the other hand this fails.
Note that unlike map/2
, when given parser returns no value
this fails.
validate_with_state( Pelecanus.parser(), (Pelecanus.state(), Pelecanus.value() -> boolean()) ) :: Pelecanus.parser()
Similiar to validate/2
, but this one invokes given function with state
and value
Note that the state
is the parser given, not returned.
In the future this behavior might be changed.
So, don’t change it’s context through given parser, and don’t read it’s offset.