Copyright | © 2015–2016 Megaparsec contributors |
---|---|
License | FreeBSD |
Maintainer | Mark Karpov <markkarpov@opmbx.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Parse errors. Current version of Megaparsec supports well-typed errors
instead of String
-based ones. This gives a lot of flexibility in
describing what exactly went wrong as well as a way to return arbitrary
data in case of failure.
- data ErrorItem t
- class Ord e => ErrorComponent e where
- representFail :: String -> e
- representIndentation :: Ordering -> Pos -> Pos -> e
- data Dec
- data ParseError t e = ParseError {
- errorPos :: NonEmpty SourcePos
- errorUnexpected :: Set (ErrorItem t)
- errorExpected :: Set (ErrorItem t)
- errorCustom :: Set e
- class ShowToken a where
- showTokens :: NonEmpty a -> String
- class Ord a => ShowErrorComponent a where
- showErrorComponent :: a -> String
- parseErrorPretty :: (Ord t, ShowToken t, ShowErrorComponent e) => ParseError t e -> String
- sourcePosStackPretty :: NonEmpty SourcePos -> String
Documentation
Data type that is used to represent “unexpected/expected” items in
parse error. The data type is parametrized over token type t
.
Since: 5.0.0
class Ord e => ErrorComponent e where Source
The type class defines how to represent information about various
exceptional situations. Data types that are used as custom data component
in ParseError
must be instances of this type class.
Since: 5.0.0
“Default error component”. This in our instance of ErrorComponent
provided out-of-box.
Since: 5.0.0
data ParseError t e Source
The data type ParseError
represents parse errors. It provides the
stack of source positions, set of expected and unexpected tokens as well
as set of custom associated data. The data type is parametrized over
token type t
and custom data e
.
Note that stack of source positions contains current position as its head, and the rest of positions allows to track full sequence of include files with topmost source file at the end of the list.
Semigroup
(or Monoid
) instance of the data type allows to merge parse
errors from different branches of parsing. When merging two
ParseError
s, longest match is preferred; if positions are the same,
custom data sets and collections of message items are combined.
ParseError | |
|
(Eq t, Eq e) => Eq (ParseError t e) Source | |
(Ord t, Ord e, Read t, Read e) => Read (ParseError t e) Source | |
(Show t, Show e) => Show (ParseError t e) Source | |
(Show t, Typeable * t, Show e, Typeable * e) => Exception (ParseError t e) Source | |
(Ord t, Ord e) => Monoid (ParseError t e) Source | |
(Ord t, Ord e) => Semigroup (ParseError t e) Source |
class ShowToken a where Source
Type class ShowToken
includes methods that allow to pretty-print
single token as well as stream of tokens. This is used for rendering of
error messages.
showTokens :: NonEmpty a -> String Source
Pretty-print non-empty stream of tokens. This function is also used to print single tokens (represented as singleton lists).
Since: 5.0.0
class Ord a => ShowErrorComponent a where Source
The type class defines how to print custom data component of
ParseError
.
Since: 5.0.0
showErrorComponent :: a -> String Source
Pretty-print custom data component of ParseError
.
ShowErrorComponent Dec Source | |
(Ord t, ShowToken t) => ShowErrorComponent (ErrorItem t) Source |
:: (Ord t, ShowToken t, ShowErrorComponent e) | |
=> ParseError t e | Parse error to render |
-> String | Result of rendering |
Pretty-print ParseError
. Note that rendered String
always ends with
a newline.
Since: 5.0.0
sourcePosStackPretty :: NonEmpty SourcePos -> String Source
Pretty-print stack of source positions.
Since: 5.0.0