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.
    • 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.extension contains syntactic sugar combinators exposed as implicit classes.
    • parsley.io contains extension methods to run parsers with input sourced from IO sources.
    • parsley.expr contains the following sub modules:
      • parsley.expr.chain contains combinators used in expression parsing
      • parsley.expr.precedence is a builder for expression parsers built on a precedence table.
      • parsley.expr.infix contains combinators used in expression parsing, but with more permissive types than their equivalents in chain.
      • parsley.expr.mixed contains combinators that can be used for expression parsing, but where different fixities may be mixed on the same level: this is rare in practice.
    • 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.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.ap contains functions which allow for the application of a parser returning a function to several parsers returning each of the argument types.
    • 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.position contains parsers for extracting position information.
    • parsley.genericbridges contains some basic implementations of the Parser Bridge pattern (see Design Patterns for Parser Combinators in Scala, or the parsley wiki): these can be used before more specialised generic bridge traits can be constructed.
    Definition Classes
    root
  • package parsley
    Definition Classes
    root
  • object registers

    This module contains all the functionality and operations for using and manipulating registers.

    This module contains all the functionality and operations for using and manipulating registers.

    These often have a role in performing context-sensitive parsing tasks, where a Turing-powerful system is required. While flatMap is capable of such parsing, it is much less efficient than the use of registers, though slightly more flexible. In particular, the persist combinator enabled by RegisterMethods can serve as a drop-in replacement for flatMap in many scenarios.

    Definition Classes
    parsley
    Since

    2.2.0

  • Reg
  • RegisterMaker
  • RegisterMethods

class Reg[A] extends AnyRef

This class is used to index registers within the mutable state.

Source
registers.scala
Since

2.2.0

Note

