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

    This package contains implementations of token extractors that can be mixed into ErrorBuilder to decide how to extract unexpected tokens from the residual input left over from a parse error.

    This package contains implementations of token extractors that can be mixed into ErrorBuilder to decide how to extract unexpected tokens from the residual input left over from a parse error.

    These are common strategies, and something here is likely to be what is needed. They are all careful to handle unprintable characters and whitespace in a sensible way, and account for unicode codepoints that are wider than a single 16-bit character.

    Since

    4.0.0

  • DefaultErrorBuilder
  • ErrorBuilder
  • ErrorGen
  • SpecialisedGen
  • Token
  • TokenSpan
  • UnexpectedItem
  • VanillaGen
  • combinator
  • patterns
  • 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
  • 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
p

parsley

errors

package errors

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.

Source
package.scala
Linear Supertypes
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. errors
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class DefaultErrorBuilder extends ErrorBuilder[String]

    This class us used to build Parsley's default error messages.

    This class us used to build Parsley's default error messages.

    While it compiles with the ErrorBuilder typeclass, it should not be considered a stable contract: the formatting can be changed at any time and without notice. The API, however, will remain stable.

    Since

    3.0.0

    Note

    this class is abstract as it does not implement unexpectedToken: when creating an instance mix-in an appropriate token extractor from parsley.errors.tokenextractors.

  2. trait ErrorBuilder[+Err] extends AnyRef

    This typeclass specifies how to format an error from a parser as a specified type.

    This typeclass specifies how to format an error from a parser as a specified type.

    An instance of this trait is required when calling parse (or similar). By default, Parsley defines its own instance for ErrorBuilder[String] found in the ErrorBuilder companion object.

    To implement this trait, a number of methods must be defined, as well the representation types for a variety of different components; the relation between the various methods is closely linked to the types that they both produce and consume. To only change the basics of formatting without having to define the entire instance, inherit from DefaultErrorBuilder: this will mean, however, that the representation types cannot be overriden.

    How an Error is Structured

    There are two kinds of error messages that are generated by Parsley: Specialised and Vanilla. These are produced by different combinators and can be merged with other errors of the same type if both errors appear at the same offset. However, Specialised errors will take precedence over Vanilla errors if they appear at the same offset. The most common form of error is the Vanilla variant, which is generated by most combinators, except for some in errors.combinator.

    Both types of error share some common structure, namely:

    • The error preamble, which has the file and the position.
    • The content lines, the specifics of which differ between the two types of error.
    • The context lines, which has the surrounding lines of input for contextualisation.

    Vanilla Errors

    There are three kinds of content line found in a Vanilla error:

    1. Unexpected info: this contains information about the kind of token that caused the error.
    2. Expected info: this contains the information about what kinds of token could have avoided the error.
    3. Reasons: these are the bespoke reasons that an error has occurred (as generated by explain).

    There can be at most one unexpected line, at most one expected line, and zero or more reasons. Both of the unexpected and expected info are built up of error items, which are either: the end of input, a named token, raw input taken from the parser definition. These can all be formatted separately.

    The overall structure of a Vanilla error is given in the following diagram:

    ┌───────────────────────────────────────────────────────────────────────┐
    │   Vanilla Error                                                       │
    │                          ┌────────────────┐◄──────── position         │
    │                  source  │                │                           │
    │                     │    │   line      col│                           │
    │                     ▼    │     │         ││                           │
    │                  ┌─────┐ │     ▼         ▼│   end of input            │
    │               In foo.txt (line 1, column 5):       │                  │
    │                 ┌─────────────────────┐            │                  │
    │unexpected ─────►│                     │            │  ┌───── expected │
    │                 │          ┌──────────┐ ◄──────────┘  │               │
    │                 unexpected end of input               ▼               │
    │                 ┌──────────────────────────────────────┐              │
    │                 expected "(", "negate", digit, or letter              │
    │                          │    └──────┘  └───┘     └────┘ ◄────── named│
    │                          │       ▲        └──────────┘ │              │
    │                          │       │                     │              │
    │                          │      raw                    │              │
    │                          └─────────────────┬───────────┘              │
    │                 '-' is a binary operator   │                          │
    │                 └──────────────────────┘   │                          │
    │                ┌──────┐        ▲           │                          │
    │                │>3+4- │        │           expected items             │
    │                │     ^│        │                                      │
    │                └──────┘        └───────────────── reason              │
    │                   ▲                                                   │
    │                   │                                                   │
    │                   line info                                           │
    └───────────────────────────────────────────────────────────────────────┘

    Specialised Errors

    There is only one kind of content found in a Specialised error: a message. These are completely free-form, and are generated by the fail combinator, as well as its derived combinators. There can be one or more messages in a Specialised error.

    The overall structure of a Specialised error is given in the following diagram:

    ┌───────────────────────────────────────────────────────────────────────┐
    │   Specialised Error                                                   │
    │                          ┌────────────────┐◄──────── position         │
    │                  source  │                │                           │
    │                     │    │   line       col                           │
    │                     ▼    │     │         │                            │
    │                  ┌─────┐ │     ▼         ▼                            │
    │               In foo.txt (line 1, column 5):                          │
    │                                                                       │
    │           ┌───► something went wrong                                  │
    │           │                                                           │
    │ message ──┼───► it looks like a binary operator has no argument       │
    │           │                                                           │
    │           └───► '-' is a binary operator                              │
    │                ┌──────┐                                               │
    │                │>3+4- │                                               │
    │                │     ^│                                               │
    │                └──────┘                                               │
    │                   ▲                                                   │
    │                   │                                                   │
    │                   line info                                           │
    └───────────────────────────────────────────────────────────────────────┘
    Err

    The final result type of the error message

    Since

    3.0.0

  3. sealed abstract class ErrorGen[-A] extends AnyRef
  4. class SpecialisedGen[-A] extends ErrorGen[A]
  5. sealed abstract class Token extends AnyRef

    This class represents an extracted token returned by unexpectedToken in ErrorBuilder.

    This class represents an extracted token returned by unexpectedToken in ErrorBuilder.

    There is deliberately no analogue for EndOfInput because we guarantee that non-empty residual input is provided to token extraction.

    Since

    4.0.0

  6. sealed abstract class TokenSpan extends AnyRef

    This class and its subtypes are used to describe how big a token should be (and therefore the size of the corresponding error caret).

    This class and its subtypes are used to describe how big a token should be (and therefore the size of the corresponding error caret). This is provided to Token.Named and is therefore used in the creation of Tokens for lexical extractors.

    Since

    4.0.0

  7. sealed abstract class UnexpectedItem extends AnyRef
  8. class VanillaGen[-A] extends ErrorGen[A]

