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
  • Atoms
  • Fixity
  • GOps
  • InfixL
  • InfixN
  • InfixR
  • Ops
  • Postfix
  • Prec
  • Prefix
  • SOps
  • chain
  • infix
  • mixed
  • precedence
  • 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
  • package internal
    Definition Classes
    parsley
  • 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

package expr

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.

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

Type Members

  1. case class Atoms[+A](atom0: Parsley[A], atoms: Parsley[A]*) extends Prec[A] with Product with Serializable

    This class is the base of a precedence table.

    This class is the base of a precedence table.

    Forms the base of a precedence table, requiring at least one atom to be provided. This first atom will be parsed first.

    A

    the type of the atoms.

    atom0

    the first atom found at the root of the precedence table.

    atoms

    any remaining atoms found at the root of the precedence table.

    Since

    4.0.0

  2. sealed trait Fixity extends AnyRef

    Denotes the fixity and associativity of an operator.

    Denotes the fixity and associativity of an operator. Importantly, it also specifies the type of the of the operations themselves.

    Since

    4.0.0

  3. sealed abstract class Ops[-A, B] extends AnyRef

    This class allows for the description of a single layer of operators in the precedence tree.

    This class allows for the description of a single layer of operators in the precedence tree.

    Describes the operators at a specific level in the precedence tree, such that these ops consume Bs, possibly As and produce Bs: this depends on the Fixity of the operators.

    A

    the base type consumed by the operators.

    B

    the type produced/consumed by the operators.

    Since

    2.2.0

    Note

    for less complex types Ops[A, A] is sufficient.

  4. sealed abstract class Prec[+A] extends AnyRef

    This class is the base type for precedence tables.

    This class is the base type for precedence tables.

    For more complex expression parser types Prec can be used to describe the precedence table whilst preserving the intermediate structure between each level.

    The base of the table will always be an Atoms, and each layer built on top of the last using either the :+ or +: methods.

    A

    the type of structure produced by the list of levels.

    Since

    4.0.0

Value Members

  1. object GOps

    This helper object builds values of Ops[A, B], for fully heterogeneous precedence parsing.

    This helper object builds values of Ops[A, B], for fully heterogeneous precedence parsing.

    Since

    2.2.0

  2. case object InfixL extends Fixity with Product with Serializable

    Describes left-associative binary operators

    Describes left-associative binary operators

    Since

    4.0.0

  3. case object InfixN extends Fixity with Product with Serializable

    Describes non-associative operators

    Describes non-associative operators

    Since

    4.0.0

  4. case object InfixR extends Fixity with Product with Serializable

    Describes right-associative binary operators

    Describes right-associative binary operators

    Since

    4.0.0

  5. object Ops

    This helper object is used to build values of Ops[A, A], for homogeneous precedence parsing.

    This helper object is used to build values of Ops[A, A], for homogeneous precedence parsing.

    Since

    2.2.0

  6. case object Postfix extends Fixity with Product with Serializable

    Describes unary postfix operators

    Describes unary postfix operators

    Since

    4.0.0

  7. case object Prefix extends Fixity with Product with Serializable

    Describes unary prefix operators

    Describes unary prefix operators

    Since

    4.0.0

  8. object SOps

    This helper object builds values of Ops[A, B] where A <: B, for subtyped heterogeneous precedence parsing.

    This helper object builds values of Ops[A, B] where A <: B, for subtyped heterogeneous precedence parsing.

    Since

    3.0.0

  9. object chain

    This module contains the very useful chaining family of combinators, which are mostly used to parse operators and expressions of varying fixities.

    This module contains the very useful chaining family of combinators, which are mostly used to parse operators and expressions of varying fixities. It is a more low-level API compared with precedence.

    Since

    2.2.0

  10. object infix

    This module contains the very useful chaining family of combinators, which are mostly used to parse operators and expressions of varying fixities.

    This module contains the very useful chaining family of combinators, which are mostly used to parse operators and expressions of varying fixities. It is a more low-level API compared with precedence.

    Compared with the combinators in chain, these allow for more freedom in the type of the values and the operators.

    Since

    4.0.0

  11. object mixed

    This module contains specialist combinators for mixing unary and binary operators on the same level.

    This module contains specialist combinators for mixing unary and binary operators on the same level. This is only sensible when mixing infix-left and postfix or infix-right and prefix.

    Since

    4.0.0

    Note

    the behaviour of the enclosed combinators may be counter intuitive: they should not be used unless you know what you are doing.

  12. object precedence

    This object is used to construct precedence parsers from either a Prec or many Ops[A, A].

    This object is used to construct precedence parsers from either a Prec or many Ops[A, A].

    Contained within this object are three different shapes of apply functions: they allows for the construction of a precedence parser from either: a collection of levels of operators and atoms, in either weak-to-strong or strong-to-weak orderings; or a heterogeneous precedence table Prec.

    Since

    2.2.0

Inherited from AnyRef

Inherited from Any

Chain Combinators

These are all modules that contain the standalone chain combinators. These are useful for parsing the application of operators to values in many different configurations, including: prefix, postfix, infix (left and right associated), and mixed fixity. These combinators do have their uses, however they will be overshadowed by the precedence combinator, which allows for the combining of multiple levels of chaining in a clean and concise way.

The Precedence Combinator

This object contains apply methods which represent each of the different "shapes" of precedence combinator, which takes a description of the precedence relations between various operators and constructs a parser for them.

Precedence Layer Builders

These are used to construct an individual layer of a precedence table. They all allow for the tying of a fixity: Fixity to the parsers that inhabit the level, which will have type fixity.Op[A, B] for some A (the type of the layer below) and B (the type of this layer). This is the path-dependent typing at work: the types of the parsers are only known when fixity itself is known. The different objects represent different inter-layer relationships: are they the same type? Use Ops; is the layer below a subtype of this layer? use SOps; or none of the above? Use Gops!

Fixity Description

These all describe the fixities and associativities of operators at a given level of the precedence table. They are special because they each encode an Op type, which directs the type of the operators that are legal at the level (using path-dependent typing).

Precedence Table Datatypes

These are the parts that make up a precedence table (in particular, they are used for heterogeneous expression parsing, with the types of each layer of the table vary from one another). These are (mostly) not constructed directly, but are instead constructed via the use of the Ops builders or the :+ and +: methods.