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
- errorPos :: Error -> Pos
- 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
- symbol' :: String -> Q Exp
- keyword :: String -> Q Exp
- keyword' :: String -> Q Exp
Documentation
An expected item which is displayed in error messages.
A parsing error.
merge :: Error -> Error -> Error Source #
Merge two errors. Inner errors (which were thrown at points with more consumed inputs) are preferred. If errors are thrown at identical input positions, we prefer precise errors to imprecise ones.
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 items on inner errors.
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.