pelecanus v0.3.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 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

Similar to lazy/1 but given Module, function_name and args as list

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

Link to this function deadline(e, timeout \\ 5000)

Starts linked task and crashes when given parser can’t return in the time.

This may be used as fuse.

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.

Link to this function lazy(mod, fun, args)
lazy(module(), atom(), [term()]) :: Pelecanus.parser()

Similar to lazy/1 but given Module, function_name and args as list.

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"

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.

Link to this function validate_with_state(e, fun)
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.