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

Description

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

Synopsis

Verified Errors

These are combinators related to the Verified Errors parser design pattern.

They allow for the parsing of known illegal values, providing richer error messages in case they succeed.

Note

Expand

The following applies to each of the verified<...> combinators:

When this combinator fails (and not this parser itself), it will generate errors rooted at the start of the parse (as if amend had been used) and the caret will span the entire successful parse of this parser.

When this parser is not to be considered as a terminal error, use atomic around the entire combinator to allow for backtracking if this parser succeeds (and therefore fails).

verifiedWith Source #

Arguments

:: ErrorGen a

err, the generator that produces the error message.

-> Parsec a

p, the parser for the bad input.

-> Parsec b

a parser that ensures p fails, otherwise it raises an error described by err.

Ensures this parser does not succeed, failing with an error as described by the given ErrorGen object.

If this parser succeeds, input is consumed and this combinator will fail, producing an error message using the given ErrorGen with width the same as the parsed data. However, if this parser fails, no input is consumed and an empty error is generated.

This parser will produce no labels if it fails.

Since: 0.2.3.0

verifiedFail Source #

Arguments

:: (a -> [String])

the function that generates the error messages from the parsed value.

-> Parsec a

p, the parser for the bad input.

-> Parsec b

a parser that ensures p fails, otherwise it raises an error with the given message based on the result.

Ensures this parser does not succeed, failing with a specialised error based on this parsers result if it does.

If this parser succeeds, input is consumed and this combinator will fail, producing an error message based on the parsed result. However, if this parser fails, no input is consumed and an empty error is generated.

This parser will produce no labels if it fails.

Since: 0.2.3.0

verifiedUnexpected Source #

Arguments

:: Parsec a

p, the parser for the bad input.

-> Parsec b

a parser that ensures p fails, otherwise it raises an unexpected error.

Ensures this parser does not succeed, failing with a vanilla error with an unexpected message and caret spanning the parse.

If this parser succeeds, input is consumed and this combinator will fail, producing an unexpected message the same width as the parse. However, if this parser fails, no input is consumed and an empty error is generated.

This parser will produce no labels if it fails.

Since: 0.2.3.0

verifiedExplain Source #

Arguments

:: (a -> String)

a function that produces a reason for the error given the parsed result.

-> Parsec a

p, the parser for the bad input.

-> Parsec b

a parser that ensures p fails, otherwise it raises an error with the given reason based on the result.

Ensures this parser does not succeed, failing with a vanilla error with an unexpected message and caret spanning the parse and a reason generated from this parser's result.

If this parser succeeds, input is consumed and this combinator will fail, producing an unexpected message the same width as the parse along with a reason generated from the successful parse. However, if this parser fails, no input is consumed and an empty error is generated. This parser will produce no labels if it fails.

Since: 0.2.3.0

Preventative Errors

These are combinators related to the Preventative Errors parser design pattern.

They allow for the parsing of known illegal values, providing richer error messages in case they succeed.

Note

Expand

The following applies to each of the verified<...> combinators:

When this combinator fails (and not this parser itself), it will generate errors rooted at the start of the parse (as if amend had been used) and the caret will span the entire successful parse of this parser.

When this parser is not to be considered as a terminal error, use atomic around the entire combinator to allow for backtracking if this parser succeeds (and therefore fails).

preventWith Source #

Arguments

:: ErrorGen a

err, the generator that produces the error message.

-> Parsec a

p, the parser for the bad input.

-> Parsec ()

a parser that ensures p fails, otherwise it raises an error described by err.

Ensures this parser does not succeed, failing with an error as described by the given ErrorGen object.

If this parser succeeds, input is consumed and this combinator will fail, producing an error message using the given errGen with width the same as the parsed data along with the given labels. However, if this parser fails, no input is consumed and this combinator succeeds.

This parser will produce no evidence of running if it succeeds.

Since: 0.2.3.0

preventativeFail Source #

Arguments

:: (a -> [String])

the function that generates the error messages from the parsed value.

-> Parsec a

p, the parser for the bad input.

-> Parsec ()

a parser that ensures p fails, otherwise it raises an error with the given message based on the result.

Ensures this parser does not succeed, failing with a specialised error based on this parsers result if it does.

If this parser succeeds, input is consumed and this combinator will fail, producing an error message based on the parsed result. However, if this parser fails, no input is consumed and this combinator succeeds. This parser will produce no evidence of running if it succeeds.

Since: 0.2.3.0

preventativeExplain Source #

Arguments

:: (a -> String)

a function that produces a reason for the error given the parsed result.

-> Parsec a

p, the parser for the bad input.

-> Parsec ()

a parser that ensures p fails, otherwise it raises an unexpected error with the given reason based on the result.

Ensures this parser does not succeed, failing with a vanilla error with an unexpected message and caret spanning the parse and a reason generated from this parser's result.

If this parser succeeds, input is consumed and this combinator will fail, producing an unexpected message the same width as the parse along with a reason generated from the successful parse along with the given labels. However, if this parser fails, no input is consumed and this combinator succeeds. This parser will produce no evidence of running if it succeeds.

Since: 0.2.3.0