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.io contains extension methods to run parsers with input sourced from IO sources.
    • parsley.expr contains the following sub modules:
    • parsley.implicits contains several implicits to add syntactic sugar to the combinators. These are sub-categorised into the following sub modules:
      • parsley.implicits.character contains implicits to allow you to use character and string literals as parsers.
      • parsley.implicits.combinator contains implicits related to combinators, such as the ability to make any parser into a Parsley[Unit] automatically.
      • parsley.implicits.lift enables postfix application of the lift combinator onto a function (or value).
      • parsley.implicits.zipped enables boths a reversed form of lift where the function appears on the right and is applied on a tuple (useful when type inference has failed) as well as a .zipped method for building tuples out of several combinators.
    • parsley.errors contains modules to deal with error messages, their refinement and generation.
      • parsley.errors.combinator provides combinators that can be used to either produce more detailed errors as well as refine existing errors.
    • 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.
    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

This class exposes the commonly used combinators in Parsley. For a description of why the library is designed in this way, see: the Parsley wiki

Version

1.0.0

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

    p

    The parser which serves as the method receiver

    con

    A conversion (if required) to turn p into a parser

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. 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

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

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

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

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

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

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

  9. def <+>[B](q: Parsley[B]): Parsley[Either[A, B]]

    This combinator, pronounced "sum", is similar to <|>, except it allows the types of either side of the combinator to vary by returning their result as part of an Either.

    This combinator, pronounced "sum", is similar to <|>, except it allows the types of either side of the combinator to vary by returning their result as part of an Either.

    q

    The parser to run if the invokee failed without consuming input

    returns

    the result of the parser which succeeded, if any

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

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

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

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

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

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

    This is the parser that corresponds to a more optimal version of (p <~> q).map(_._1). 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

    Since

    2.4.0

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

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

    This combinator is an alias for flatMap

  17. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  18. 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

    2.0.0

  19. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  20. 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

    2.0.0

  21. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  23. 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

  24. 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 fails the predicate

  25. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  26. 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.

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

    This combinator is an alias for flatMap(identity).

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

    2.1.0

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

    2.1.0

  32. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  33. def getOrElse[B >: A](x: B): Parsley[B]

    This combinator is an alias for </>.

  34. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  35. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  36. 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).

  37. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  38. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  39. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  40. def orElse[B >: A](q: => Parsley[B]): Parsley[B]

    This combinator is an alias for <|>.

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

    Since

    2.3.0

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

    Since

    2.3.0

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

    Since

    2.3.0

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

    Since

    2.3.0

  45. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  46. def toString(): String
    Definition Classes
    AnyRef → Any
  47. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  48. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  49. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  50. def zip[A_ >: A, B](q: => Parsley[B]): Parsley[(A_, B)]

    This combinator is an alias for <~>

    This combinator is an alias for <~>

    Since

    2.3.0

  51. def ~>[B](q: Parsley[B]): Parsley[B]

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

    This is the parser that corresponds to a more optimal version of (p <~> q).map(_._2). 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

    Since

    2.4.0

Deprecated Value Members

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

    Annotations
    @deprecated
    Deprecated

    (Since version 3.0.1) This combinator is unfortunately misleading since it is left-associative. It will be removed in 4.0.0, use attempt with <|> instead

    Note

    This combinator should not be used: operators without trailing colons in Scala are left-associative, but this operator was designed to be right associative. This means that where we might intend for p <|> q <\> r to mean p <|> attempt(q) <|> r, it in fact means attempt(p <|> q) <|> r. While this will not break a parser, it hinders optimisation and may damage the quality of generated messages.

Inherited from AnyRef

Inherited from Any

Ungrouped