Packages

  • package root

    This is the documentation for Parsley.

    This is the documentation for Parsley.

    Package structure

    The parsley package contains the Parsley class, as well as the Result, Success, and Failure types. In addition to these, it also contains the following packages and "modules" (a module is defined as being an object which mocks a package):

    • parsley.Parsley contains the bulk of the core "function-style" combinators, as well as the implicit classes which enable the "method-style" combinators.
    • parsley.combinator contains many helpful combinators that simplify some common parser patterns.
    • parsley.character contains the combinators needed to read characters and strings, as well as combinators to match specific sub-sets of characters.
    • parsley.debug contains debugging combinators, helpful for identifying faults in parsers.
    • parsley.expr contains the following sub modules:
    • parsley.implicits contains several implicits to add syntactic sugar to the combinators, such as being able to use character and string literals directly as parsers, as well as enabling lifting of functions to work on parsers.
    • parsley.lift contains functions which lift functions that work on regular types to those which now combine the results of parsers returning those same types. these are ubiquitous.
    • parsley.registers contains combinators that interact with the context-sensitive functionality in the form of registers.
    • parsley.token contains the Lexer class that provides a host of helpful lexing combinators when provided with the description of a language.
    • parsley.unsafe contains unsafe (and not thread-safe) ways of speeding up the execution of a parser.

    In addition to the modules and packages outlined above, this version of Parsley (up to version 3.0), also includes the so-called old-style API, which is deprecated (see the Parsley wiki for a discussion of these differences). You should use the modules described above, and avoid the following:

    • parsley.BitGen
    • parsley.Char
    • parsley.CharSet
    • parsley.Combinator
    • parsley.ExpressionParser
    • parsley.Impl
    • parsley.Implicits
    • parsley.LanguageDef
    • parsley.NotRequired
    • parsley.Parser
    • parsley.Predicate
    • parsley.Reg
    • parsley.TokenParser
    Definition Classes
    root
  • package parsley
    Definition Classes
    root
  • object Parsley

    This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators.

    This object contains the core "function-style" combinators as well as the implicit classes which provide the "method-style" combinators. All parsers will likely require something from within!

    Definition Classes
    parsley
  • LazyChooseParsley
  • LazyMapParsley
  • LazyParsley
c

parsley.Parsley

LazyParsley

implicit final class LazyParsley[P, +A] extends AnyRef

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. LazyParsley
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new LazyParsley(p: => P)(implicit con: (P) => Parsley[A])

