sealed abstract class Parser[+A] extends Parser0[A]
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.
- Self Type
- Parser[A] with Product
- Source
- Parser.scala
- Alphabetic
- By Inheritance
- Parser
- Parser0
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
*>[B](that: Parser0[B]): Parser[B]
This method overrides
Parser0#*>
to refine the return type. -
def
<*[B](that: Parser0[B]): Parser[A]
This method overrides
Parser0#<*
to refine the return type. -
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
?: Parser0[Option[A]]
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 inSome(_)
).If the underlying parser failed with other errors, this parser will still fail.
- Definition Classes
- Parser0
-
def
as[B](b: B): Parser[B]
This method overrides
Parser0#as
to refine the return type. -
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
backtrack: Parser[A]
This method overrides
Parser0#backtrack
to refine the return type. -
def
between(b: Parser0[Any], c: Parser0[Any]): Parser[A]
This method overrides
Parser0#between
to refine the return type -
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
collect[B](fn: PartialFunction[A, B]): Parser[B]
This method overrides
Parser0#collect
to refine the return type. -
def
eitherOr[B](pb: Parser[B]): Parser[Either[B, A]]
a version of eitherOr when both sides are not Parser0
-
def
eitherOr[B](pb: Parser0[B]): Parser0[Either[B, A]]
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.
- Definition Classes
- Parser0
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
filter(fn: (A) ⇒ Boolean): Parser[A]
This method overrides
Parser0#filter
to refine the return type. -
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
flatMap[B](fn: (A) ⇒ Parser0[B]): Parser[B]
This method overrides
Parser0#flatMap
to refine the return type. -
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
lazy val
hashCode: Int
This method overrides
Object#hashCode
to cache its result for performance reasons.This method overrides
Object#hashCode
to cache its result for performance reasons.- Definition Classes
- Parser0 → AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
map[B](fn: (A) ⇒ B): Parser[B]
This method overrides
Parser0#map
to refine the return type. -
def
mapFilter[B](fn: (A) ⇒ Option[B]): Parser[B]
This method overrides
Parser0#mapFilter
to refine the return type. -
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
orElse[A1 >: A](that: Parser[A1]): Parser[A1]
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.
-
def
orElse[A1 >: A](that: Parser0[A1]): Parser0[A1]
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.
- Definition Classes
- Parser0
-
final
def
parse(str: String): Either[Error, (String, A)]
Attempt to parse an
A
value out ofstr
.Attempt to parse an
A
value out ofstr
.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
.- Definition Classes
- Parser0
-
final
def
parseAll(str: String): Either[Error, A]
Attempt to parse all of the input
str
into anA
value.Attempt to parse all of the input
str
into anA
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)
.- Definition Classes
- Parser0
-
def
peek: Parser0[Unit]
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.
- Definition Classes
- Parser0
-
def
rep(min: Int, max: Int): Parser[NonEmptyList[A]]
Repeat the parser
min
or more times, but no more thanmax
Repeat the parser
min
or more times, but no more thanmax
The parser fails if it can't match at least
min
times After repeating the parsermax
times, the parser completes successfully- Exceptions thrown
java.lang.IllegalArgumentException
if min < 1 or max < min
-
def
rep(min: Int): Parser[NonEmptyList[A]]
Use this parser to parse at least
min
values (wheremin >= 1
).Use this parser to parse at least
min
values (wheremin >= 1
).This method behaves likes
rep
, except that if fewer thanmin
values are produced an arresting failure will be returned. -
def
rep: Parser[NonEmptyList[A]]
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. -
def
rep0(min: Int, max: Int): Parser0[List[A]]
Repeat the parser
min
or more times, but no more thanmax
Repeat the parser
min
or more times, but no more thanmax
The parser fails if it can't match at least
min
times After repeating the parsermax
times, the parser completes successfully- Exceptions thrown
java.lang.IllegalArgumentException
if min < 0 or max < min
-
def
rep0(min: Int): Parser0[List[A]]
Use this parser to parse at least
min
values (wheremin >= 0
).Use this parser to parse at least
min
values (wheremin >= 0
).If
min
is zero, this parser may succeed without consuming input in the case where zero values are parsed. Ifmin
is known to be greater than zero, consider usingrep(min)
instead.Like
rep0
, arresting failures in the underlying parser will result in an arresting failure. Unlikerep0
, this method may also return an arresting failure if it has not parsed at leastmin
values (but has consumed input). -
def
rep0: Parser0[List[A]]
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.
-
def
repAs[B](min: Int, max: Int)(implicit acc: Accumulator[A, B]): Parser[B]
Repeat the parser
min
or more times, but no more thanmax
Repeat the parser
min
or more times, but no more thanmax
The parser fails if it can't match at least
min
times After repeating the parsermax
times, the parser completes successfully- Exceptions thrown
java.lang.IllegalArgumentException
if min < 1 or max < min
-
def
repAs[B](min: Int)(implicit acc: Accumulator[A, B]): Parser[B]
Repeat the parser
min
or more timesRepeat the parser
min
or more timesThe parser fails if it can't match at least
min
times- Exceptions thrown
java.lang.IllegalArgumentException
if min < 1
-
def
repAs[B](implicit acc: Accumulator[A, B]): Parser[B]
Repeat the parser 1 or more times
-
def
repAs0[B](max: Int)(implicit acc: Accumulator0[A, B]): Parser0[B]
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
- Exceptions thrown
java.lang.IllegalArgumentException
if max < 0- Note
this can wind up parsing nothing
-
def
repAs0[B](implicit acc: Accumulator0[A, B]): Parser0[B]
Repeat the parser 0 or more times
Repeat the parser 0 or more times
- Note
this can wind up parsing nothing
-
def
repExactlyAs[B](times: Int)(implicit acc: Accumulator[A, B]): Parser[B]
Repeat the parser exactly
times
timesRepeat the parser exactly
times
times- Exceptions thrown
java.lang.IllegalArgumentException
if times < 1
-
def
repSep(min: Int, max: Int, sep: Parser0[Any]): Parser[NonEmptyList[A]]
Repeat
min
or more, up tomax
times with a separator, at least once.Repeat
min
or more, up tomax
times with a separator, at least once.- Exceptions thrown
java.lang.IllegalArgumentException
ifmin <= 0
ormax < min
-
def
repSep(min: Int, sep: Parser0[Any]): Parser[NonEmptyList[A]]
Repeat
min
or more times with a separator, at least once.Repeat
min
or more times with a separator, at least once.- Exceptions thrown
java.lang.IllegalArgumentException
ifmin <= 0
-
def
repSep(sep: Parser0[Any]): Parser[NonEmptyList[A]]
Repeat 1 or more times with a separator
-
def
repSep0(min: Int, max: Int, sep: Parser0[Any]): Parser0[List[A]]
Repeat
min
or more, up tomax
times with a separator.Repeat
min
or more, up tomax
times with a separator.- Exceptions thrown
java.lang.IllegalArgumentException
ifmin < 0
ormax < min
-
def
repSep0(min: Int, sep: Parser0[Any]): Parser0[List[A]]
Repeat
min
or more times with a separator.Repeat
min
or more times with a separator.- Exceptions thrown
java.lang.IllegalArgumentException
ifmin < 0
-
def
repSep0(sep: Parser0[Any]): Parser0[List[A]]
Repeat 0 or more times with a separator
-
def
repUntil(end: Parser0[Any]): Parser[NonEmptyList[A]]
Repeat this parser 1 or more times until
end
Parser succeeds. -
def
repUntil0(end: Parser0[Any]): Parser0[List[A]]
Repeat this parser 0 or more times until
end
Parser succeeds. -
def
repUntilAs[B](end: Parser0[Any])(implicit acc: Accumulator[A, B]): Parser[B]
Repeat this parser 1 or more times until
end
Parser succeeds. -
def
repUntilAs0[B](end: Parser0[Any])(implicit acc: Accumulator0[A, B]): Parser0[B]
Repeat this parser 0 or more times until
end
Parser succeeds. -
def
soft: Soft[A]
This method overrides
Parser0#soft
to refine the return type. -
def
string: Parser[String]
This method overrides
Parser0#string
to refine the return type. -
def
surroundedBy(b: Parser0[Any]): Parser[A]
This method overrides
Parser0#surroundedBy
to refine the return type -
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
def
unary_!: Parser0[Unit]
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.
- Definition Classes
- Parser0
-
def
void: Parser[Unit]
This method overrides
Parser0#void
to refine the return type. -
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
with1: With1[A]
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]
andp1: 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 returnParser0
values since they are not known to returnParser
values instead.- Definition Classes
- Parser0
-
def
withContext(str: String): Parser[A]
This method overrides
Parser0#withContext
to refine the return type. -
def
|[A1 >: A](that: Parser[A1]): Parser[A1]
Synonym for orElse Note this is not commutative: if this has an arresting failure we do not continue onto the next.
-
def
|[A1 >: A](that: Parser0[A1]): Parser0[A1]
Synonym for orElse Note this is not commutative: if this has an arresting failure we do not continue onto the next.
Synonym for orElse Note this is not commutative: if this has an arresting failure we do not continue onto the next.
- Definition Classes
- Parser0
-
def
~[B](that: Parser0[B]): Parser[(A, B)]
This method overrides
Parser0#~
to refine the return type.