combinators
identity
Identity parser, returns the Parser as is.
pure
A parser that will have the argument as its output, no matter what the input was. It doesn't consume any input.
optional
Optionally parse something, but still succeed if the thing is not there
bind
Create a parser that takes the output from the first parser (if successful) and feeds it to the callable. The callable must return another parser. If the first parser fails, the first parser is returned.
This is a monadic bind aka flatmap.
sequence
Parse something, then follow by something else. Ignore the result of the first parser and return the result of the second parser.
keepFirst
Sequence two parsers, and return the output of the first one.
keepSecond
Sequence two parsers, and return the output of the second one.
either
Either parse the first thing or the second thing
append
Combine the parser with another parser of the same type, which will cause the results to be appended.
assemble
Append all the passed parsers.
collect
Parse into an array that consists of the results of all parsers.
any
Tries each parser one by one, returning the result of the first one that succeeds.
choice
Tries each parser one by one, returning the result of the first one that succeeds.
Alias for {@see any()}
atLeastOne
One or more repetitions of Parser
repeat
Parse something exactly n times
repeatList
Parse something exactly n times and return as an array
many
Parse something zero or more times, and output an array of the successful outputs.
some
Parse something one or more times, and output an array of the successful outputs.
between
Parse $open, followed by $middle, followed by $close, and return the result of $middle. Useful for eg. "(value)".
sepBy
Parses zero or more occurrences of $parser, separated by $separator. Returns a list of values.
The sepBy parser always succeed, even if it doesn't find anything. Use {@see sepBy1()} if you want it to find at least one value.
sepBy1
Parses one or more occurrences of $parser, separated by $separator. Returns a list of values.
notFollowedBy
notFollowedBy only succeeds when $parser fails. It never consumes any input.
Example:
string("print")
will also match "printXYZ"
keepFirst(string("print"), notFollowedBy(alphaNumChar()))
will match "print something" but not "printXYZ something"