Parser[A] is a Parser0[A] that will always consume one-or-more characters on a successful parse.
Parser[A] is a Parser0[A] that will always consume one-or-more characters on a successful parse.
Since Parser is guaranteed to consume input it provides additional
methods which would be unsafe when used on parsers that succeed
without consuming input, such as rep0
.
When a Parser is composed with a Parser0 the result is usually a
Parser. Parser overrides many of Parser0's methods to refine the
return type. In other cases, callers may need to use the with1
helper method to refine the type of their expressions.
Parser doesn't provide any additional guarantees over Parser0 on what kind of parsing failures it can return.
- Companion
- object
Value members
Concrete methods
This method overrides Parser0#*>
to refine the return type.
This method overrides Parser0#*>
to refine the return type.
- Definition Classes
This method overrides Parser0#<*
to refine the return type.
This method overrides Parser0#<*
to refine the return type.
- Definition Classes
This method overrides Parser0#as
to refine the return type.
This method overrides Parser0#as
to refine the return type.
- Definition Classes
This method overrides Parser0#backtrack
to refine the return type.
This method overrides Parser0#backtrack
to refine the return type.
- Definition Classes
This method overrides Parser0#between
to refine the return type
This method overrides Parser0#between
to refine the return type
- Definition Classes
This method overrides Parser0#collect
to refine the return type.
This method overrides Parser0#collect
to refine the return type.
- Definition Classes
a version of eitherOr when both sides are not Parser0
a version of eitherOr when both sides are not Parser0
This method overrides Parser0#filter
to refine the return type.
This method overrides Parser0#filter
to refine the return type.
- Definition Classes
This method overrides Parser0#flatMap
to refine the return type.
This method overrides Parser0#flatMap
to refine the return type.
- Definition Classes
This method overrides Parser0#map
to refine the return type.
This method overrides Parser0#map
to refine the return type.
- Definition Classes
This method overrides Parser0#mapFilter
to refine the return type.
This method overrides Parser0#mapFilter
to refine the return type.
- Definition Classes
If this parser fails to parse its input with an epsilon error, try the given parser instead.
If this parser fails to parse its input with an epsilon error, try the given parser instead.
This method is similar to Parser0#orElse, but since both arguments are known to be Parser values, the result is known to be a Parser as well.
Use this parser to parse one-or-more values.
Use this parser to parse one-or-more values.
This parser behaves like rep0
, except that it must produce at
least one value, and is guaranteed to consume input on successful
parses.
Use this parser to parse at least min
values (where min >= 1
).
Use this parser to parse at least min
values (where min >= 1
).
This method behaves likes rep
, except that if fewer than min
values are produced an arresting failure will be returned.
Repeat the parser min
or more times, but no more than max
Repeat the parser min
or more times, but no more than max
The parser fails if it can't match at least min
times
After repeating the parser max
times, the parser completes successfully
- Throws
- java.lang.IllegalArgumentException
if min < 1 or max < min
Use this parser to parse zero-or-more values.
Use this parser to parse zero-or-more values.
This parser may succeed without consuming input in the case where zero values are parsed.
If the underlying parser hits an arresting failure, the entire parse is also an arresting failure. If the underlying parser hits an epsilon failure, the parsed values (if any) are returned in a list as a successful parse.
Use this parser to parse at least min
values (where min >= 0
).
Use this parser to parse at least min
values (where min >= 0
).
If min
is zero, this parser may succeed without consuming
input in the case where zero values are parsed. If min
is
known to be greater than zero, consider using rep(min)
instead.
Like rep0
, arresting failures in the underlying parser will
result in an arresting failure. Unlike rep0
, this method may
also return an arresting failure if it has not parsed at least
min
values (but has consumed input).
Repeat the parser min
or more times, but no more than max
Repeat the parser min
or more times, but no more than max
The parser fails if it can't match at least min
times
After repeating the parser max
times, the parser completes successfully
- Throws
- java.lang.IllegalArgumentException
if min < 0 or max < min
Repeat the parser min
or more times
Repeat the parser min
or more times
The parser fails if it can't match at least min
times
- Throws
- java.lang.IllegalArgumentException
if min < 1
Repeat the parser min
or more times, but no more than max
Repeat the parser min
or more times, but no more than max
The parser fails if it can't match at least min
times
After repeating the parser max
times, the parser completes successfully
- Throws
- java.lang.IllegalArgumentException
if min < 1 or max < min
Repeat the parser 0 or more times
Repeat the parser 0 or more times
- Note
this can wind up parsing nothing
Repeat the parser 0 or more times, but no more than max
Repeat the parser 0 or more times, but no more than max
It may seem weird to accept 0 here, but without, composing this method becomes more complex. Since and empty parse is possible for this method, we do allow max = 0
- Throws
- java.lang.IllegalArgumentException
if max < 0
- Note
this can wind up parsing nothing
Repeat the parser exactly times
times
Repeat the parser exactly times
times
- Throws
- java.lang.IllegalArgumentException
if times < 1
Repeat min
or more times with a separator, at least once.
Repeat min
or more times with a separator, at least once.
- Throws
- java.lang.IllegalArgumentException
if
min <= 0
Repeat min
or more, up to max
times with a separator, at least once.
Repeat min
or more, up to max
times with a separator, at least once.
- Throws
- java.lang.IllegalArgumentException
if
min <= 0
ormax < min
Repeat min
or more times with a separator.
Repeat min
or more times with a separator.
- Throws
- java.lang.IllegalArgumentException
if
min < 0
Repeat min
or more, up to max
times with a separator.
Repeat min
or more, up to max
times with a separator.
- Throws
- java.lang.IllegalArgumentException
if
min < 0
ormax < min
Repeat this parser 1 or more times until end
Parser succeeds.
Repeat this parser 1 or more times until end
Parser succeeds.
Repeat this parser 0 or more times until end
Parser succeeds.
Repeat this parser 0 or more times until end
Parser succeeds.
Repeat this parser 1 or more times until end
Parser succeeds.
Repeat this parser 1 or more times until end
Parser succeeds.
Repeat this parser 0 or more times until end
Parser succeeds.
Repeat this parser 0 or more times until end
Parser succeeds.
This method overrides Parser0#soft
to refine the return type.
This method overrides Parser0#soft
to refine the return type.
- Definition Classes
This method overrides Parser0#string
to refine the return type.
This method overrides Parser0#string
to refine the return type.
- Definition Classes
This method overrides Parser0#surroundedBy
to refine the return type
This method overrides Parser0#surroundedBy
to refine the return type
- Definition Classes
This method overrides Parser0#void
to refine the return type.
This method overrides Parser0#void
to refine the return type.
- Definition Classes
This method overrides Parser0#withContext
to refine the return type.
add a string context to any Errors on parsing
this is useful for debugging failing parsers.
This method overrides Parser0#withContext
to refine the return type.
add a string context to any Errors on parsing
this is useful for debugging failing parsers.
- Definition Classes
Inherited methods
Convert epsilon failures into None values.
Convert epsilon failures into None values.
Normally if a parser fails to consume any input it fails with an
epsilon failure. The ?
method converts these failures into
None values (and wraps other values in Some(_)
).
If the underlying parser failed with other errors, this parser will still fail.
- Inherited from
- Parser0
If this parser fails to parse its input with an epsilon error, try the given parser instead.
If this parser fails to parse its input with an epsilon error, try the given parser instead.
If this parser fails with an arresting error, the next parser won't be tried.
Backtracking may be used on the left parser to allow the right one to pick up after any error, resetting any state that was modified by the left parser.
This method is similar to Parser#orElse but returns Either.
- Inherited from
- Parser0
If this parser fails to parse its input with an epsilon error, try the given parser instead.
If this parser fails to parse its input with an epsilon error, try the given parser instead.
If this parser fails with an arresting error, the next parser won't be tried.
Backtracking may be used on the left parser to allow the right one to pick up after any error, resetting any state that was modified by the left parser.
- Inherited from
- Parser0
Attempt to parse an A
value out of str
.
Attempt to parse an A
value out of str
.
This method will either return a failure, or else the remaining string and the parsed value.
To require the entire input to be consumed, see parseAll
.
- Inherited from
- Parser0
Attempt to parse all of the input str
into an A
value.
Attempt to parse all of the input str
into an A
value.
This method will return a failure unless all of str
is consumed
during parsing.
p.parseAll(s)
is equivalent to (p <* Parser.end).parse(s).map(_._2)
.
- Inherited from
- Parser0
Return a parser that succeeds (consuming nothing and extracting nothing) if the current parser would also succeed.
Return a parser that succeeds (consuming nothing and extracting nothing) if the current parser would also succeed.
This parser expects the underlying parser to succeed, and will unconditionally backtrack after running it.
- Inherited from
- Parser0
Return a parser that succeeds (consuming nothing, and extracting nothing) if the current parser would fail.
Return a parser that succeeds (consuming nothing, and extracting nothing) if the current parser would fail.
This parser expects the underlying parser to fail, and will unconditionally backtrack after running it.
- Inherited from
- Parser0
Wrap this parser in a helper class, enabling better composition
with Parser
values.
Wrap this parser in a helper class, enabling better composition
with Parser
values.
For example, with p: Parser0[Int]
and p1: Parser0[Double]
:
val a1: Parser0[(Int, Double)] = p ~ p1 val a2: Parser[(Int, Double)] = p.with1 ~ p1
val b1: Parser0[Double] = p *> p1 val b2: Parser[Double] = p.with1 *> p1
val c1: Parser0[Int] = p <* p1 val c2: Parser[Int] = p.with1 <* p1
Without using with1
, these methods will return Parser0
values
since they are not known to return Parser
values instead.
- Inherited from
- Parser0