| Copyright | © 2015 Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen |
|---|---|
| License | FreeBSD |
| Maintainer | Mark Karpov <markkarpov@opmbx.org> |
| Stability | experimental |
| Portability | portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Text.Megaparsec.Error
Description
Parse errors.
- data Message
- messageString :: Message -> String
- badMessage :: Message -> Bool
- data ParseError
- errorPos :: ParseError -> SourcePos
- errorMessages :: ParseError -> [Message]
- errorIsUnknown :: ParseError -> Bool
- newErrorMessage :: Message -> SourcePos -> ParseError
- newErrorMessages :: [Message] -> SourcePos -> ParseError
- newErrorUnknown :: SourcePos -> ParseError
- addErrorMessage :: Message -> ParseError -> ParseError
- addErrorMessages :: [Message] -> ParseError -> ParseError
- setErrorMessage :: Message -> ParseError -> ParseError
- setErrorPos :: SourcePos -> ParseError -> ParseError
- mergeError :: ParseError -> ParseError -> ParseError
- showMessages :: [Message] -> String
Documentation
This data type represents parse error messages. There are three kinds of messages:
data Message = Unexpected String
| Expected String
| Message StringThe fine distinction between different kinds of parse errors allows the system to generate quite good error messages for the user.
messageString :: Message -> String Source
Extract the message string from an error message.
badMessage :: Message -> Bool Source
Test if message string is empty.
data ParseError Source
errorPos :: ParseError -> SourcePos Source
Extract the source position from ParseError.
errorMessages :: ParseError -> [Message] Source
Extract the list of error messages from ParseError.
errorIsUnknown :: ParseError -> Bool Source
Test whether given ParseError has associated collection of error
messages. Return True if it has none and False otherwise.
newErrorMessage :: Message -> SourcePos -> ParseError Source
newErrorMessage m pos creates ParseError with message m and
associated position pos. If message m has empty message string, it
won't be included.
newErrorMessages :: [Message] -> SourcePos -> ParseError Source
newErrorMessages ms pos creates ParseError with messages ms and
associated position pos.
newErrorUnknown :: SourcePos -> ParseError Source
newErrorUnknown pos creates ParseError without any associated
message but with specified position pos.
addErrorMessage :: Message -> ParseError -> ParseError Source
addErrorMessage m err returns err with message m added. This
function makes sure that list of messages is always sorted and doesn't
contain duplicates or messages with empty message strings.
addErrorMessages :: [Message] -> ParseError -> ParseError Source
addErrorMessages ms err returns err with messages ms added. The
function is defined in terms of addErrorMessage.
setErrorMessage :: Message -> ParseError -> ParseError Source
setErrorMessage m err returns err with message m added. This
function also deletes all existing error messages that were created with
the same constructor as m. If message m has empty message string, the
function does not add the message to the result (it still deletes all
messages of the same type, though).
setErrorPos :: SourcePos -> ParseError -> ParseError Source
setErrorPos pos err returns ParseError identical to err, but with
position pos.
mergeError :: ParseError -> ParseError -> ParseError Source
Merge two error data structures into one joining their collections of
messages and preferring longest match. In other words, earlier error
message is discarded. This may seem counter-intuitive, but mergeError
is only used to merge error messages of alternative branches of parsing
and in this case longest match should be preferred.
showMessages :: [Message] -> String Source
showMessages ms transforms list of error messages ms into
their textual representation.