Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module contains lexer and error message primitives for a simple lambda calculus parser. It demonstrates a simple but decently informative implementation of error message propagation.
Synopsis
- data Expected
- data Error'
- data Error = Error !Pos !Error'
- merge :: Error -> Error -> Error
- type Parser = Parser () Error
- prettyError :: ByteString -> Error -> String
- cut :: Parser a -> [Expected] -> Parser a
- cut' :: Parser a -> Expected -> Parser a
- runParser :: Parser a -> ByteString -> Result Error a
- testParser :: Show a => Parser a -> String -> IO ()
- lineComment :: Parser ()
- multilineComment :: Parser ()
- ws :: Parser ()
- token :: Parser a -> Parser a
- identStartChar :: Parser Char
- identChar :: Parser Char
- isKeyword :: Span -> Parser ()
- symbol :: String -> Q Exp
- cutSymbol :: String -> Q Exp
- keyword :: String -> Q Exp
- cutKeyword :: String -> Q Exp
Documentation
An expected item which is displayed in error messages.
A parsing error, without source position.
A source-annotated error.
merge :: Error -> Error -> Error Source #
Merge two errors. Imprecise errors are merged by appending lists of expected items. If we have a precise and an imprecise error, we throw away the imprecise one. If we have two precise errors, we choose the left one, which is by convention the one throw by an inner parser.
The point of prioritizing inner and precise errors is to suppress the deluge of "expected" items, and instead try to point to a concrete issue to fix.
prettyError :: ByteString -> Error -> String Source #
Pretty print an error. The ByteString
input is the source file. The offending line from the
source is displayed in the output.
cut :: Parser a -> [Expected] -> Parser a Source #
Imprecise cut: we slap a list of expected things on inner errors.
cut' :: Parser a -> Expected -> Parser a Source #
Precise cut: we propagate at most a single expected thing.
testParser :: Show a => Parser a -> String -> IO () Source #
Run parser, print pretty error on failure.
lineComment :: Parser () Source #
Parse a line comment.
multilineComment :: Parser () Source #
Parse a potentially nested multiline comment.
identStartChar :: Parser Char Source #
Read a starting character of an identifier.