View Source Chrysopoeia.Combinator (chrysopoeia v0.1.2)

Core combinators for general use.

Link to this section Summary

Functions

Combinator that adds a condition to an existing parser.

Parser that always errors.

Applies fun to the result of parser on success.

Parser that always succeeds, and consumes nothing.

Link to this section Functions

Link to this function

condition(parser, fun, opts \\ [err_msg: "Condition was not met"])

View Source
@spec condition(Chrysopoeia.parser(i, o, e1), (o -> boolean()), [{:err_msg, e2}]) ::
  Chrysopoeia.parser(i, o, e1 | e2)
when o: var, e2: var

Combinator that adds a condition to an existing parser.

If fun is true, return the value. Otherwise, return an error. The error message is optional.

@spec failure() :: (any() -> {:err, any()})

Parser that always errors.

@spec map(Chrysopoeia.parser(i, t, e), (t -> m)) :: Chrysopoeia.parser(i, m, e)
when t: var, m: var

Applies fun to the result of parser on success.

@spec success() :: (i -> {:ok, nil, i}) when i: var

Parser that always succeeds, and consumes nothing.