parz/combinators
Values
pub fn as_list(
parser: fn(String) -> Result(types.ParserState(a), String),
) -> fn(String) -> Result(types.ParserState(List(a)), String)
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), String),
keep: fn(String) -> Result(types.ParserState(b), String),
r: fn(String) -> Result(types.ParserState(c), String),
) -> fn(String) -> Result(types.ParserState(b), String)
pub fn choice(
parsers: List(
fn(String) -> Result(types.ParserState(a), String),
),
) -> fn(String) -> Result(types.ParserState(a), String)
Uses any of the given parsers, returning the result from the first succcessful one
pub fn concat_str(
parser: fn(String) -> Result(
types.ParserState(List(String)),
String,
),
) -> fn(String) -> Result(types.ParserState(String), String)
Join the results of multiple string-parsers into a single string
pub fn label_error(
parser parser: fn(a) -> Result(b, c),
message message: d,
) -> fn(a) -> Result(b, d)
Customize the error message of a parser
pub fn lazy(
thunk: fn() -> fn(String) -> Result(
types.ParserState(a),
String,
),
) -> fn(String) -> Result(types.ParserState(a), String)
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), String),
r: fn(String) -> Result(types.ParserState(b), String),
) -> fn(String) -> Result(types.ParserState(a), String)
Takes the result of the parser on the left, discarding the right result
pub fn many(
parser: fn(String) -> Result(types.ParserState(a), String),
) -> fn(String) -> Result(types.ParserState(List(a)), b)
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), String),
) -> fn(String) -> Result(types.ParserState(List(a)), String)
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),
String,
),
transform transform: fn(a) -> b,
) -> fn(String) -> Result(types.ParserState(b), String)
Call a transform on the successful result of a parser
pub fn map_token(
parser parser: fn(String) -> Result(
types.ParserState(a),
String,
),
token token: b,
) -> fn(String) -> Result(types.ParserState(b), String)
Convert a parsed result into a fixed-value token
pub fn padded(
padding padding: fn(String) -> Result(
types.ParserState(a),
String,
),
parser parser: fn(String) -> Result(
types.ParserState(b),
String,
),
) -> fn(String) -> Result(types.ParserState(b), String)
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), String),
r: fn(String) -> Result(types.ParserState(b), String),
) -> fn(String) -> Result(types.ParserState(b), String)
Takes the result of the parser on the right, discarding the left result
pub fn separator(
parser parser: fn(String) -> Result(
types.ParserState(a),
String,
),
sep sep: fn(String) -> Result(types.ParserState(a), String),
) -> fn(String) -> Result(types.ParserState(List(a)), b)
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),
String,
),
sep sep: fn(String) -> Result(types.ParserState(a), String),
) -> fn(String) -> Result(types.ParserState(List(a)), String)
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), String),
),
) -> fn(String) -> Result(types.ParserState(List(a)), String)
Parses the given parsers one after the other and returns the results in a List
pub fn try_map(
parser parser: fn(String) -> Result(
types.ParserState(a),
String,
),
transform transform: fn(a) -> Result(b, String),
) -> fn(String) -> Result(types.ParserState(b), String)
Call a transform that may fail on the successful result of a parser