parz/combinators
Values
pub fn as_list(
parser: fn(String) -> Result(types.ParserState(a), err),
) -> fn(String) -> Result(types.ParserState(List(a)), err)
Creates a List from a single parser. Useful for composing with other parsers that may return a List of results
pub fn between(
l: fn(String) -> Result(types.ParserState(a), err),
keep: fn(String) -> Result(types.ParserState(b), err),
r: fn(String) -> Result(types.ParserState(c), err),
) -> fn(String) -> Result(types.ParserState(b), err)
Takes the value between two parsers. Keeps the middle result. Discards the left and right values
pub fn choice(
parsers: List(fn(String) -> Result(types.ParserState(a), err)),
) -> fn(String) -> Result(types.ParserState(a), Nil)
Uses any of the given parsers, returning the result from the first succcessful one.
A Nil error will be returned if none of options could be parsed
pub fn concat_str(
parser: fn(String) -> Result(types.ParserState(List(String)), e),
) -> fn(String) -> Result(types.ParserState(String), e)
Join the results of multiple string-parsers into a single string
pub fn label_error(
parser parser: fn(a) -> Result(b, c),
err err: err,
) -> fn(a) -> Result(b, err)
Customize the error message of a parser
pub fn lazy(
thunk: fn() -> fn(String) -> Result(types.ParserState(a), err),
) -> fn(String) -> Result(types.ParserState(a), err)
Takes a thunk that will be lazily evaluated to a parser. This makes it possible to define recursive parsers
pub fn left(
l: fn(String) -> Result(types.ParserState(a), err),
r: fn(String) -> Result(types.ParserState(b), err),
) -> fn(String) -> Result(types.ParserState(a), err)
Takes the result of the parser on the left, discarding the right result
pub fn many(
parser: fn(String) -> Result(types.ParserState(a), err),
) -> fn(String) -> Result(types.ParserState(List(a)), err)
Tries match the given parser as many times as possible. Returns a list of all parsed results
pub fn many1(
parser: fn(String) -> Result(types.ParserState(a), err),
) -> fn(String) -> Result(types.ParserState(List(a)), err)
Tries match the given parser at least once, and as many more times as possible. Returns a list of all parsed results
pub fn map(
parser parser: fn(String) -> Result(types.ParserState(a), err),
transform transform: fn(a) -> b,
) -> fn(String) -> Result(types.ParserState(b), err)
Call a transform on the successful result of a parser
pub fn map2(
parser parser: fn(String) -> Result(
types.ParserState(#(a, b)),
err,
),
transform transform: fn(a, b) -> c,
) -> fn(String) -> Result(types.ParserState(c), err)
Call a transform on the successful result of a parser that returns a pair
pub fn map_token(
parser parser: fn(String) -> Result(types.ParserState(a), err),
token token: b,
) -> fn(String) -> Result(types.ParserState(b), err)
Convert a parsed result into a fixed-value token
pub fn or(
a: fn(String) -> Result(types.ParserState(t), err),
b: fn(String) -> Result(types.ParserState(t), err),
) -> fn(String) -> Result(types.ParserState(t), err)
Parse the first parser or the second
pub fn padded(
padding padding: fn(String) -> Result(types.ParserState(a), err),
parser parser: fn(String) -> Result(types.ParserState(b), err),
) -> fn(String) -> Result(types.ParserState(b), err)
Pads the parser with the given padding parser on the left and right side. Returns the result of the main parser
pub fn right(
l: fn(String) -> Result(types.ParserState(a), err),
r: fn(String) -> Result(types.ParserState(b), err),
) -> fn(String) -> Result(types.ParserState(b), err)
Takes the result of the parser on the right, discarding the left result
pub fn separator(
parser parser: fn(String) -> Result(types.ParserState(a), err),
sep sep: fn(String) -> Result(types.ParserState(a), err),
) -> fn(String) -> Result(types.ParserState(List(a)), err)
Parses a list of the given parser separated by sep. The results of the given parser will be returned as a List
pub fn separator1(
parser parser: fn(String) -> Result(types.ParserState(a), err),
sep sep: fn(String) -> Result(types.ParserState(a), err),
) -> fn(String) -> Result(types.ParserState(List(a)), Nil)
Parses a list of the given parser separated by sep at least once. The results of the given parser will be returned as a List
pub fn sequence(
parsers: List(fn(String) -> Result(types.ParserState(a), err)),
) -> fn(String) -> Result(types.ParserState(List(a)), err)
Parses the given parsers one after the other and returns the results in a List
pub fn then(
a: fn(String) -> Result(types.ParserState(a), err),
b: fn(String) -> Result(types.ParserState(b), err),
) -> fn(String) -> Result(types.ParserState(#(a, b)), err)
Parse the given parsers sequentially, returning both results as a tuple
pub fn try_map(
parser parser: fn(String) -> Result(types.ParserState(a), err),
transform transform: fn(a) -> Result(b, err),
) -> fn(String) -> Result(types.ParserState(b), err)
Call a transform that may fail on the successful result of a parser