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.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
  • package errors

    This package contains various functionality relating to the generation and formatting of error messages.

    This package contains various functionality relating to the generation and formatting of error messages.

    In particular, it includes a collection of combinators for improving error messages within the parser, including labelling and providing additional information. It also contains combinators that can be used to valid data produced by a parser, to ensure it conforms to expected invariances, producing good quality error messages if this is not the case. Finally, this package contains ways of changing the formatting of error messages: this can either be changing how the default String-based errors are formatted, or by injectiing Parsley's errors into a custom error object.

    Definition Classes
    parsley
  • package expr

    This package contains various functionality relating to the parsing of expressions..

    This package contains various functionality relating to the parsing of expressions..

    This includes the "chain" combinators, which tackle the left-recursion problem and allow for the parsing and combining of operators with values. It also includes functionality for constructing larger precedence tables, which may even vary the type of each layer in the table, allowing for strongly-typed expression parsing.

    Definition Classes
    parsley
  • package implicits

    This package contains various functionality that involve Scala's implicits mechanism.

    This package contains various functionality that involve Scala's implicits mechanism.

    This includes conversions from scala literals into parsers, as well as enabling new syntax on regular Scala values (such as Parsley's lift or zipped syntax). Automatic conversion to Parsley[Unit] is also supported within this package.

    Definition Classes
    parsley
  • Failure
  • Parsley
  • Result
  • Success
  • ap
  • character
  • combinator
  • debug
  • extension
  • genericbridges
  • io
  • lift
  • registers
  • package token

    This package provides a wealth of functionality for performing common lexing tasks.

    This package provides a wealth of functionality for performing common lexing tasks.

    It is organised as follows:

    • the main parsing functionality is accessed via Lexer, which provides implementations for the combinators found in the sub-packages given a LexicalDesc.
    • the descriptions sub-package is how a lexical structure can be described, providing the configuration that alters the behaviour of the parsers produced by the Lexer.
    • the other sub-packages contain the high-level interfaces that the Lexer exposes, which can be used to pass whitespace-aware and non-whitespace-aware combinators around in a uniform way.
    • the predicate module contains functionality to help define boolean predicates on characters or unicode codepoints.
    Definition Classes
    parsley
o

parsley

registers

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

Source
registers.scala
Since

2.2.0

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

Type Members

  1. class Reg[A] extends AnyRef

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

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

    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.

  2. implicit final class RegisterMaker[A] extends AnyRef

    This class, when in scope, enables a method to create and fill a register with a given value.

  3. implicit final class RegisterMethods[P, A] extends AnyRef

    This class, when in scope, enables the use of combinators directly on parsers that interact with the register system to store and persist results so they can be used multiple times.

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 forP[A](init: Parsley[A], cond: => Parsley[(A) => Boolean], step: => Parsley[(A) => A])(body: => Parsley[_]): Parsley[Unit]

    This combinator allows for the repeated execution of a parser in a stateful loop.

    This combinator allows for the repeated execution of a parser in a stateful loop.

    forP(init, cond, step)(body) behaves much like a traditional for loop using init, cond, step and body as parsers which control the loop itself. First, a register r is created and initialised with init. Then cond is parsed, producing the function pred. If r.gets(pred) returns true, then body is parsed, then r is modified with the result of parsing step. This repeats until r.gets(pred) returns false. This is useful for performing certain context sensitive tasks.

    init

    the initial value of the induction variable.

    cond

    the condition by which the loop terminates.

    step

    the change in induction variable on each iteration.

    body

    the body of the loop performed each iteration.

    returns

    a parser that initialises some state with init and then parses body until cond is true, modifying the state each iteration with step.

    Example:
    1. the classic context sensitive grammar of anbncn can be matched using forP:

      val r = Reg.make[Int]
      
      r.put(0) *>
      many('a' *> r.modify(_+1)) *>
      forP[Int](r.get, pure(_ != 0), pure(_ - 1)){'b'} *>
      forP[Int](r.get, pure(_ != 0), pure(_ - 1)){'c'}
    See also

    forYieldP for a version that returns the results of each body parse.

  10. def forP_[A](init: Parsley[A], cond: => Parsley[(A) => Boolean], step: => Parsley[(A) => A])(body: (Parsley[A]) => Parsley[_]): Parsley[Unit]

    This combinator allows for the repeated execution of a parser body in a stateful loop, body will have access to the current value of the state.

    This combinator allows for the repeated execution of a parser body in a stateful loop, body will have access to the current value of the state.

    forP_(init, cond, step)(body) behaves much like a traditional for loop using init, cond, step and body as parsers which control the loop itself. First, a register r is created and initialised with init. Then cond is parsed, producing the function pred. If r.gets(pred) returns true, then body is parsed, then r is modified with the result of parsing step. This repeats until r.gets(pred) returns false. This is useful for performing certain context sensitive tasks.

    init

    the initial value of the induction variable.

    cond

    the condition by which the loop terminates.

    step

    the change in induction variable on each iteration.

    body

    the body of the loop performed each iteration, which has access to the current value of the state.

    returns

    a parser that initialises some state with init and then parses body until cond is true, modifying the state each iteration with step.

    Example:
    1. the classic context sensitive grammar of anbncn can be matched using forP_:

      val r = Reg.make[Int]
      
      r.put(0) *>
      many('a' *> r.modify(_+1)) *>
      forP_[Int](r.get, pure(_ != 0), pure(_ - 1)){_ => 'b'} *>
      forP_[Int](r.get, pure(_ != 0), pure(_ - 1)){_ => 'c'}
    See also

    forYieldP_ for a version that returns the results of each body parse.

  11. def forYieldP[A, B](init: Parsley[A], cond: => Parsley[(A) => Boolean], step: => Parsley[(A) => A])(body: => Parsley[B]): Parsley[List[B]]

    This combinator allows for the repeated execution of a parser in a stateful loop.

    This combinator allows for the repeated execution of a parser in a stateful loop.

    forYieldP(init, cond, step)(body) behaves much like a traditional for comprehension using init, cond, step and body as parsers which control the loop itself. First, a register r is created and initialised with init. Then cond is parsed, producing the function pred. If r.gets(pred) returns true, then body is parsed, then r is modified with the result of parsing step. This repeats until r.gets(pred) returns false. This is useful for performing certain context sensitive tasks. Unlike forP the results of the body invokations are returned in a list.

    init

    the initial value of the induction variable.

    cond

    the condition by which the loop terminates.

    step

    the change in induction variable on each iteration.

    body

    the body of the loop performed each iteration.

    returns

    a parser that initialises some state with init and then parses body until cond is true, modifying the state each iteration with step. The results of the iterations are returned in a list.

    Example:
    1. the classic context sensitive grammar of anbncn can be matched using forP:

      val r = Reg.make[Int]
      
      r.put(0) *>
      many('a' *> r.modify(_+1)) *>
      forYieldP[Int](r.get, pure(_ != 0), pure(_ - 1)){'b'} *>
      forYieldP[Int](r.get, pure(_ != 0), pure(_ - 1)){'c'}

      This will return a list n 'c' characters.

    See also

    forP for a version that ignores the results.

  12. def forYieldP_[A, B](init: Parsley[A], cond: => Parsley[(A) => Boolean], step: => Parsley[(A) => A])(body: (Parsley[A]) => Parsley[B]): Parsley[List[B]]

    This combinator allows for the repeated execution of a parser body in a stateful loop, body will have access to the current value of the state.

    This combinator allows for the repeated execution of a parser body in a stateful loop, body will have access to the current value of the state.

    forP_(init, cond, step)(body) behaves much like a traditional for comprehension using init, cond, step and body as parsers which control the loop itself. First, a register r is created and initialised with init. Then cond is parsed, producing the function pred. If r.gets(pred) returns true, then body is parsed, then r is modified with the result of parsing step. This repeats until r.gets(pred) returns false. This is useful for performing certain context sensitive tasks. Unlike forP_ the results of the body invokations are returned in a list.

    init

    the initial value of the induction variable.

    cond

    the condition by which the loop terminates.

    step

    the change in induction variable on each iteration.

    body

    the body of the loop performed each iteration, which has access to the current value of the state.

    returns

    a parser that initialises some state with init and then parses body until cond is true, modifying the state each iteration with step.

    Example:
    1. the classic context sensitive grammar of anbncn can be matched using forP_:

      val r = Reg.make[Int]
      
      r.put(0) *>
      many('a' *> r.modify(_+1)) *>
      forYieldP_[Int](r.get, pure(_ != 0), pure(_ - 1)){_ => 'b'} *>
      forYieldP_[Int](r.get, pure(_ != 0), pure(_ - 1)){_ => 'c'}

      This will return a list n 'c' characters.

    See also

    forP_ for a version that ignores the results of the body.

  13. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  17. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  18. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  20. def toString(): String
    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  22. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  23. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  24. object Reg

    This object allows for the construction of a register via its make function.

Inherited from AnyRef

Inherited from Any

Registers

The Reg type is used to describe pieces of state that are threaded through a parser. The creation and basic combinators of registers are found within Reg and its companion object.

Register-Based Combinators

Some combinators are made much more efficient in the presence of registers and they can be found here.

Register Extension Combinators

These are implicit classes that, when in scope, enable additional combinators on parsers that interact with the register system in some way.

Ungrouped