combinator
This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.
This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.
- Since
2.2.0
Value members
Concrete methods
attemptChoice(ps)
tries to apply the parsers in the list ps
in order, until one of them succeeds.
Returns the value of the succeeding parser. Utilises attempt p <|> q
vs choice's p <|> q
.
attemptChoice(ps)
tries to apply the parsers in the list ps
in order, until one of them succeeds.
Returns the value of the succeeding parser. Utilises attempt p <|> q
vs choice's p <|> q
.
between(open, close, p)
parses open
, followed by p
and close
. Returns the value returned by p
.
between(open, close, p)
parses open
, followed by p
and close
. Returns the value returned by p
.
choice(ps)
tries to apply the parsers in the list ps
in order, until one of them succeeds.
Returns the value of the succeeding parser.
choice(ps)
tries to apply the parsers in the list ps
in order, until one of them succeeds.
Returns the value of the succeeding parser.
decide(p)
removes the option from inside parser p
, and if it returned None
will fail.
decide(p)
removes the option from inside parser p
, and if it returned None
will fail.
decide(p, q)
removes the option from inside parser p
, if it returned None
then q
is executed.
decide(p, q)
removes the option from inside parser p
, if it returned None
then q
is executed.
endBy(p, sep)
parses zero or more occurrences of p
, separated and ended by sep
. Returns a list
of values returned by p
.
endBy(p, sep)
parses zero or more occurrences of p
, separated and ended by sep
. Returns a list
of values returned by p
.
endBy1(p, sep)
parses one or more occurrences of p
, separated and ended by sep
. Returns a list
of values returned by p
.
endBy1(p, sep)
parses one or more occurrences of p
, separated and ended by sep
. Returns a list
of values returned by p
.
many(p)
executes the parser p
zero or more times. Returns a list of the returned values of p
.
many(p)
executes the parser p
zero or more times. Returns a list of the returned values of p
.
- Since
2.2.0
manyN(n, p)
applies the parser p
n or more times. Returns a list of the returned values of p
.
manyN(n, p)
applies the parser p
n or more times. Returns a list of the returned values of p
.
manyUntil(p, end)
applies parser p
zero or more times until the parser end
succeeds.
Returns a list of values returned by p
. This parser can be used to scan comments.
manyUntil(p, end)
applies parser p
zero or more times until the parser end
succeeds.
Returns a list of values returned by p
. This parser can be used to scan comments.
option(p)
tries to apply parser p
. If p
fails without consuming input, it returns
None
, otherwise it returns Some
of the value returned by p
.
option(p)
tries to apply parser p
. If p
fails without consuming input, it returns
None
, otherwise it returns Some
of the value returned by p
.
optional(p) tries to apply parser p
. It will parse p
or nothing. It only fails if p
fails after consuming input. It discards the result of p
.
optional(p) tries to apply parser p
. It will parse p
or nothing. It only fails if p
fails after consuming input. It discards the result of p
.
optionally(p, x) tries to apply parser p
. It will always result in x
regardless of
whether or not p
succeeded or p
failed without consuming input.
optionally(p, x) tries to apply parser p
. It will always result in x
regardless of
whether or not p
succeeded or p
failed without consuming input.
repeat(n, p)
parses n
occurrences of p
. If n
is smaller or equal to zero, the parser is
pure(Nil)
. Returns a list of n
values returned by p
.
repeat(n, p)
parses n
occurrences of p
. If n
is smaller or equal to zero, the parser is
pure(Nil)
. Returns a list of n
values returned by p
.
sepBy(p, sep)
parses zero or more occurrences of p
, separated by sep
. Returns a list
of values returned by p
.
sepBy(p, sep)
parses zero or more occurrences of p
, separated by sep
. Returns a list
of values returned by p
.
sepBy1(p, sep)
parses one or more occurrences of p
, separated by sep
. Returns a list
of values returned by p
.
sepBy1(p, sep)
parses one or more occurrences of p
, separated by sep
. Returns a list
of values returned by p
.
sepEndBy(p, sep)
parses zero or more occurrences of p
, separated and optionally ended
by sep
. Returns a list of values returned by p
.
sepEndBy(p, sep)
parses zero or more occurrences of p
, separated and optionally ended
by sep
. Returns a list of values returned by p
.
sepEndBy1(p, sep)
parses one or more occurrences of p
, separated and optionally ended
by sep
. Returns a list of values returned by p
.
sepEndBy1(p, sep)
parses one or more occurrences of p
, separated and optionally ended
by sep
. Returns a list of values returned by p
.
skipMany(p)
executes the parser p
zero or more times and ignores the results. Returns ()
skipMany(p)
executes the parser p
zero or more times and ignores the results. Returns ()
- Since
2.2.0
skipManyN(n, p)
applies the parser p
n or more times, skipping its result.
skipManyN(n, p)
applies the parser p
n or more times, skipping its result.
skipSome(p)
applies the parser p
one or more times, skipping its result.
skipSome(p)
applies the parser p
one or more times, skipping its result.
some(p)
applies the parser p
one or more times. Returns a list of the returned values of p
.
some(p)
applies the parser p
one or more times. Returns a list of the returned values of p
.
someUntil(p, end)
applies parser p
one or more times until the parser end
succeeds.
Returns a list of values returned by p
.
someUntil(p, end)
applies parser p
one or more times until the parser end
succeeds.
Returns a list of values returned by p
.
when(p, q)
will first perform p
, and if the result is true
will then execute q
or else return unit.
when(p, q)
will first perform p
, and if the result is true
will then execute q
or else return unit.
- Value Params
- p
The first parser to parse
- q
If
p
returnstrue
then this parser is executed
- Returns
()