License | BSD-3-Clause |
---|---|
Maintainer | Jamie Willis, Gigaparsec Maintainers |
Stability | experimental |
Safe Haskell | Safe |
Language | Haskell2010 |
This module contains combinators that help facilitate the error message generational patterns Verified Errors™ and Preventative Errors™.
Synopsis
- verifiedWith :: ErrorGen a -> Parsec a -> Parsec b
- verifiedFail :: (a -> [String]) -> Parsec a -> Parsec b
- verifiedUnexpected :: Parsec a -> Parsec b
- verifiedExplain :: (a -> String) -> Parsec a -> Parsec b
- preventWith :: ErrorGen a -> Parsec a -> Parsec ()
- preventativeFail :: (a -> [String]) -> Parsec a -> Parsec ()
- preventativeExplain :: (a -> String) -> Parsec a -> Parsec ()
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
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).
:: ErrorGen a |
|
-> Parsec a |
|
-> Parsec b | a parser that ensures |
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
:: (a -> [String]) | the function that generates the error messages from the parsed value. |
-> Parsec a |
|
-> Parsec b | a parser that ensures |
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
:: Parsec a |
|
-> Parsec b | a parser that ensures |
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
:: (a -> String) | a function that produces a reason for the error given the parsed result. |
-> Parsec a |
|
-> Parsec b | a parser that ensures |
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
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).
:: ErrorGen a |
|
-> Parsec a |
|
-> Parsec () | a parser that ensures |
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
:: (a -> [String]) | the function that generates the error messages from the parsed value. |
-> Parsec a |
|
-> Parsec () | a parser that ensures |
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
:: (a -> String) | a function that produces a reason for the error given the parsed result. |
-> Parsec a |
|
-> Parsec () | a parser that ensures |
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