flatparse-0.3.5.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

Msg String

An error message.

Lit String

A literal expected thing.

data Error Source #

A parsing error.

Constructors

Precise Pos Expected

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

Imprecise Pos [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

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

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.

cut' :: Parser a -> Expected -> Parser a Source #

Precise cut: we propagate at most a single error.

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.

symbol' :: String -> Q Exp Source #

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

keyword :: String -> Q Exp Source #

Parse a keyword string.

keyword' :: String -> Q Exp Source #

Parse a keyword string, throw precise error on failure.