chart-svg-0.4.0: Charting library targetting SVGs.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Chart.FlatParse

Description

Lower-level flatparse parsers

Synopsis

Documentation

runParserMaybe :: Parser e a -> ByteString -> Maybe a Source #

run a Parser, Nothing on failure

runParserEither :: Parser Error a -> ByteString -> Either ByteString a Source #

Run parser, Left error on failure.

testParser :: Show a => Parser Error a -> String -> IO () Source #

Run parser, print pretty error on failure.

data Expected Source #

An expected item which is displayed in error messages.

Constructors

Msg String

An error message.

Lit String

A literal expected thing.

Instances

Instances details
IsString Expected Source # 
Instance details

Defined in Chart.FlatParse

Show Expected Source # 
Instance details

Defined in Chart.FlatParse

Eq Expected Source # 
Instance details

Defined in Chart.FlatParse

Ord Expected Source # 
Instance details

Defined in Chart.FlatParse

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 Chart.FlatParse

Methods

showsPrec :: Int -> Error -> ShowS #

show :: Error -> String #

showList :: [Error] -> ShowS #

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 Error a -> [Expected] -> Parser Error a Source #

Imprecise cut: we slap a list of items on inner errors.

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

Precise cut: we propagate at most a single error.

ws :: Parser e Char Source #

single whitespace

>>> runParser ws " \nx"
OK ' ' "\nx"

ws_ :: Parser e () Source #

Consume whitespace.

>>> runParser ws_ " \nx"
OK () "x"
>>> runParser ws_ "x"
OK () "x"

wss :: Parser e ByteString Source #

multiple whitespace

>>> runParser wss " \nx"
OK " \n" "x"
>>> runParser wss "x"
Fail

sep :: Parser e s -> Parser e a -> Parser e [a] Source #

some with a separator

>>> runParser (sep ws (many (satisfy (/= ' ')))) "a b c"
OK ["a","b","c"] ""

bracketed :: Parser e b -> Parser e b -> Parser e a -> Parser e a Source #

parser bracketed by two other parsers

>>> runParser (bracketed ($(char '[')) ($(char ']')) (many (satisfy (/= ']')))) "[bracketed]"
OK "bracketed" ""

wrapped :: Parser e () -> Parser e a -> Parser e a Source #

parser wrapped by another parser

>>> runParser (wrapped ($(char '"')) (many (satisfy (/= '"')))) "\"wrapped\""
OK "wrapped" ""

digit :: Parser e Int Source #

A single digit

runParserMaybe digit "5" Just 5

int :: Parser e Int Source #

(unsigned) Int parser

runParserMaybe int "567" Just 567

double :: Parser e Double Source #

>>> runParser double "1.234x"
OK 1.234 "x"
>>> runParser double "."
Fail
>>> runParser double "123"
OK 123.0 ""
>>> runParser double ".123"
OK 0.123 ""
>>> runParser double "123."
OK 123.0 ""

signed :: Num b => Parser e b -> Parser e b Source #

>>> runParser (signed double) "-1.234x"
OK (-1.234) "x"