Class/Object

cats.parse

Parser

Related Docs: object Parser | package parse

Permalink

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
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Parser
  2. Parser0
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def *>[B](that: Parser0[B]): Parser[B]

    Permalink

    This method overrides Parser0#*> to refine the return type.

    This method overrides Parser0#*> to refine the return type.

    Definition Classes
    ParserParser0
  4. def <*[B](that: Parser0[B]): Parser[A]

    Permalink

    This method overrides Parser0#<* to refine the return type.

    This method overrides Parser0#<* to refine the return type.

    Definition Classes
    ParserParser0
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def ?: Parser0[Option[A]]

    Permalink

    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.

    Definition Classes
    Parser0
  7. def as[B](b: B): Parser[B]

    Permalink

    This method overrides Parser0#as to refine the return type.

    This method overrides Parser0#as to refine the return type.

    Definition Classes
    ParserParser0
  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. def backtrack: Parser[A]

    Permalink

    This method overrides Parser0#backtrack to refine the return type.

    This method overrides Parser0#backtrack to refine the return type.

    Definition Classes
    ParserParser0
  10. def between(b: Parser0[Any], c: Parser0[Any]): Parser[A]

    Permalink

    This method overrides Parser0#between to refine the return type

    This method overrides Parser0#between to refine the return type

    Definition Classes
    ParserParser0
  11. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. def collect[B](fn: PartialFunction[A, B]): Parser[B]

    Permalink

    This method overrides Parser0#collect to refine the return type.

    This method overrides Parser0#collect to refine the return type.

    Definition Classes
    ParserParser0
  13. def eitherOr[B](pb: Parser[B]): Parser[Either[B, A]]

    Permalink

    a version of eitherOr when both sides are not Parser0

  14. def eitherOr[B](pb: Parser0[B]): Parser0[Either[B, A]]

    Permalink

    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
  15. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  17. def filter(fn: (A) ⇒ Boolean): Parser[A]

    Permalink

    This method overrides Parser0#filter to refine the return type.

    This method overrides Parser0#filter to refine the return type.

    Definition Classes
    ParserParser0
  18. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  19. def flatMap[B](fn: (A) ⇒ Parser0[B]): Parser[B]

    Permalink

    This method overrides Parser0#flatMap to refine the return type.

    This method overrides Parser0#flatMap to refine the return type.

    Definition Classes
    ParserParser0
  20. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  21. lazy val hashCode: Int

    Permalink

    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
  22. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  23. def map[B](fn: (A) ⇒ B): Parser[B]

    Permalink

    This method overrides Parser0#map to refine the return type.

    This method overrides Parser0#map to refine the return type.

    Definition Classes
    ParserParser0
  24. def mapFilter[B](fn: (A) ⇒ Option[B]): Parser[B]

    Permalink

    This method overrides Parser0#mapFilter to refine the return type.

    This method overrides Parser0#mapFilter to refine the return type.

    Definition Classes
    ParserParser0
  25. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  26. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  28. def orElse[A1 >: A](that: Parser[A1]): Parser[A1]

    Permalink

    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.

  29. def orElse[A1 >: A](that: Parser0[A1]): Parser0[A1]

    Permalink

    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
  30. final def parse(str: String): Either[Error, (String, A)]

    Permalink

    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.

    Definition Classes
    Parser0
  31. final def parseAll(str: String): Either[Error, A]

    Permalink

    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).

    Definition Classes
    Parser0
  32. def peek: Parser0[Unit]

    Permalink

    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
  33. def rep(min: Int, max: Int): Parser[NonEmptyList[A]]

    Permalink

    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

    Exceptions thrown

    java.lang.IllegalArgumentException if min < 1 or max < min

  34. def rep(min: Int): Parser[NonEmptyList[A]]

    Permalink

    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.

  35. def rep: Parser[NonEmptyList[A]]

    Permalink

    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.

  36. def rep0(min: Int, max: Int): Parser0[List[A]]

    Permalink

    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

    Exceptions thrown

    java.lang.IllegalArgumentException if min < 0 or max < min

  37. def rep0(min: Int): Parser0[List[A]]

    Permalink

    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).

  38. def rep0: Parser0[List[A]]

    Permalink

    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.

  39. def repAs[B](min: Int, max: Int)(implicit acc: Accumulator[A, B]): Parser[B]

    Permalink

    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

    Exceptions thrown

    java.lang.IllegalArgumentException if min < 1 or max < min

  40. def repAs[B](min: Int)(implicit acc: Accumulator[A, B]): Parser[B]

    Permalink

    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

    Exceptions thrown

    java.lang.IllegalArgumentException if min < 1

  41. def repAs[B](implicit acc: Accumulator[A, B]): Parser[B]

    Permalink

    Repeat the parser 1 or more times

  42. def repAs0[B](max: Int)(implicit acc: Accumulator0[A, B]): Parser0[B]

    Permalink

    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

  43. def repAs0[B](implicit acc: Accumulator0[A, B]): Parser0[B]

    Permalink

    Repeat the parser 0 or more times

    Repeat the parser 0 or more times

    Note

    this can wind up parsing nothing

  44. def repExactlyAs[B](times: Int)(implicit acc: Accumulator[A, B]): Parser[B]

    Permalink

    Repeat the parser exactly times times

    Repeat the parser exactly times times

    Exceptions thrown

    java.lang.IllegalArgumentException if times < 1

  45. def repSep(min: Int, max: Int, sep: Parser0[Any]): Parser[NonEmptyList[A]]

    Permalink

    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.

    Exceptions thrown

    java.lang.IllegalArgumentException if min <= 0 or max < min

  46. def repSep(min: Int, sep: Parser0[Any]): Parser[NonEmptyList[A]]

    Permalink

    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 if min <= 0

  47. def repSep(sep: Parser0[Any]): Parser[NonEmptyList[A]]

    Permalink

    Repeat 1 or more times with a separator

  48. def repSep0(min: Int, max: Int, sep: Parser0[Any]): Parser0[List[A]]

    Permalink

    Repeat min or more, up to max times with a separator.

    Repeat min or more, up to max times with a separator.

    Exceptions thrown

    java.lang.IllegalArgumentException if min < 0 or max < min

  49. def repSep0(min: Int, sep: Parser0[Any]): Parser0[List[A]]

    Permalink

    Repeat min or more times with a separator.

    Repeat min or more times with a separator.

    Exceptions thrown

    java.lang.IllegalArgumentException if min < 0

  50. def repSep0(sep: Parser0[Any]): Parser0[List[A]]

    Permalink

    Repeat 0 or more times with a separator

  51. def repUntil(end: Parser0[Any]): Parser[NonEmptyList[A]]

    Permalink

    Repeat this parser 1 or more times until end Parser succeeds.

  52. def repUntil0(end: Parser0[Any]): Parser0[List[A]]

    Permalink

    Repeat this parser 0 or more times until end Parser succeeds.

  53. def repUntilAs[B](end: Parser0[Any])(implicit acc: Accumulator[A, B]): Parser[B]

    Permalink

    Repeat this parser 1 or more times until end Parser succeeds.

  54. def repUntilAs0[B](end: Parser0[Any])(implicit acc: Accumulator0[A, B]): Parser0[B]

    Permalink

    Repeat this parser 0 or more times until end Parser succeeds.

  55. def soft: Soft[A]

    Permalink

    This method overrides Parser0#soft to refine the return type.

    This method overrides Parser0#soft to refine the return type.

    Definition Classes
    ParserParser0
  56. def string: Parser[String]

    Permalink

    This method overrides Parser0#string to refine the return type.

    This method overrides Parser0#string to refine the return type.

    Definition Classes
    ParserParser0
  57. def surroundedBy(b: Parser0[Any]): Parser[A]

    Permalink

    This method overrides Parser0#surroundedBy to refine the return type

    This method overrides Parser0#surroundedBy to refine the return type

    Definition Classes
    ParserParser0
  58. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  59. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  60. def unary_!: Parser0[Unit]

    Permalink

    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
  61. def void: Parser[Unit]

    Permalink

    This method overrides Parser0#void to refine the return type.

    This method overrides Parser0#void to refine the return type.

    Definition Classes
    ParserParser0
  62. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  63. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  65. def with1: With1[A]

    Permalink

    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.

    Definition Classes
    Parser0
  66. def withContext(str: String): Parser[A]

    Permalink

    This method overrides Parser0#withContext to refine the return type.

    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
    ParserParser0
  67. def |[A1 >: A](that: Parser[A1]): Parser[A1]

    Permalink

    Synonym for orElse Note this is not commutative: if this has an arresting failure we do not continue onto the next.

  68. def |[A1 >: A](that: Parser0[A1]): Parser0[A1]

    Permalink

    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
  69. def ~[B](that: Parser0[B]): Parser[(A, B)]

    Permalink

    This method overrides Parser0#~ to refine the return type.

    This method overrides Parser0#~ to refine the return type.

    Definition Classes
    ParserParser0

Inherited from Parser0[A]

Inherited from AnyRef

Inherited from Any

Ungrouped