Data.Conduit.Attoparsec

conduit-extra-1.1.16: Batteries included conduit: adapters for common libraries.

Copyright | 2011 Michael Snoyman 2010 John Millikin
License | MIT
Safe Haskell | None
Language | Haskell98

Data.Conduit.Attoparsec

Contents

- Sink
- Conduit
- Types
- Classes

Description

Consume attoparsec parsers via conduit.

This code was taken from attoparsec-enumerator and adapted for conduits.

Synopsis

- sinkParser :: (AttoparsecInput a, MonadThrow m) => Parser a b -> Consumer a m b
- sinkParserEither :: (AttoparsecInput a, Monad m) => Parser a b -> Consumer a m (Either ParseError b)
- conduitParser :: (AttoparsecInput a, MonadThrow m) => Parser a b -> Conduit a m (PositionRange, b)
- conduitParserEither :: (Monad m, AttoparsecInput a) => Parser a b -> Conduit a m (Either ParseError (PositionRange, b))
- data ParseError
  - = ParseError {
    - errorContexts :: [String]
    - errorMessage :: String
    - errorPosition :: Position
    }
  - | DivergentParser
- data Position = Position {
  - posLine :: !Int
  - posCol :: !Int
  }
- data PositionRange = PositionRange {
  - posRangeStart :: !Position
  - posRangeEnd :: !Position
  }
- class AttoparsecInput a

# Sink

sinkParser :: (AttoparsecInput a, MonadThrow m) => Parser a b -> Consumer a m b #

Convert an Attoparsec `Parser` into a `Sink`. The parser will be streamed bytes until it returns `Done` or `Fail`.

If parsing fails, a `ParseError` will be thrown with `monadThrow`.

Since 0.5.0

sinkParserEither :: (AttoparsecInput a, Monad m) => Parser a b -> Consumer a m (Either ParseError b) #

Same as `sinkParser`, but we return an `Either` type instead of raising an exception.

Since 1.1.5

# Conduit

conduitParser :: (AttoparsecInput a, MonadThrow m) => Parser a b -> Conduit a m (PositionRange, b) #

Consume a stream of parsed tokens, returning both the token and the position it appears at. This function will raise a `ParseError` on bad input.

Since 0.5.0

conduitParserEither :: (Monad m, AttoparsecInput a) => Parser a b -> Conduit a m (Either ParseError (PositionRange, b)) #

Same as `conduitParser`, but we return an `Either` type instead of raising an exception.

# Types

data ParseError #

The context and message from a `Fail` value.

Constructors

ParseError |
Fields errorContexts :: [String] errorMessage :: String errorPosition :: Position
DivergentParser |

Instances

Show ParseError # |
Methods showsPrec :: Int -> ParseError -> ShowS # show :: ParseError -> String # showList :: [ParseError] -> ShowS #
Exception ParseError # |
Methods toException :: ParseError -> SomeException # fromException :: SomeException -> Maybe ParseError # displayException :: ParseError -> String #

data Position #

Constructors

Position |
Fields posLine :: !Int posCol :: !Int

Instances

Eq Position # |
Methods (==) :: Position -> Position -> Bool # (/=) :: Position -> Position -> Bool #
Ord Position # |
Methods compare :: Position -> Position -> Ordering # (<) :: Position -> Position -> Bool # (<=) :: Position -> Position -> Bool # (>) :: Position -> Position -> Bool # (>=) :: Position -> Position -> Bool # max :: Position -> Position -> Position # min :: Position -> Position -> Position #
Show Position # |
Methods showsPrec :: Int -> Position -> ShowS # show :: Position -> String # showList :: [Position] -> ShowS #

data PositionRange #

Constructors

PositionRange |
Fields posRangeStart :: !Position posRangeEnd :: !Position

Instances

Eq PositionRange # |
Methods (==) :: PositionRange -> PositionRange -> Bool # (/=) :: PositionRange -> PositionRange -> Bool #
Ord PositionRange # |
Methods compare :: PositionRange -> PositionRange -> Ordering # (<) :: PositionRange -> PositionRange -> Bool # (<=) :: PositionRange -> PositionRange -> Bool # (>) :: PositionRange -> PositionRange -> Bool # (>=) :: PositionRange -> PositionRange -> Bool # max :: PositionRange -> PositionRange -> PositionRange # min :: PositionRange -> PositionRange -> PositionRange #
Show PositionRange # |
Methods showsPrec :: Int -> PositionRange -> ShowS # show :: PositionRange -> String # showList :: [PositionRange] -> ShowS #

# Classes

class AttoparsecInput a #

A class of types which may be consumed by an Attoparsec parser.

Minimal complete definition

parseA, feedA, empty, isNull, notEmpty, getLinesCols, stripFromEnd

Instances

AttoparsecInput ByteString # |
Methods parseA :: Parser ByteString b -> ByteString -> IResult ByteString b feedA :: IResult ByteString b -> ByteString -> IResult ByteString b empty :: ByteString isNull :: ByteString -> Bool notEmpty :: [ByteString] -> [ByteString] getLinesCols :: ByteString -> Position stripFromEnd :: ByteString -> ByteString -> ByteString
AttoparsecInput Text # |
Methods parseA :: Parser Text b -> Text -> IResult Text b feedA :: IResult Text b -> Text -> IResult Text b empty :: Text isNull :: Text -> Bool notEmpty :: [Text] -> [Text] getLinesCols :: Text -> Position stripFromEnd :: Text -> Text -> Text