megaparsec-4.4.0: Monadic parser combinators

Copyright© 2015–2016 Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen
MaintainerMark Karpov <>
Safe HaskellNone



Parse errors.



data Message Source

This data type represents parse error messages.


Unexpected !String

Parser ran into an unexpected token

Expected !String

What is expected instead

Message !String

General-purpose error message component

isUnexpected :: Message -> Bool Source

Check if given Message is created with Unexpected constructor.

Since: 4.4.0

isExpected :: Message -> Bool Source

Check if given Message is created with Expected constructor.

Since: 4.4.0

isMessage :: Message -> Bool Source

Check if given Message is created with Message constructor.

Since: 4.4.0

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

The data type ParseError represents parse errors. It provides the source position (SourcePos) of the error and a list of error messages (Message).

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.

Since: 4.2.0

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.

Since: 4.2.0

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.