conduit-parse-0.1.2.2: Parsing framework based on conduit.

Safe HaskellNone
LanguageHaskell2010

Data.Conduit.Parser

Contents

Description

This module introduces ConduitParser, a wrapper around Sink that behaves like a parser.

You probably want to import the Text.Parser.Combinators module together with this module.

Synopsis

Conduit parser monad

newtype ConduitParser i m a Source #

Core type of the package. This is basically a Sink with a parsing state.

Constructors

ConduitParser (ExceptT ConduitParserException (StateT ([Text], Buffer i) (Sink i m)) a) 

Instances

MonadError ConduitParserException (ConduitParser i m) Source #

Backtracking is supported by pushing back consumed elements (using leftover) whenever an error is catched.

As a consequence, within the scope of a catchError, all streamed items are kept in memory, which means the consumer no longer uses constant memory.

MonadTrans (ConduitParser i) Source # 

Methods

lift :: Monad m => m a -> ConduitParser i m a #

Monad (ConduitParser i m) Source # 

Methods

(>>=) :: ConduitParser i m a -> (a -> ConduitParser i m b) -> ConduitParser i m b #

(>>) :: ConduitParser i m a -> ConduitParser i m b -> ConduitParser i m b #

return :: a -> ConduitParser i m a #

fail :: String -> ConduitParser i m a #

Functor (ConduitParser i m) Source # 

Methods

fmap :: (a -> b) -> ConduitParser i m a -> ConduitParser i m b #

(<$) :: a -> ConduitParser i m b -> ConduitParser i m a #

Applicative (ConduitParser i m) Source # 

Methods

pure :: a -> ConduitParser i m a #

(<*>) :: ConduitParser i m (a -> b) -> ConduitParser i m a -> ConduitParser i m b #

(*>) :: ConduitParser i m a -> ConduitParser i m b -> ConduitParser i m b #

(<*) :: ConduitParser i m a -> ConduitParser i m b -> ConduitParser i m a #

Alternative (ConduitParser i m) Source #

Parsers can be combined with (<|>), some, many, optional, choice.

The use of guard is not recommended as it generates unhelpful error messages. Please consider using throwError or unexpected instead.

Methods

empty :: ConduitParser i m a #

(<|>) :: ConduitParser i m a -> ConduitParser i m a -> ConduitParser i m a #

some :: ConduitParser i m a -> ConduitParser i m [a] #

many :: ConduitParser i m a -> ConduitParser i m [a] #

MonadIO m => MonadIO (ConduitParser i m) Source # 

Methods

liftIO :: IO a -> ConduitParser i m a #

MonadThrow m => MonadThrow (ConduitParser i m) Source # 

Methods

throwM :: Exception e => e -> ConduitParser i m a #

MonadCatch m => MonadCatch (ConduitParser i m) Source # 

Methods

catch :: Exception e => ConduitParser i m a -> (e -> ConduitParser i m a) -> ConduitParser i m a #

Monad m => CharParsing (ConduitParser Char m) Source # 
Monad m => Parsing (ConduitParser i m) Source #

Parsing combinators can be used with ConduitParsers.

runConduitParser :: MonadThrow m => ConduitParser i m a -> Sink i m a Source #

Run a ConduitParser. Any parsing failure will be thrown as an exception.

named :: Monad m => Text -> ConduitParser i m a -> ConduitParser i m a Source #

Flipped version of (<?>).

Primitives

await :: Monad m => ConduitParser i m i Source #

await wrapped as a ConduitParser.

If no data is available, UnexpectedEndOfInput is thrown.

anyOne :: Monad m => ConduitParser i m i Source #

Synonym for await

leftover :: i -> ConduitParser i m () Source #

leftover wrapped as a ConduitParser.

getParserNames :: ConduitParser i m [Text] Source #

Return the ordered list of names (assigned through (<?>)) for the current parser stack. First element is the most nested parser.

getParserName :: ConduitParser i m Text Source #

Return the name (assigned through (<?>)) of the current parser (most nested), or mempty if it has none.

Utility

peek :: Monad m => ConduitParser i m (Maybe i) Source #

peek wrapped as a ConduitParser.

Exception

Utilities

parseC :: MonadThrow m => ConduitParser i m a -> Conduit i m a Source #

Turn a parser into a regular Conduit that yields parsed items as long as the parser succeeds. Once the parser fails, the conduit stops consuming input and won't yield any more.

lastDef :: MonadThrow m => a -> Consumer a m a Source #

embed :: MonadCatch m => Sink i m a -> ConduitParser i m a Source #