it is undefined behaviour to use a register in multiple different independent parsers. You should be careful to parameterise the registers in shared parsers and allocate fresh ones for each "top-level" parser you will run.

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

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  9. def get: Parsley[A]

    This combinator injects the value stored in this register into a parser.

    This combinator injects the value stored in this register into a parser.

    Allows for the value stored in this register to be purely injected into the parsing context. No input is consumed in this process, and it cannot fail.

    returns

    a parser that returns the value stored in this register.

    Example:
    1. Get-Get Law:

      r.get *> r.get == r.get
      r.get <~> r.get == r.get.map(x => (x, x))
    Since

    3.2.0

  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def gets[B](pf: Parsley[(A) => B]): Parsley[B]

    This combinator injects the value stored in this register into a parser after applying a function obtained from a parser to it.

    This combinator injects the value stored in this register into a parser after applying a function obtained from a parser to it.

    First, pf is parsed, producing the function f on success. Then, the value stored in this register x is applied to the function f. The combinator returns f(x). Only pf is allowed to consume input. If pf fails, the combinator fails, otherwise it will succeed.

    B

    the desired result type.

    pf

    the parser that produces the function used to transform the value in this register.

    returns

    the value stored in this register applied to a function generated from pf.

    Since

    3.2.0

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

    This combinator injects the value stored in this register into a parser after applying a function to it.

    This combinator injects the value stored in this register into a parser after applying a function to it.

    Allows for the value stored in this register to be purely injected into the parsing context but the function f is applied first. No input is consumed in this process, and it cannot fail.

    B

    the desired result type.

    f

    the function used to transform the value in this register.

    returns

    the value stored in this register applied to f.

    Since

    3.2.0

  13. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  15. def local[B](f: (A) => A)(p: Parsley[B]): Parsley[B]

    This combinator changed the value stored in this register for the duration of a given parser, resetting it afterwards.

    This combinator changed the value stored in this register for the duration of a given parser, resetting it afterwards.

    First get the current value in this register xold, then place f(xold) into this register without any further effect. Then, parse p, producing result y on success. Finally, put xold back into this register and return y. If p fails, the whole combinator fails and the state is not restored.

    f

    the function used to modify the value in this register.

    p

    the parser to execute with the adjusted state.

    returns

    the parser that performs p with the modified state.

    Example:
    1. Put-Put Law and Put-Get Law:

      r.put(x) *> r.local(f)(p) == r.put(f(x)) *> p <* r.put(x)
    Since

    3.2.0

  16. def local[B](p: Parsley[A])(q: => Parsley[B]): Parsley[B]

    This combinator changed the value stored in this register for the duration of a given parser, resetting it afterwards.

    This combinator changed the value stored in this register for the duration of a given parser, resetting it afterwards.

    First get the current value in this register xold, then parse p to get the result x, placing it into this register without any further effect. Then, parse q, producing result y on success. Finally, put xold back into this register and return y. If p or q fail, the whole combinator fails and the state is not restored.

    p

    the parser whose return value is placed in this register.

    q

    the parser to execute with the adjusted state.

    returns

    the parser that performs q with the modified state.

    Since

    3.2.0

  17. def local[B](x: A)(p: Parsley[B]): Parsley[B]

    This combinator changed the value stored in this register for the duration of a given parser, resetting it afterwards.

    This combinator changed the value stored in this register for the duration of a given parser, resetting it afterwards.

    First get the current value in this register xold, then place x into this register without any further effect. Then, parse p, producing result y on success. Finally, put xold back into this register and return y. If p fails, the whole combinator fails and the state is not restored.

    x

    the value to place into this register.

    p

    the parser to execute with the adjusted state.

    returns

    the parser that performs p with the modified state x.

    Example:
    1. Put-Put Law:

      r.put(x) *> r.local(y)(p) == r.put(y) *> p <* r.put(x)
    Since

    3.2.0

  18. def modify(pf: Parsley[(A) => A]): Parsley[Unit]

    This combinator modifies the value stored in this register with a function.

    This combinator modifies the value stored in this register with a function.

    First, parse pf to obtain its result f. Then get the value stored in this register, x, and put back f(x). If p fails this combinator fails.

    Equivalent to

    this.put(this.gets(pf))
    pf

    the parser that produces the function used to transform the value in this register.

    Since

    3.2.0

  19. def modify(f: (A) => A): Parsley[Unit]

    This combinator modifies the value stored in this register with a function.

    This combinator modifies the value stored in this register with a function.

    Without any other effect, get the value stored in this register, x, and put back f(x).

    Equivalent to

    this.put(this.gets(f))
    f

    the function used to modify this register's value.

    Since

    3.2.0

  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. def put(p: Parsley[A]): Parsley[Unit]

    This combinator stores a new value into this register.

    This combinator stores a new value into this register.

    First, parse p to obtain its result x. Then store x into this register without any further effect. If p fails this combinator fails.

    p

    the parser that produces the value to store in the register.

    Examples:
    1. Get-Put Law:

      r.put(r.get) == unit
    2. ,
    3. Put-Put Law:

      // only when `q` does not inspect the value of `r`!
      r.put(p) *> r.put(q) == p *> r.put(q)
    Since

    3.2.0

  24. def put(x: A): Parsley[Unit]

    This combinator stores a new value into this register.

    This combinator stores a new value into this register.

    Without any other effect, the value x will be placed into this register.

    x

    the value to place in the register.

    Examples:
    1. Put-Get Law:

      r.put(x) *> r.get == r.put(x).as(x)
    2. ,
    3. Put-Put Law:

      r.put(x) *> r.put(y) == r.put(y)
    Since

    3.2.0

  25. def puts[B](p: Parsley[B], f: (B) => A): Parsley[Unit]

    This combinator stores a new value into this register.

    This combinator stores a new value into this register.

    First, parse p to obtain its result x. Then store f(x) into this register without any further effect. If p fails this combinator fails.

    Equivalent to

    this.put(p.map(f))
    p

    the parser that produces the value to store in the register.

    f

    a function which adapts the result of p so that it can fit into this register.

    Since

    3.0.0

  26. def rollback[B](p: Parsley[B]): Parsley[B]

    This combinator rolls-back any changes to this register made by a given parser if it fails.

    This combinator rolls-back any changes to this register made by a given parser if it fails.

    First get the current value in this register xold. Then parse p, if it succeeds, producing y, then y is returned and this register retains its value post-p. Otherwise, if p failed without consuming input, xold is placed back into this register and this combinator fails.

    This can be used in conjunction with local to make an almost unconditional state restore:

    // `r`'s state is always rolled back after `p` unless it fails having consumed input.
    r.rollback(r.local(x)(p))
    p

    the parser to perform.

    returns

    the result of the parser p, if any.

    Since

    3.2.0

  27. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  28. def toString(): String
    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Getters

These combinators allow for the retrieval of the stateful value of a register, and injecting it into the parsing context. Does not modify the contents of the register itself.

Setters

These combinators directly update the value contained within a register. This new value can be provided directly or sourced from a parser.

Modification

These combinators modify the value stored within a register by using a function. The function used can be provided directly or sourced from a parser.

Local Modification

These combinators allow for some form of local stateful modification. This means that any changes to the register may be reverted after the execution of the parser: this may be on the parsers success, but it could also involve the parsers failure.

Ungrouped