Value Members

  1. object DefaultErrorBuilder

    Helper functions used to build the DefaultErrorBuilder error messages.

    Helper functions used to build the DefaultErrorBuilder error messages.

    Since

    4.3.0

  2. object ErrorBuilder

    Contains the default instance for the ErrorBuilder typeclass, which will be automatically available without import.

  3. object Token

    This object contains the sub-types of Token.

    This object contains the sub-types of Token.

    Since

    4.0.0

  4. object TokenSpan

    This object contains the sub-types of TokenSpan.

    This object contains the sub-types of TokenSpan.

    Since

    4.0.0

  5. object UnexpectedItem
  6. object combinator

    This module contains combinators that can be used to directly influence error messages of parsers.

    This module contains combinators that can be used to directly influence error messages of parsers.

    Error messages are, by default, not particularly descriptive. However, the combinators in this module can be used to improve the generation of error messages by providing labels for expected items, explanations for why things went wrong, custom error messages, custom unexpected error messages, as well as correcting the offsets that error messages actually occurred at.

    Since

    3.0.0

  7. object patterns

    This module contains combinators that help facilitate the error message generational patterns Verified Errors and Preventative Errors.

    This module contains combinators that help facilitate the error message generational patterns Verified Errors and Preventative Errors.

    In particular, exposes an extension class VerifiedErrors that facilitates creating verified errors in many different formats.

    Since

    4.2.0

Inherited from AnyRef

Inherited from Any

Error Combinators

These are combinators associated with influencing how error messages are generated during a parse.

Error Formatting and Construction

These classes control how error messages are constructed by Parsley - via the ErrorBuilder typeclass.

Unexpected Token Description

These are classes used to describe unexpected tokens that are extracted from residual input after a failed parse.

Ungrouped