flatparse-0.1.0.1: High-performance parsing from strict bytestrings
Safe HaskellNone
LanguageHaskell2010

FlatParse.Examples.BasicLambda.Lexer

Description

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

Documentation

data Expected Source #

An expected item which is displayed in error messages.

Constructors

Lit String

An expected literal string.

Msg String

A description of what's expected.

data Error' Source #

A parsing error, without source position.

Constructors

Precise Expected

A precisely known error, like leaving out "in" from "let".

Imprecise [Expected]

An imprecise error, when we expect a number of different things, but parse something else.

Instances

Instances details
Show Error' Source # 
Instance details

Defined in FlatParse.Examples.BasicLambda.Lexer

data Error Source #

A source-annotated error.

Constructors

Error !Pos !Error' 

Instances

Instances details
Show Error Source # 
Instance details

Defined in FlatParse.Examples.BasicLambda.Lexer

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

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.

ws :: Parser () Source #

Consume whitespace.

token :: Parser a -> Parser a Source #

Consume whitespace after running a parser.

identStartChar :: Parser Char Source #

Read a starting character of an identifier.

identChar :: Parser Char Source #

Read a non-starting character of an identifier.

isKeyword :: Span -> Parser () Source #

Check whether a Span contains exactly a keyword. Does not change parsing state.

symbol :: String -> Q Exp Source #

Parse a non-keyword string.

cutSymbol :: String -> Q Exp Source #

Parser a non-keyword string, throw precise error on failure.

keyword :: String -> Q Exp Source #

Parse a keyword string.

cutKeyword :: String -> Q Exp Source #

Parse a keyword string, throw precise error on failure.