pipes-attoparsec-0.3.1: Attoparsec and Pipes integration.

Safe HaskellNone

Pipes.Attoparsec

Contents

Description

The utilities in this module allow you to run Attoparsec parsers on input flowing downstream through pipes, possibly interleaving other stream effects while doing so.

This module builds on top of the attoparsec, pipes and pipes-parse libraries and assumes you understand how to use those.

Synopsis

Parsing

parseSource

Arguments

:: (Monad m, ParserInput a) 
=> Parser a b

Attoparsec parser.

-> StateT (Producer a m r) m (Either ParsingError (Int, b)) 

Run an Attoparsec Parser on input from the underlying Producer, returning either a ParsingError on failure, or a pair with the parsed entity together with the length of input consumed in order to produce it.

Use this function only if isEndOfParserInput returns False, otherwise you'll get unexpected parsing errors.

parseManySource

Arguments

:: (Monad m, ParserInput a) 
=> Parser a b

Attoparsec parser.

-> Producer a m r

Producer from which to draw input.

-> Producer' (Int, b) m (Either (ParsingError, Producer a m r) r) 

Continuously run an Attoparsec Parser on input from the given Producer, sending downstream pairs of each successfully parsed entity together with the length of input consumed in order to produce it.

This Producer runs until it either runs out of input or a parsing failure occurs, in which case it returns Left with a ParsingError and a Producer with any leftovers. You can use errorP to turn the Either return value into an ErrorT monad transformer.

isEndOfParserInput :: (ParserInput a, Monad m) => StateT (Producer a m r) m BoolSource

Like isEndOfInput, except it also consumes and discards leading empty ParserInput chunks.

Types

class (Eq a, Monoid a) => ParserInput a Source

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.

Constructors

ParsingError 

Fields

peContexts :: [String]

Contexts where the parsing error occurred.

peMessage :: String

Parsing error description message.