Object/Class

cats.parse

Parser

Related Docs: class Parser | package parse

Permalink

object Parser

Source
Parser.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Parser
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. class Error extends Product with Serializable

    Permalink

    Represents where a failure occurred and all the expectations that were broken

  2. sealed abstract class Expectation extends AnyRef

    Permalink

    An expectation reports the kind or parsing error and where it occured.

  3. final class Soft[+A] extends Soft0[A]

    Permalink

    If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming.

    If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming. If either consume 1 or more, do not rewind

  4. sealed class Soft0[+A] extends AnyRef

    Permalink

    If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming.

    If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming. If either consume 1 or more, do not rewind

  5. final class Soft01[+A] extends AnyVal

    Permalink

    If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming.

    If we can parse this then that, do so, if we fail that without consuming, rewind before this without consuming. If either consume 1 or more, do not rewind

  6. final class State extends AnyRef

    Permalink
    Attributes
    protected[cats.parse]
  7. final class With1[+A] extends AnyVal

    Permalink

    Enables syntax to access product01, product and flatMap01 This helps us build Parser instances when starting from a Parser0

Value Members

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. object Error extends AbstractFunction2[Int, NonEmptyList[Expectation], Error] with Serializable

    Permalink
  5. object ErrorWithInput

    Permalink
  6. object Expectation

    Permalink
  7. val Fail: Parser[Nothing]

    Permalink

    A parser that always fails with an epsilon failure

  8. def anyChar: Parser[Char]

    Permalink

    Parse 1 character from the string

  9. def as[B](pa: Parser[Any], b: B): Parser[B]

    Permalink

    Replaces parsed values with the given value.

  10. def as0[B](pa: Parser0[Any], b: B): Parser0[B]

    Permalink

    Replaces parsed values with the given value.

  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. def backtrack[A](pa: Parser[A]): Parser[A]

    Permalink

    If we fail, rewind the offset back so that we can try other branches.

    If we fail, rewind the offset back so that we can try other branches. This tends to harm debuggability and ideally should be minimized

  13. def backtrack0[A](pa: Parser0[A]): Parser0[A]

    Permalink

    If we fail, rewind the offset back so that we can try other branches.

    If we fail, rewind the offset back so that we can try other branches. This tends to harm debuggability and ideally should be minimized

  14. def caret: Parser0[Caret]

    Permalink

    return the current Caret (offset, line, column) this is a bit more expensive that just the index

  15. implicit val catsInstancesParser: FlatMap[Parser] with Defer[Parser] with MonoidK[Parser] with FunctorFilter[Parser]

    Permalink
  16. def char(c: Char): Parser[Unit]

    Permalink

    parse a single character

  17. def charIn(c0: Char, cs: Char*): Parser[Char]

    Permalink

    parse one of a given set of characters

  18. def charIn(cs: Iterable[Char]): Parser[Char]

    Permalink

    An empty iterable is the same as fail

  19. def charWhere(fn: (Char) ⇒ Boolean): Parser[Char]

    Permalink

    parse one character that matches a given function

  20. def charsWhile(fn: (Char) ⇒ Boolean): Parser[String]

    Permalink

    Parse a string while the given function is true parses at least one character

  21. def charsWhile0(fn: (Char) ⇒ Boolean): Parser0[String]

    Permalink

    Parse a string while the given function is true

  22. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. def defer[A](pa: ⇒ Parser[A]): Parser[A]

    Permalink

    Lazily create a Parser This is useful to create some recursive parsers see Defer0[Parser].fix

  24. def defer0[A](pa: ⇒ Parser0[A]): Parser0[A]

    Permalink

    Lazily create a Parser0 This is useful to create some recursive parsers see Defer0[Parser].fix

  25. def eitherOr[A, B](first: Parser[B], second: Parser[A]): Parser[Either[A, B]]

    Permalink

    If the first parser fails to parse its input with an epsilon error, try the second parser instead.

    If the first parser fails to parse its input with an epsilon error, try the second parser instead.

    If the first parser fails with an arresting error, the second parser won't be tried.

    Backtracking may be used on the first parser to allow the second one to pick up after any error, resetting any state that was modified by the first parser.

  26. def eitherOr0[A, B](first: Parser0[B], second: Parser0[A]): Parser0[Either[A, B]]

    Permalink

    If the first parser fails to parse its input with an epsilon error, try the second parser instead.

    If the first parser fails to parse its input with an epsilon error, try the second parser instead.

    If the first parser fails with an arresting error, the second parser won't be tried.

    Backtracking may be used on the first parser to allow the second one to pick up after any error, resetting any state that was modified by the first parser.

  27. def end: Parser0[Unit]

    Permalink

    succeeds when we are at the end

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

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

    Permalink
    Definition Classes
    AnyRef → Any
  30. def fail[A]: Parser[A]

    Permalink

    A parser that always fails with an epsilon failure

  31. def failWith[A](message: String): Parser[A]

    Permalink

    A parser that always fails with an epsilon failure and a given message this is generally used with flatMap to validate a result beyond the literal parsing.

    A parser that always fails with an epsilon failure and a given message this is generally used with flatMap to validate a result beyond the literal parsing.

    e.g. parsing a number then validate that it is bounded.

  32. def finalize(): Unit

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

    Permalink

    Standard monadic flatMap Avoid this function if possible.

    Standard monadic flatMap Avoid this function if possible. If you can instead use product, ~, *>, or <* use that. flatMap always has to allocate a parser, and the parser is less amenable to optimization

  34. def flatMap01[A, B](pa: Parser0[A])(fn: (A) ⇒ Parser[B]): Parser[B]

    Permalink

    Standard monadic flatMap where you end with a Parser Avoid this function if possible.

    Standard monadic flatMap where you end with a Parser Avoid this function if possible. If you can instead use product, ~, *>, or <* use that. flatMap always has to allocate a parser, and the parser is less amenable to optimization

  35. def flatMap10[A, B](pa: Parser[A])(fn: (A) ⇒ Parser0[B]): Parser[B]

    Permalink

    Standard monadic flatMap where you start with a Parser Avoid this function if possible.

    Standard monadic flatMap where you start with a Parser Avoid this function if possible. If you can instead use product, ~, *>, or <* use that. flatMap always has to allocate a parser, and the parser is less amenable to optimization

  36. def fromCharMap[A](charMap: Map[Char, A]): Parser[A]

    Permalink

    Convert a Map[Char, A] to Parser[A] first match a character, then map it to a value A

  37. def fromStringMap[A](stringMap: Map[String, A]): Parser[A]

    Permalink

    Convert a Map[String, A] to Parser[A] first match a character, then map it to a value A This throws if any of the keys are the empty string

  38. def fromStringMap0[A](stringMap: Map[String, A]): Parser0[A]

    Permalink

    Convert a Map[String, A] to Parser[A] first match a character, then map it to a value A

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

    Permalink
    Definition Classes
    AnyRef → Any
  40. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  41. def ignoreCase(str: String): Parser[Unit]

    Permalink

    Parse a given string, in a case-insensitive manner, or fail.

    Parse a given string, in a case-insensitive manner, or fail. This backtracks on failure this is an error if the string is empty

  42. def ignoreCase0(str: String): Parser0[Unit]

    Permalink

    Parse a potentially empty string, in a case-insensitive manner, or fail.

    Parse a potentially empty string, in a case-insensitive manner, or fail. This backtracks on failure

  43. def ignoreCaseChar(c: Char): Parser[Unit]

    Permalink

    Ignore the case of a single character If you want to know if it is upper or lower, use .string to capture the string and then map to process the result.

  44. def ignoreCaseCharIn(c0: Char, cs: Char*): Parser[Char]

    Permalink

    Parse any single character in a set of characters as lower or upper case

  45. def ignoreCaseCharIn(cs: Iterable[Char]): Parser[Char]

    Permalink

    Parse any single character in a set of characters as lower or upper case

  46. def index: Parser0[Int]

    Permalink

    return the current position in the string we are parsing.

    return the current position in the string we are parsing. This lets you record position information in your ASTs you are parsing

  47. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  48. def length(len: Int): Parser[String]

    Permalink

    Parse the next len characters where len > 0 if (len < 1) throw IllegalArgumentException

  49. def length0(len: Int): Parser0[String]

    Permalink

    if len < 1, the same as pure("") else length(len)

  50. def map[A, B](p: Parser[A])(fn: (A) ⇒ B): Parser[B]

    Permalink

    transform a Parser result

  51. def map0[A, B](p: Parser0[A])(fn: (A) ⇒ B): Parser0[B]

    Permalink

    transform a Parser0 result

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

    Permalink
    Definition Classes
    AnyRef
  53. def not(pa: Parser0[Any]): Parser0[Unit]

    Permalink

    returns a parser that succeeds if the current parser fails.

    returns a parser that succeeds if the current parser fails. Note, this parser backtracks (never returns an arresting failure)

  54. final def notify(): Unit

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

    Permalink
    Definition Classes
    AnyRef
  56. def oneOf[A](parsers: List[Parser[A]]): Parser[A]

    Permalink

    go through the list of parsers trying each as long as they are epsilon failures (don't advance) see @backtrack if you want to do backtracking.

    go through the list of parsers trying each as long as they are epsilon failures (don't advance) see @backtrack if you want to do backtracking.

    This is the same as parsers.foldLeft(fail)(_.orElse(_))

    recommended style: oneOf(p1 :: p2 :: p3 :: Nil) rather than oneOf(List(p1, p2, p3))

    Note: order matters here, since we don't backtrack by default.

  57. def oneOf0[A](ps: List[Parser0[A]]): Parser0[A]

    Permalink

    go through the list of parsers trying each as long as they are epsilon failures (don't advance) see @backtrack if you want to do backtracking.

    go through the list of parsers trying each as long as they are epsilon failures (don't advance) see @backtrack if you want to do backtracking.

    This is the same as parsers.foldLeft(fail)(_.orElse(_))

    recommended style: oneOf(p1 :: p2 :: p3 :: Nil) rather than oneOf(List(p1, p2, p3))

    Note: order matters here, since we don't backtrack by default.

  58. def peek(pa: Parser0[Any]): Parser0[Unit]

    Permalink

    a parser that consumes nothing when it succeeds, basically rewind on success

  59. def product0[A, B](first: Parser0[A], second: Parser0[B]): Parser0[(A, B)]

    Permalink

    parse first then second

  60. def product01[A, B](first: Parser0[A], second: Parser[B]): Parser[(A, B)]

    Permalink

    product with the second argument being a Parser

  61. def product10[A, B](first: Parser[A], second: Parser0[B]): Parser[(A, B)]

    Permalink

    product with the first argument being a Parser

  62. def pure[A](a: A): Parser0[A]

    Permalink

    Don't advance in the parsed string, just return a This is used by the Applicative typeclass.

  63. def recursive[A](fn: (Parser[A]) ⇒ Parser[A]): Parser[A]

    Permalink

    Build a recursive parser by assuming you have it Useful for parsing recurive structures, like for instance JSON.

  64. def repAs[A, B](p1: Parser[A], 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 succesfully

    Exceptions thrown

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

  65. def repAs[A, B](p1: Parser[A], 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

  66. def repAs0[A, B](p1: Parser[A], 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

  67. def repAs0[A, B](p1: Parser[A])(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

  68. def repExactlyAs[A, B](p: Parser[A], 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

  69. def repSep[A](p1: Parser[A], 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

  70. def repSep[A](p1: Parser[A], 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

  71. def repSep[A](p1: Parser[A], sep: Parser0[Any]): Parser[NonEmptyList[A]]

    Permalink

    Repeat 1 or more times with a separator

  72. def repSep0[A](p1: Parser[A], 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

  73. def repSep0[A](p1: Parser[A], 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

  74. def repSep0[A](p1: Parser[A], sep: Parser0[Any]): Parser0[List[A]]

    Permalink

    Repeat 0 or more times with a separator

  75. def repUntil[A](p: Parser[A], end: Parser0[Any]): Parser[NonEmptyList[A]]

    Permalink

    parse one or more times until Parser end succeeds.

  76. def repUntil0[A](p: Parser[A], end: Parser0[Any]): Parser0[List[A]]

    Permalink

    parse zero or more times until Parser end succeeds.

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

    Permalink

    parse one or more times until Parser end succeeds.

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

    Permalink

    parse zero or more times until Parser end succeeds.

  79. def select[A, B](p: Parser[Either[A, B]])(fn: Parser0[(A) ⇒ B]): Parser[B]

    Permalink

    Parser version of select

  80. def select0[A, B](p: Parser0[Either[A, B]])(fn: Parser0[(A) ⇒ B]): Parser0[B]

    Permalink

    Parse p and if we get the Left side, parse fn This function name comes from seletive functors.

    Parse p and if we get the Left side, parse fn This function name comes from seletive functors. This should be more efficient than flatMap since the fn Parser0 is evaluated once, not on every item parsed

  81. def softProduct0[A, B](first: Parser0[A], second: Parser0[B]): Parser0[(A, B)]

    Permalink

    softProduct, a variant of product A soft product backtracks if the first succeeds and the second is an epsilon-failure.

    softProduct, a variant of product A soft product backtracks if the first succeeds and the second is an epsilon-failure. By contrast product will be a failure in that case

    see @Parser.soft

  82. def softProduct01[A, B](first: Parser0[A], second: Parser[B]): Parser[(A, B)]

    Permalink

    softProduct with the second argument being a Parser A soft product backtracks if the first succeeds and the second is an epsilon-failure.

    softProduct with the second argument being a Parser A soft product backtracks if the first succeeds and the second is an epsilon-failure. By contrast product will be a failure in that case

    see @Parser.soft

  83. def softProduct10[A, B](first: Parser[A], second: Parser0[B]): Parser[(A, B)]

    Permalink

    softProduct with the first argument being a Parser A soft product backtracks if the first succeeds and the second is an epsilon-failure.

    softProduct with the first argument being a Parser A soft product backtracks if the first succeeds and the second is an epsilon-failure. By contrast product will be a failure in that case

    see @Parser.soft

  84. def start: Parser0[Unit]

    Permalink

    succeeds when we are at the start

  85. def string(pa: Parser[Any]): Parser[String]

    Permalink

    Discard the result A and instead capture the matching string this is optimized to avoid internal allocations

  86. def string(str: String): Parser[Unit]

    Permalink

    Parse a given string or fail.

    Parse a given string or fail. This backtracks on failure this is an error if the string is empty

  87. def string0(pa: Parser0[Any]): Parser0[String]

    Permalink

    Discard the result A and instead capture the matching string this is optimized to avoid internal allocations

  88. def string0(str: String): Parser0[Unit]

    Permalink

    Parse a potentially empty string or fail.

    Parse a potentially empty string or fail. This backtracks on failure

  89. def stringIn(strings: Iterable[String]): Parser[String]

    Permalink

    Parse the longest matching string between alternatives.

    Parse the longest matching string between alternatives. The order of the strings does not matter.

    If no string matches, this parser results in an epsilon failure.

    It is an error to pass the empty string here, if you need that see stringIn0

  90. def stringIn0(strings: Iterable[String]): Parser0[String]

    Permalink

    Version of stringIn that allows the empty string

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

    Permalink
    Definition Classes
    AnyRef
  92. def tailRecM[A, B](init: A)(fn: (A) ⇒ Parser[Either[A, B]]): Parser[B]

    Permalink

    tail recursive monadic flatMaps on Parser This is a rarely used function, but needed to implement cats.FlatMap Avoid this function if possible.

    tail recursive monadic flatMaps on Parser This is a rarely used function, but needed to implement cats.FlatMap Avoid this function if possible. If you can instead use product, ~, *>, or <* use that. flatMap always has to allocate a parser, and the parser is less amenable to optimization

  93. def tailRecM0[A, B](init: A)(fn: (A) ⇒ Parser0[Either[A, B]]): Parser0[B]

    Permalink

    tail recursive monadic flatMaps This is a rarely used function, but needed to implement cats.FlatMap Avoid this function if possible.

    tail recursive monadic flatMaps This is a rarely used function, but needed to implement cats.FlatMap Avoid this function if possible. If you can instead use product, ~, *>, or <* use that. flatMap always has to allocate a parser, and the parser is less amenable to optimization

  94. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  95. val unit: Parser0[Unit]

    Permalink

    A parser that returns unit

  96. def until(p: Parser0[Any]): Parser[String]

    Permalink

    parse one or more characters as long as they don't match p

  97. def until0(p: Parser0[Any]): Parser0[String]

    Permalink

    parse zero or more characters as long as they don't match p this is useful for parsing comment strings, for instance.

  98. def void(pa: Parser[Any]): Parser[Unit]

    Permalink

    discard the value in a Parser.

    discard the value in a Parser. This is an optimization because we remove trailing map operations and don't allocate internal data structures This function is called internal to Functor.as and Apply.*> and Apply.<* so those are good uses.

  99. def void0(pa: Parser0[Any]): Parser0[Unit]

    Permalink

    discard the value in a Parser.

    discard the value in a Parser. This is an optimization because we remove trailing map operations and don't allocate internal data structures This function is called internal to Functor.as and Apply.*> and Apply.<* so those are good uses.

  100. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  103. def withContext[A](p: Parser[A], ctx: String): Parser[A]

    Permalink

    Add a context string to Errors to aid debugging

  104. def withContext0[A](p0: Parser0[A], ctx: String): Parser0[A]

    Permalink

    Add a context string to Errors to aid debugging

  105. def withString[A](pa: Parser[A]): Parser[(A, String)]

    Permalink

    Return the value and the input string matched

  106. def withString0[A](pa: Parser0[A]): Parser0[(A, String)]

    Permalink

    Return the value and the input string matched

Inherited from AnyRef

Inherited from Any

Ungrouped