Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Lower-level flatparse parsers
Synopsis
- runParserMaybe :: Parser e a -> ByteString -> Maybe a
- runParserEither :: Parser Error a -> ByteString -> Either ByteString a
- testParser :: Show a => Parser Error a -> String -> IO ()
- data Expected
- data Error
- prettyError :: ByteString -> Error -> String
- cut :: Parser Error a -> [Expected] -> Parser Error a
- cut' :: Parser Error a -> Expected -> Parser Error a
- ws :: Parser e Char
- ws_ :: Parser e ()
- wss :: Parser e ByteString
- sep :: Parser e s -> Parser e a -> Parser e [a]
- bracketed :: Parser e b -> Parser e b -> Parser e a -> Parser e a
- wrapped :: Parser e () -> Parser e a -> Parser e a
- digit :: Parser e Int
- int :: Parser e Int
- double :: Parser e Double
- signed :: Num b => Parser e b -> Parser e b
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.
An expected item which is displayed in error messages.
A parsing error.
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.
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" ""