megaparsec-4.1.0: Monadic parser combinators

Copyright© 2015 Megaparsec contributors © 2007 Paolo Martini © 1999–2001 Daan Leijen
LicenseBSD3
MaintainerMark Karpov <markkarpov@opmbx.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Text.Megaparsec.Error

Description

Parse errors.

Synopsis

Documentation

data Message Source

This data type represents parse error messages. There are three kinds of messages:

data Message = Unexpected String
             | Expected   String
             | Message    String

The 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

The data type ParseError represents parse errors. It provides the source position (SourcePos) of the error and a list of error messages (Message). A ParseError can be returned by the function parse. ParseError is an instance of the Show and Eq type classes.

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.

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.

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.