Class/Object

cats.parse

Parser0

Related Docs: object Parser0 | package parse

Permalink

sealed abstract class Parser0[+A] extends AnyRef

Parser0[A] attempts to extract an A value from the given input, potentially moving its offset forward in the process.

When calling parse, one of three outcomes occurs:

Operations such as x.orElse(y) will only consider parser y if x returns an epsilon failure; these methods cannot recover from an arresting failure. Arresting failures can be "rewound" using methods such as x.backtrack (which converts arresting failures from x into epsilon failures), or softProduct(x, y) (which can rewind successful parses by x that are followed by epsilon failures for y).

Rewinding tends to make error reporting more difficult and can lead to exponential parser behavior it is not the default behavior.

Self Type
Parser0[A] with Product
Source
Parser.scala
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Parser0
  2. AnyRef
  3. 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]): Parser0[B]

    Permalink

    Compose two parsers, ignoring the values extracted by the left-hand parser.

    Compose two parsers, ignoring the values extracted by the left-hand parser.

    x *> y is equivalent to (x.void ~ y).map(_._2).

  4. def <*[B](that: Parser0[B]): Parser0[A]

    Permalink

    Compose two parsers, ignoring the values extracted by the right-hand parser.

    Compose two parsers, ignoring the values extracted by the right-hand parser.

    x <* y is equivalent to (x ~ y.void).map(_._1).

  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.

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

    Permalink

    Replaces parsed values with the given value.

  8. final def asInstanceOf[T0]: T0

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

    Permalink

    If this parser fails to match, rewind the offset to the starting point before moving on to other parser.

    If this parser fails to match, rewind the offset to the starting point before moving on to other parser.

    This method converts arresting failures into epsilon failures, which includes rewinding the offset to that used before parsing began.

    This method will most often be used before calling methods such as orElse, ~, or flatMap which involve a subsequent parser picking up where this one left off.

  10. def between(b: Parser0[Any], c: Parser0[Any]): Parser0[A]

    Permalink

    Use this parser to parse between values.

    Use this parser to parse between values.

    Parses b followed by this and c. Returns only the values extracted by this parser.

  11. def clone(): AnyRef

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

    Permalink

    Transform parsed values using the given function, or fail when not defined

    Transform parsed values using the given function, or fail when not defined

    When the function is not defined, this parser fails This is implemented with select, which makes it more efficient than using flatMap

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

  14. final def eq(arg0: AnyRef): Boolean

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

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

    Permalink

    If the predicate is not true, fail you may want .filter(fn).backtrack so if the filter fn fails you can fall through in an oneOf0 or orElse

    If the predicate is not true, fail you may want .filter(fn).backtrack so if the filter fn fails you can fall through in an oneOf0 or orElse

    Without the backtrack, a failure of the function will be an arresting failure.

  17. def finalize(): Unit

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

    Permalink

    Dynamically construct the next parser based on the previously parsed value.

    Dynamically construct the next parser based on the previously parsed value.

    Using flatMap is very expensive. When possible, you should prefer to use methods such as ~, *>, or <* when possible, since these are much more efficient.

  19. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  20. 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
  21. final def isInstanceOf[T0]: Boolean

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

    Permalink

    Transform parsed values using the given function.

    Transform parsed values using the given function.

    This parser will match the same inputs as the underlying parser, using the given function f to transform the values the underlying parser produces.

    If the underlying value is ignored (e.g. map(_ => ...)) calling void before map will improve the efficiency of the parser.

  23. def mapFilter[B](fn: (A) ⇒ Option[B]): Parser0[B]

    Permalink

    Transform parsed values using the given function, or fail on None

    Transform parsed values using the given function, or fail on None

    When the function return None, this parser fails This is implemented with select, which makes it more efficient than using flatMap

  24. final def ne(arg0: AnyRef): Boolean

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

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

    Permalink
    Definition Classes
    AnyRef
  27. 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.

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

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

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

  31. def soft: Soft0[A]

    Permalink

    Wrap this parser in a helper class, to enable backtracking during composition.

    Wrap this parser in a helper class, to enable backtracking during composition.

    This wrapper changes the behavior of ~, <* and *>. Normally no backtracking occurs. Using soft on the left-hand side will enable backtracking if the right-hand side returns an epsilon failure (but not in any other case).

    For example, (x ~ y) will never backtrack. But with (x.soft ~ y), if x parses successfully, and y returns an epsilon failure, the parser will "rewind" to the point before x began.

  32. def string: Parser0[String]

    Permalink

    Return the string matched by this parser.

    Return the string matched by this parser.

    When parsing an input string that the underlying parser matches, this parser will return the matched substring instead of any value that the underlying parser would have returned. It will still match exactly the same inputs as the original parser.

    This method is very efficient: similarly to void, we can avoid allocating results to return.

  33. def surroundedBy(b: Parser0[Any]): Parser0[A]

    Permalink

    Use this parser to parse surrounded by values.

    Use this parser to parse surrounded by values.

    This is the same as between(b, b)

  34. final def synchronized[T0](arg0: ⇒ T0): T0

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

    Permalink
    Definition Classes
    AnyRef → Any
  36. 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.

  37. def void: Parser0[Unit]

    Permalink

    Parse without capturing values.

    Parse without capturing values.

    Calling void on a parser can be a significant optimization -- it allows the parser to avoid allocating results to return.

    Other methods like as, *>, and <* use void internally to discard allocations, since they will ignore the original parsed result.

  38. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  41. 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.

  42. def withContext(str: String): Parser0[A]

    Permalink

    Add a string context to any Errors on parsing this is useful for debugging failing parsers.

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

  44. def ~[B](that: Parser0[B]): Parser0[(A, B)]

    Permalink

    Sequence another parser after this one, combining both results into a tuple.

    Sequence another parser after this one, combining both results into a tuple.

    This combinator returns a product of parsers. If this parser successfully produces an A value, the other parser is run on the remaining input to try to produce a B value.

    If either parser produces an error the result is an error. Otherwise both extracted values are combined into a tuple.

Inherited from AnyRef

Inherited from Any

Ungrouped