pipes-attoparsec-0.6.0: Attoparsec and Pipes integration.

Safe Haskell | Safe-Inferred
Language | Haskell2010

Pipes.Attoparsec

Contents

- Parsing
  - Including input length
- Utils
- Types

Description

`pipes` utilities for incrementally running `attoparsec`-based parsers.

This module assumes familiarity with `pipes-parse`, you can learn about it in Pipes.Parse.Tutorial.

Synopsis

- parse :: (Monad m, ParserInput a) => Parser a b -> Parser a m (Maybe (Either ParsingError b))
- parsed :: (Monad m, ParserInput a) => Parser a b -> Producer a m r -> Producer b m (Either (ParsingError, Producer a m r) r)
- parseL :: (Monad m, ParserInput a) => Parser a b -> Parser a m (Maybe (Either ParsingError (Int, b)))
- parsedL :: (Monad m, ParserInput a) => Parser a b -> Producer a m r -> Producer (Int, b) m (Either (ParsingError, Producer a m r) r)
- isEndOfParserInput :: (Monad m, ParserInput a) => Parser a m Bool
- class (Eq a, Monoid a) => ParserInput a
- data ParsingError = ParsingError {
  - peContexts :: [String]
  - peMessage :: String
  }

# Parsing

parse Source #

Arguments

:: (Monad m, ParserInput a) |
=> Parser a b | Attoparsec parser
-> Parser a m (Maybe (Either ParsingError b)) | Pipes parser

Convert an `attoparsec` `Parser` to a `pipes-parse` `Parser`.

This `Parser` is compatible with the tools from Pipes.Parse.

It returns `Nothing` if the underlying `Producer` is exhausted, otherwise it attempts to run the given attoparsec `Parser` on the underlying `Producer`, possibly failing with `ParsingError`.

parsed Source #

Arguments

:: (Monad m, ParserInput a) |
=> Parser a b | Attoparsec parser
-> Producer a m r | Raw input
-> Producer b m (Either (ParsingError, Producer a m r) r) |

Convert a producer of `ParserInput` to a producer of parsed values.

This producer returns `Right` when end-of-input is reached successfully, otherwise it returns a `ParsingError` and the leftovers including the malformed input that couldn't be parsed. You can use `errorP` to promote the `Either` return value to an `ErrorT` monad transformer.

## Including input length

Like the functions above, but these also provide information about the length of input consumed in order to fully parse each value.

parseL Source #

Arguments

:: (Monad m, ParserInput a) |
=> Parser a b | Attoparsec parser
-> Parser a m (Maybe (Either ParsingError (Int, b))) | Pipes parser

Like `parse`, but also returns the length of input consumed to parse the value.

parsedL Source #

Arguments

:: (Monad m, ParserInput a) |
=> Parser a b | Attoparsec parser
-> Producer a m r | Raw input
-> Producer (Int, b) m (Either (ParsingError, Producer a m r) r) |

Like `parsed`, except this tags each parsed value with the length of input consumed to parse the value.

# Utils

isEndOfParserInput :: (Monad m, ParserInput a) => Parser a m Bool Source #

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

# Types

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

A class for valid `attoparsec` input types

Minimal complete definition

_parse, _length

#### Instances

Instances details

ParserInput ByteString Source # | Strict `ByteString`.
Instance details Defined in Pipes.Attoparsec Methods _parse :: Parser ByteString b -> ByteString -> IResult ByteString b _length :: ByteString -> Int
ParserInput Text Source # | Strict `Text`.
Instance details Defined in Pipes.Attoparsec Methods _parse :: Parser Text b -> Text -> IResult Text b _length :: Text -> Int

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.

#### Instances

Instances details

Data ParsingError Source # |

Instance details

Defined in Pipes.Attoparsec

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ParsingError -> c ParsingError Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ParsingError Source #

toConstr :: ParsingError -> Constr Source #

dataTypeOf :: ParsingError -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ParsingError) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ParsingError) Source #

gmapT :: (forall b. Data b => b -> b) -> ParsingError -> ParsingError Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ParsingError -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ParsingError -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ParsingError -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ParsingError -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ParsingError -> m ParsingError Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ParsingError -> m ParsingError Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ParsingError -> m ParsingError Source #

Exception ParsingError Source # |
Instance details Defined in Pipes.Attoparsec Methods toException :: ParsingError -> SomeException Source # fromException :: SomeException -> Maybe ParsingError Source # displayException :: ParsingError -> String Source #
Read ParsingError Source # |
Instance details Defined in Pipes.Attoparsec Methods readsPrec :: Int -> ReadS ParsingError Source # readList :: ReadS [ParsingError] Source # readPrec :: ReadPrec ParsingError Source # readListPrec :: ReadPrec [ParsingError] Source #
Show ParsingError Source # |
Instance details Defined in Pipes.Attoparsec Methods showsPrec :: Int -> ParsingError -> ShowS Source # show :: ParsingError -> String Source # showList :: [ParsingError] -> ShowS Source #
Eq ParsingError Source # |
Instance details Defined in Pipes.Attoparsec Methods (==) :: ParsingError -> ParsingError -> Bool Source # (/=) :: ParsingError -> ParsingError -> Bool Source #