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.
- Source
- package.scala
- Grouped
- Alphabetic
- By Inheritance
- expr
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
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
-
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
-
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
B
s, possiblyA
s and produceB
s: 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.
-
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
-
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
-
object
InfixL extends Fixity with Product with Serializable
Describes left-associative binary operators
Describes left-associative binary operators
- Since
4.0.0
-
object
InfixN extends Fixity with Product with Serializable
Describes non-associative operators
Describes non-associative operators
- Since
4.0.0
-
object
InfixR extends Fixity with Product with Serializable
Describes right-associative binary operators
Describes right-associative binary operators
- Since
4.0.0
-
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
-
object
Postfix extends Fixity with Product with Serializable
Describes unary postfix operators
Describes unary postfix operators
- Since
4.0.0
-
object
Prefix extends Fixity with Product with Serializable
Describes unary prefix operators
Describes unary prefix operators
- Since
4.0.0
-
object
SOps
This helper object builds values of
Ops[A, B]
whereA <: B
, for subtyped heterogeneous precedence parsing.This helper object builds values of
Ops[A, B]
whereA <: B
, for subtyped heterogeneous precedence parsing.- Since
3.0.0
-
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
-
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
-
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.
-
object
precedence
This object is used to construct precedence parsers from either a
Prec
or manyOps[A, A]
.This object is used to construct precedence parsers from either a
Prec
or manyOps[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 tablePrec
.- Since
2.2.0
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.
This is the documentation for Parsley.
Package structure
The parsley package contains the
Parsley
class, as well as theResult
,Success
, andFailure
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.expr
contains the following sub modules:parsley.expr.chain
contains combinators used in expression parsingparsley.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 inchain
.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 aParsley[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.errors.tokenextractors
provides mixins for common token extraction strategies during error message generation: these can be used to avoid implementingunexpectedToken
in theErrorBuilder
.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 theLexer
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.