Safe Haskell | None |
---|
This module allows you to run Attoparsec parsers on input flowing downstream through Pipes streams, possibly interleaving other stream effects.
This module builds on top of the pipes-parse
package and assumes
you have read Control.Proxy.Parse.Tutorial.
- parse :: (ParserInput a, Monad m, Proxy p) => Parser a r -> EitherP ParsingError (StateP [a] p) () (Maybe a) y' y m r
- parseD :: (ParserInput a, Monad m, Proxy p) => Parser a b -> () -> Pipe (EitherP ParsingError (StateP [a] p)) (Maybe a) b m ()
- isEndOfParserInput :: (ParserInput a, Monad m, Proxy p) => StateP [a] p () (Maybe a) y' y m Bool
- class Monoid a => ParserInput a where
- data ParsingError = ParsingError {
- peContexts :: [String]
- peMessage :: String
Parsing
There are two basic parsing facilities exported by this module, and choosing
between them is easy: If you need to interleave Attoparsec parsing with other
stream effects you must use parse
, otherwise you may use the simpler
parseD
.
These proxies use the EitherP
proxy transformer to report parsing errors,
you might use any of the facilities exported by Control.Proxy.Trans.Either
to recover from them.
:: (ParserInput a, Monad m, Proxy p) | |
=> Parser a r | Attoparsec parser to run on the input stream. |
-> EitherP ParsingError (StateP [a] p) () (Maybe a) y' y m r | Proxy compatible with the facilities provided by Control.Proxy.Parse. |
Parses one element flowing downstream.
- In case of parsing errors, a
ParsingError
exception is thrown in theEitherP
proxy transformer. - Requests more input from upstream using
draw
when needed. - Do not use this proxy if
isEndOfParserInput
returnsTrue
, otherwise you may get unexpected parsing errors.
Here is an example parsing loop that allows interleaving stream effects
together with parse
:
loop = do eof <- liftP isEndOfParserInput unless eof $ do -- 1. Possibly perform some stream effects here. -- 2. Parse one element from the stream. exampleElement <- parse myExampleParser -- 3. Do something with exampleElement and possibly perform -- some more stream effects. -- 4. Start all over again. loop
:: (ParserInput a, Monad m, Proxy p) | |
=> Parser a b | Attoparsec parser to run on the input stream. |
-> () | |
-> Pipe (EitherP ParsingError (StateP [a] p)) (Maybe a) b m () | Proxy compatible with the facilities provided by Control.Proxy.Parse. |
Parses consecutive elements flowing downstream until end of input.
- In case of parsing errors, a
ParsingError
exception is thrown in theEitherP
proxy transformer. - Requests more input from upstream using
draw
when needed. - Empty input chunks flowing downstream will be discarded.
isEndOfParserInput :: (ParserInput a, Monad m, Proxy p) => StateP [a] p () (Maybe a) y' y m BoolSource
Like isEndOfInput
, except it also consumes and discards leading
empty ParserInput
chunks.
Types
class Monoid a => ParserInput a whereSource
A class for valid Attoparsec input types: strict Text
and
strict ByteString
.
data ParsingError Source
A parsing error report, as provided by Attoparsec's Fail
.
ParsingError | |
|