Value Members

  1. def !(msggen: (A) => String): Parsley[Nothing]

    Same as fail, except allows for a message generated from the result of the failed parser.

    Same as fail, except allows for a message generated from the result of the failed parser. In essence, this is equivalent to p >>= (x => fail(msggen(x)) but requires no expensive computations from the use of >>=.

    msggen

    The generator function for error message, creating a message based on the result of invokee

    returns

    A parser that fails if it succeeds, with the given generator used to produce the error message

  2. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  3. final def ##: Int
    Definition Classes
    AnyRef → Any
  4. def #>[B](x: B): Parsley[B]

    This is the parser that corresponds to p *> pure(x) or a more optimal version of p.map(_ => x).

    This is the parser that corresponds to p *> pure(x) or a more optimal version of p.map(_ => x). It performs the parse action of the invokee but discards its result and then results the value x instead

    x

    The value to be returned after the execution of the invokee

    returns

    A new parser which first parses the invokee, then results x

  5. def *>[A_ >: A, B](q: => Parsley[B]): Parsley[B]

    This is the parser that corresponds to a more optimal version of p.map(_ => x => x) <*> q.

    This is the parser that corresponds to a more optimal version of p.map(_ => x => x) <*> q. It performs the parse action of both parsers, in order, but discards the result of the invokee.

    q

    The parser whose result should be returned

    returns

    A new parser which first parses p, then q and returns the result of q

  6. def <#>[B](f: (A) => B): Parsley[B]

    This combinator is an alias for map

  7. def <*[B](q: => Parsley[B]): Parsley[A]

    This is the parser that corresponds to a more optimal version of p.map(x => _ => x) <*> q.

    This is the parser that corresponds to a more optimal version of p.map(x => _ => x) <*> q. It performs the parse action of both parsers, in order, but discards the result of the second parser.

    q

    The parser who should be executed but then discarded

    returns

    A new parser which first parses p, then q and returns the result of the p

  8. def <**>[B](pf: => Parsley[(A) => B]): Parsley[B]

    This combinator is defined as lift2((x, f) => f(x), p, f).

    This combinator is defined as lift2((x, f) => f(x), p, f). It is pure syntactic sugar.

  9. def <*>[B, C](px: => Parsley[B])(implicit ev: <:<[P, Parsley[(B) => C]]): Parsley[C]

    This is the Applicative application parser.

    This is the Applicative application parser. The type of pf is Parsley[A => B]. Then, given a Parsley[A], we can produce a Parsley[B] by parsing pf to retrieve f: A => B, then parse px to receive x: A then return f(x): B.

    px

    A parser of type A, where the invokee is A => B

    returns

    A new parser which parses pf, then px then applies the value returned by px to the function returned by pf

    Note

    pure(f) <*> p is subject to the same aggressive optimisations as map. When using impure functions the optimiser may decide to cache the result of the function execution, be sure to use unsafe in order to prevent these optimisations.

  10. def <+:>[B >: A](ps: => Parsley[Seq[B]]): Parsley[Seq[B]]

    This parser corresponds to lift2(_+:_, p, ps).

  11. def </>[B >: A](x: B): Parsley[B]

    This combinator is defined as p <|> pure(x).

    This combinator is defined as p <|> pure(x). It is pure syntactic sugar.

  12. def <::>[B >: A](ps: => Parsley[List[B]]): Parsley[List[B]]

    This parser corresponds to lift2(_::_, p, ps).

  13. def <\>[B >: A](q: Parsley[B]): Parsley[B]

    This combinator is defined as attempt(p) <|> q.

    This combinator is defined as attempt(p) <|> q. It is pure syntactic sugar.

  14. def <|>[B >: A](q: => Parsley[B]): Parsley[B]

    This is the traditional Alternative choice operator for parsers.

    This is the traditional Alternative choice operator for parsers. Following the parsec semantics precisely, this combinator first tries to parse the invokee. If this is successful, no further action is taken. If the invokee failed *without* consuming input, then q is parsed instead. If the invokee did parse input then the whole parser fails. This is done to prevent space leaks and to give good error messages. If this behaviour is not desired, use the <\> combinator (or attempt(this) <|> q) to parse q regardless of how the invokee failed.

    q

    The parser to run if the invokee failed without consuming input

    returns

    The value produced by the invokee if it was successful, or if it failed without consuming input, the possible result of parsing q.

  15. def <~>[A_ >: A, B](q: => Parsley[B]): Parsley[(A_, B)]

    This parser corresponds to lift2((_, _), p, q).

    This parser corresponds to lift2((_, _), p, q). For now it is sugar, but in future may be more optimal

  16. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  17. def >>[B](q: Parsley[B]): Parsley[B]

    This combinator is an alias for *>

  18. def >>=[B](f: (A) => Parsley[B]): Parsley[B]

    This combinator is an alias for flatMap

  19. def >?>(pred: (A) => Boolean, msggen: (A) => String): Parsley[A]

    Alias for guard combinator, taking a dynamic message generator.

  20. def >?>(pred: (A) => Boolean, msg: String): Parsley[A]

    Alias for guard combinator, taking a fixed message.

  21. def ?(msg: String): Parsley[A]

    Sets the expected message for a parser.

    Sets the expected message for a parser. If the parser fails then expected msg will added to the error

  22. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  23. def cast[B](implicit arg0: ClassTag[B]): Parsley[B]

    This casts the result of the parser into a new type B.

    This casts the result of the parser into a new type B. If the value returned by the parser is castable to type B, then this cast is performed. Otherwise the parser fails.

    B

    The type to attempt to cast into

    Since

    1.7

  24. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  25. def collect[B](pf: PartialFunction[A, B]): Parsley[B]

    Attempts to first filter the parser to ensure that pf is defined over it.

    Attempts to first filter the parser to ensure that pf is defined over it. If it is, then the function pf is mapped over its result. Roughly the same as a filter then a map.

    pf

    The partial function

    returns

    The result of applying pf to this parsers value (if possible), or fails

    Since

    1.7

  26. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  27. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  28. def filter(pred: (A) => Boolean): Parsley[A]

    Filter the value of a parser; if the value returned by the parser matches the predicate pred then the filter succeeded, otherwise the parser fails with an empty error

    Filter the value of a parser; if the value returned by the parser matches the predicate pred then the filter succeeded, otherwise the parser fails with an empty error

    pred

    The predicate that is tested against the parser result

    returns

    The result of the invokee if it passes the predicate

  29. def filterNot(pred: (A) => Boolean): Parsley[A]

    Filter the value of a parser; if the value returned by the parser does not match the predicate pred then the filter succeeded, otherwise the parser fails with an empty error

    Filter the value of a parser; if the value returned by the parser does not match the predicate pred then the filter succeeded, otherwise the parser fails with an empty error

    pred

    The predicate that is tested against the parser result

    returns

    The result of the invokee if it passes the predicate

  30. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  31. def flatMap[B](f: (A) => Parsley[B]): Parsley[B]

    This is the traditional Monadic binding operator for parsers.

    This is the traditional Monadic binding operator for parsers. When the invokee produces a value, the function f is used to produce a new parser that continued the computation.

    f

    A function that produces the next parser

    returns

    The parser produces from the application of f on the result of the last parser

    Note

    There is significant overhead for using flatMap; if possible try to write parsers in an applicative style otherwise try and use the intrinsic parsers provided to replace the flatMap.

  32. def flatten[B](implicit ev: <:<[A, Parsley[B]]): Parsley[B]

    This combinator is an alias for flatMap(identity).

  33. def foldLeft[B](k: B)(f: (B, A) => B): Parsley[B]

    A fold for a parser: p.foldLeft(k)(f) will try executing p many times until it fails, combining the results with left-associative application of f with a k on the left-most position

    A fold for a parser: p.foldLeft(k)(f) will try executing p many times until it fails, combining the results with left-associative application of f with a k on the left-most position

    k

    base case for iteration

    f

    combining function

    returns

    the result of folding the results of p with f and k

    Example:
    1. val natural: Parsley[Int] = digit.foldLeft(0)((x, d) => x * 10 + d.toInt)
  34. def foldLeft1[B](k: B)(f: (B, A) => B): Parsley[B]

    A fold for a parser: p.foldLeft1(k)(f) will try executing p many times until it fails, combining the results with left-associative application of f with a k on the left-most position.

    A fold for a parser: p.foldLeft1(k)(f) will try executing p many times until it fails, combining the results with left-associative application of f with a k on the left-most position. It must parse p at least once.

    k

    base case for iteration

    f

    combining function

    returns

    the result of folding the results of p with f and k

    Example:
    1. val natural: Parsley[Int] = digit.foldLeft1(0)((x, d) => x * 10 + d.toInt)
  35. def foldRight[B](k: B)(f: (A, B) => B): Parsley[B]

    A fold for a parser: p.foldRight(k)(f) will try executing p many times until it fails, combining the results with right-associative application of f with a k at the right-most position

    A fold for a parser: p.foldRight(k)(f) will try executing p many times until it fails, combining the results with right-associative application of f with a k at the right-most position

    k

    base case for iteration

    f

    combining function

    returns

    the result of folding the results of p with f and k

    Example:
    1. p.foldRight(Nil)(_::_) == many(p) //many is more efficient, however
  36. def foldRight1[B](k: B)(f: (A, B) => B): Parsley[B]

    A fold for a parser: p.foldRight1(k)(f) will try executing p many times until it fails, combining the results with right-associative application of f with a k at the right-most position.

    A fold for a parser: p.foldRight1(k)(f) will try executing p many times until it fails, combining the results with right-associative application of f with a k at the right-most position. It must parse p at least once.

    k

    base case for iteration

    f

    combining function

    returns

    the result of folding the results of p with f and k

    Example:
    1. p.foldRight1(Nil)(_::_) == some(p) //some is more efficient, however
  37. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  38. def getOrElse[B >: A](x: B): Parsley[B]

    This combinator is an alias for </>.

  39. def guard(pred: (A) => Boolean, msggen: (A) => String): Parsley[A]

    Similar to filter, except the error message desired is also provided.

    Similar to filter, except the error message desired is also provided. This allows you to name the message itself. The message is provided as a generator, which allows the user to avoid otherwise expensive computation.

    pred

    The predicate that is tested against the parser result

    msggen

    Generator function for error message, generating a message based on the result of the parser

    returns

    The result of the invokee if it passes the predicate

  40. def guard(pred: (A) => Boolean, msg: String): Parsley[A]

    Similar to filter, except the error message desired is also provided.

    Similar to filter, except the error message desired is also provided. This allows you to name the message itself.

    pred

    The predicate that is tested against the parser result

    msg

    The message used for the error if the input failed the check

    returns

    The result of the invokee if it passes the predicate

  41. def guardNot(pred: (A) => Boolean, msggen: (A) => String): Parsley[A]

    Similar to filterNot, except the error message desired is also provided.

    Similar to filterNot, except the error message desired is also provided. This allows you to name the message itself. The message is provided as a generator, which allows the user to avoid otherwise expensive computation.

    pred

    The predicate that is tested against the parser result

    msggen

    Generator function for error message, generating a message based on the result of the parser

    returns

    The result of the invokee if it passes the predicate

  42. def guardNot(pred: (A) => Boolean, msg: String): Parsley[A]

    Similar to filterNot, except the error message desired is also provided.

    Similar to filterNot, except the error message desired is also provided. This allows you to name the message itself.

    pred

    The predicate that is tested against the parser result

    msg

    The message used for the error if the input failed the check

    returns

    The result of the invokee if it passes the predicate

  43. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  44. def hide: Parsley[A]

    Hides the "expected" error message for a parser.

  45. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  46. def map[B](f: (A) => B): Parsley[B]

    This is the functorial map operation for parsers.

    This is the functorial map operation for parsers. When the invokee produces a value, this value is fed through the function f.

    f

    The mutator to apply to the result of previous parse

    returns

    A new parser which parses the same input as the invokee but mutated by function f

    Note

    This is subject to aggressive optimisations assuming purity; the compiler is permitted to optimise such that the application of f actually only happens once at compile time. In order to preserve the behaviour of impure functions, consider using the unsafe method before map; p.unsafe.map(f).

  47. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  48. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  49. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  50. def orElse[B >: A](q: => Parsley[B]): Parsley[B]

    This combinator is an alias for <|>.

  51. def reduceLeft[B >: A](op: (B, A) => B): Parsley[B]

    A reduction for a parser: p.reduceLeft(op) will try executing p many times until it fails, combining the results with left-associative application of op.

    A reduction for a parser: p.reduceLeft(op) will try executing p many times until it fails, combining the results with left-associative application of op. It must parse p at least once.

    op

    combining function

    returns

    the result of reducing the results of p with op

  52. def reduceLeftOption[B >: A](op: (B, A) => B): Parsley[Option[B]]

    A reduction for a parser: p.reduceLeft(op) will try executing p many times until it fails, combining the results with left-associative application of op.

    A reduction for a parser: p.reduceLeft(op) will try executing p many times until it fails, combining the results with left-associative application of op. If there is no p, it returns None, otherwise it returns Some(x) where x is the result of the reduction.

    op

    combining function

    returns

    the result of reducing the results of p with op wrapped in Some or None otherwise

  53. def reduceRight[B >: A](op: (A, B) => B): Parsley[B]

    A reduction for a parser: p.reduceRight(op) will try executing p many times until it fails, combining the results with right-associative application of op.

    A reduction for a parser: p.reduceRight(op) will try executing p many times until it fails, combining the results with right-associative application of op. It must parse p at least once.

    op

    combining function

    returns

    the result of reducing the results of p with op

  54. def reduceRightOption[B >: A](op: (A, B) => B): Parsley[Option[B]]

    A reduction for a parser: p.reduceRight(op) will try executing p many times until it fails, combining the results with right-associative application of op.

    A reduction for a parser: p.reduceRight(op) will try executing p many times until it fails, combining the results with right-associative application of op. If there is no p, it returns None, otherwise it returns Some(x) where x is the result of the reduction.

    op

    combining function

    returns

    the result of reducing the results of p with op wrapped in Some or None otherwise

  55. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  56. def toString(): String
    Definition Classes
    AnyRef → Any
  57. def unexpected(msggen: (A) => String): Parsley[Nothing]

    Same as unexpected, except allows for a message generated from the result of the failed parser.

    Same as unexpected, except allows for a message generated from the result of the failed parser. In essence, this is equivalent to p >>= (x => unexpected(x)) but requires no expensive computations from the use of >>=

    msggen

    The generator function for error message, creating a message based on the result of invokee

    returns

    A parser that fails if it succeeds, with the given generator used to produce an unexpected message

  58. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  59. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  60. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  61. def withFilter(pred: (A) => Boolean): Parsley[A]
  62. def zip[A_ >: A, B](q: => Parsley[B]): Parsley[(A_, B)]

    This combinator is an alias for <~>

Inherited from AnyRef

Inherited from Any

Ungrouped