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.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.syntax contains several implicits to add syntactic sugar to the combinators. These are sub-categorised into the following sub modules:
      • parsley.syntax.character contains implicits to allow you to use character and string literals as parsers.
      • parsley.syntax.lift enables postfix application of the lift combinator onto a function (or value).
      • parsley.syntax.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.syntax.extension contains syntactic sugar combinators exposed as implicit classes.
    • 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.state contains combinators that interact with the context-sensitive functionality in the form of state.
    • 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.generic 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.

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

  • package syntax
  • 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.
  • Failure
  • Parsley
  • PlatformSpecific
  • Result
  • Success
  • ap
  • character
  • combinator
  • debug
  • generic
  • lift
  • position
  • state
  • unicode
p

parsley

package parsley

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. Protected

Package Members

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

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

  3. package syntax
  4. 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.

Type Members

  1. class Failure[Err] extends Result[Err, Nothing] with Product with Serializable

    This class is used for a parser failure, and contains the error message.

    This class is used for a parser failure, and contains the error message.

    Err

    the type of the error message generated by the failing parse.

  2. final class Parsley[+A] extends AnyVal

    This is the class that encapsulates the act of parsing and running an object of this class with parse will parse the string given as input to parse.

    This is the class that encapsulates the act of parsing and running an object of this class with parse will parse the string given as input to parse.

    Version

    4.0.0

    Note

    In order to construct an object of this class you must use the combinators; the class itself is opaque.

  3. class PlatformSpecific extends AnyRef
  4. sealed abstract class Result[+Err, +A] extends AnyRef

    This trait represents the result of a parser.

    This trait represents the result of a parser.

    Either a Success[A] or a Failure.

    A

    the type of expected success result.

  5. case class Success[A](x: A) extends Result[Nothing, A] with Product with Serializable

    This class is used for when a parser succeeds, and contains its result.

    This class is used for when a parser succeeds, and contains its result.

    A

    the type of expected success result.

    x

    the result value of the successful parse.

Value Members

  1. object Failure extends Serializable
  2. object Parsley extends PlatformSpecific

    This object contains the core "function-style" combinators: all parsers will likely require something from within!

    This object contains the core "function-style" combinators: all parsers will likely require something from within!

    In particular, it contains combinators for: controlling how input is consumed; injecting values into the parser, or failing; extracting position information from the parser; conditional execution of parsers; and more.

  3. object ap

    This module contains ap1 through ap22, which allow for the application of a parser returning a function of arity N to N parsers.

    This module contains ap1 through ap22, which allow for the application of a parser returning a function of arity N to N parsers.

    The combinators contained in this module all sequence a number of parsers together, but are capable of combining the results generated by these parsers into a single value with a function of the correct arity produced by the first parser. This is a clean way of putting together multiple parsers and getting a meaningful result out.

    Example:
    1. scala> import parsley.character.char
      scala> import parsley.ap.{ap2, ap3}
      scala> case class Add(x: Int, y: Int)
      scala> val p = ap2(pure(Add), char('a').as(4), char('b').as(5))
      scala> p.parse("ab")
      val res0 = Success(Add(4, 5))
      scala> val q = ap3(pure((x: Int, y: Int, z: Int) => x * y + z), char('a').as(3), char('b').as(2), char('c').as(5))
      scala> q.parse("abc")
      val res1 = Success(11)
      scala> q.parse("ab")
      val res2 = Failure(..)
    Since

    4.0.0

  4. object character

    This module contains many parsers to do with reading one or more characters.

    This module contains many parsers to do with reading one or more characters. Almost every parser will need something from this module.

    In particular, this module contains: combinators that can read specific characters; combinators that represent character classes and their negations; combinators for reading specific strings; as well as a selection of pre-made parsers to parse specific kinds of character, like digits and letters.

    Since

    2.2.0

  5. object combinator

    This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.

    This module contains a huge number of pre-made combinators that are very useful for a variety of purposes.

    In particular, it contains combinators for: performing a parser iteratively, collecting all the results; querying whether or not any input is left; optionally performing parsers; parsing delimited constructions; handling multiple possible alternatives or parsers to sequence; handling more complex conditional execution; and more.

    Since

    2.2.0

  6. object debug

    This module contains the very useful debugging combinator, as well as breakpoints.

  7. object generic

    This module contains the definition of 23 basic generic parser bridge traits, which are used to implement the Parser Bridge pattern for types that do not require metadata.

    This module contains the definition of 23 basic generic parser bridge traits, which are used to implement the Parser Bridge pattern for types that do not require metadata.

    The traits within are designed to be extended by the companion object of some case class that is produced as the result of a parser: by using these traits, it enables a new apply method that makes it appear like the constructor is applied to the parsers themselves. This can be very useful for performing extra verification on the produced results, or to incorporate metadata into the result. Specifically, these traits are designed to be the bare-minimum functionaity, and do not interact with any metadata.

    Since

    4.5.0

  8. object lift

    This module contains lift1 through lift22, which allow for the application of a function of arity N to N parsers.

    This module contains lift1 through lift22, which allow for the application of a function of arity N to N parsers.

    The combinators contained in this module all sequence a number of parsers together, but are capable of combining the results generated by these parsers into a single value with a given function of the correct arity. This is a clean way of putting together multiple parsers and getting a meaningful result out.

    Example:
    1. scala> import parsley.character.char
      scala> import parsley.lift.{lift2, lift3}
      scala> case class Add(x: Int, y: Int)
      scala> val p = lift2(Add, char('a').as(4), char('b').as(5))
      scala> p.parse("ab")
      val res0 = Success(Add(4, 5))
      scala> val q = lift3((x: Int, y: Int, z: Int) => x * y + z, char('a').as(3), char('b').as(2), char('c').as(5))
      scala> q.parse("abc")
      val res1 = Success(11)
      scala> q.parse("ab")
      val res2 = Failure(..)
      scala> val q2 = lift3[Int, Int, Int, Int](_ * _ + _, char('a').as(3), char('b').as(2), char('c').as(5))
    Since

    2.2.0

  9. object position

    This module contains parsers that provide a way to extract position information during a parse.

    This module contains parsers that provide a way to extract position information during a parse.

    Position parsers can be important for when the final result of the parser needs to encode position information for later consumption: this is particularly useful for abstract syntax trees. Offset is also exposed by this interface, which may be useful for establishing a caret size in specialised error messages.

    Since

    4.2.0

  10. object state

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

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

    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 references, though slightly more flexible. In particular, the persist combinator enabled by StateCombinators can serve as a drop-in replacement for flatMap in many scenarios.

    Since

    4.5.0

  11. object unicode

    This module contains many parsers to do with reading one or more characters.

    This module contains many parsers to do with reading one or more characters.

    In particular, this module contains: combinators that can read specific characters; combinators that represent character classes and their negations; combinators for reading specific strings; as well as a selection of pre-made parsers to parse specific kinds of character, like digits and letters. Unlike character, this module handles full utf-16 codepoints, which can be up to two 16-bit characters long.

    Since

    4.4.0

Ungrouped