gigaparsec-0.3.0.0: Refreshed parsec-style library for compatibility with Scala parsley
LicenseBSD-3-Clause
MaintainerJamie Willis, Gigaparsec Maintainers
Stabilityexperimental
Safe HaskellSafe
LanguageHaskell2010

Text.Gigaparsec.Errors.ErrorGen

Description

This module can be used to generate hand-tuned error messages without using monadic bind.

Synopsis

Documentation

Error Generators

data ErrorGen a Source #

This type describes special primitives that can use the results of a previous parser to form and raise an error message. This is not something that is normally possible with raw combinators, without using (>>=), which is expensive.

Primarily, these are designed to be used with filterSWith/verifiedWith/preventWith but can be used in other parsers as well.

Constructors

SpecializedGen

An error generator for Specialized errors, which can tune the freeform messages of the error.

Fields

  • messages :: a -> [String]

    Produces the messages of the error message when given the result of the offending parser.

  • adjustWidth :: a -> Word -> Word

    Controls how wide an error is based on the value a and width Word provided.

VanillaGen

An error generator for Vanilla errors, which can tune the unexpected message and a generated reason.

Fields

  • unexpected :: a -> UnexpectedItem

    Produces the unexpected component (if any) of the error message when given the result of the offending parser.

  • reason :: a -> Maybe String

    Produces the reason component (if any) of the error message when given the result of the offending parser.

  • adjustWidth :: a -> Word -> Word

    Controls how wide an error is based on the value a and width Word provided.

data UnexpectedItem Source #

This type describes how to form the unexpected component of a vanilla error message from a VanillaGen.

This includes the different sorts of 'unexpected item' messages that may occur; whether to display the expected characters, a name for the expected expression, or not to display at all.

Constructors

RawItem

The error should use whatever input was consumed by the offending parser, verbatim.

EmptyItem

The error should not have an unexpected component at all (as in filterS).

NamedItem String

The error should use the given name as the unexpected component.

Blank Generators

vanillaGen :: ErrorGen a Source #

A blank Vanilla error generator, which does not affect the unexpected message or reason.

specializedGen :: ErrorGen a Source #

The default Specialized error generator, which does not affect the error message.

Error Generating Combinators

These combinators create parsers that fail or raise errors with messages desribed by a given ErrorGen.

asFail Source #

Arguments

:: ErrorGen a

errGen, the generator for the error message.

-> Parsec (a, Word)

p, a parser that returns a result x and its width w.

-> Parsec b

A parser that unconditionally fails with a message described by errGen, using the result of p.

This combinator takes a given parser p and unconditionally fails with a message based on p's results.

asSelect Source #

Arguments

:: ErrorGen a

errGen, the generator for the error message.

-> Parsec (Either (a, Word) b)

p, a parser which may produce a bad result of type a

-> Parsec b

A parser that fails if p produces a bad result, otherwise returns the result of p if it is a b

This combinator takes a given parser p and, if p returns an a, fails with a message based on this result.

asErr Source #

Arguments

:: ErrorGen a

errGen, the generator for the error message to raise.

-> a

x, the result of the offending parser

-> Word

The width of the parsed result, x.

-> Parsec b

A parser that unconditionally raises an error described by errGen.

Given a parser result and its width, raise an error according to the given error generator.