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

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

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 :: forall a (m :: Type -> Type) b o. (AttoparsecInput a, MonadThrow m) => Parser a b -> ConduitT a o m b
- sinkParserEither :: forall a (m :: Type -> Type) b o. (AttoparsecInput a, Monad m) => Parser a b -> ConduitT a o m (Either ParseError b)
- conduitParser :: forall a (m :: Type -> Type) b. (AttoparsecInput a, MonadThrow m) => Parser a b -> ConduitT a (PositionRange, b) m ()
- conduitParserEither :: forall (m :: Type -> Type) a b. (Monad m, AttoparsecInput a) => Parser a b -> ConduitT a (Either ParseError (PositionRange, b)) m ()
- data ParseError
  - = ParseError {
    - errorContexts :: [String]
    - errorMessage :: String
    - errorPosition :: Position
    }
  - | DivergentParser
- data Position = Position {
  - posLine :: !Int
  - posCol :: !Int
  - posOffset :: !Int
  }
- data PositionRange = PositionRange {
  - posRangeStart :: !Position
  - posRangeEnd :: !Position
  }
- class AttoparsecInput a

# Sink

sinkParser :: forall a (m :: Type -> Type) b o. (AttoparsecInput a, MonadThrow m) => Parser a b -> ConduitT a o m b Source #

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 `throwM`.

Since 0.5.0

sinkParserEither :: forall a (m :: Type -> Type) b o. (AttoparsecInput a, Monad m) => Parser a b -> ConduitT a o m (Either ParseError b) Source #

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

Since 1.1.5

# Conduit

conduitParser :: forall a (m :: Type -> Type) b. (AttoparsecInput a, MonadThrow m) => Parser a b -> ConduitT a (PositionRange, b) m () Source #

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 :: forall (m :: Type -> Type) a b. (Monad m, AttoparsecInput a) => Parser a b -> ConduitT a (Either ParseError (PositionRange, b)) m () Source #

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

# Types

data ParseError Source #

The context and message from a `Fail` value.

Constructors

ParseError |

Fields

- errorContexts :: [String]
- errorMessage :: String
- errorPosition :: Position

DivergentParser |

#### Instances

Instances details

Exception ParseError Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods toException :: ParseError -> SomeException Source # fromException :: SomeException -> Maybe ParseError Source # displayException :: ParseError -> String Source # backtraceDesired :: ParseError -> Bool Source #
Show ParseError Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods showsPrec :: Int -> ParseError -> ShowS Source # show :: ParseError -> String Source # showList :: [ParseError] -> ShowS Source #

data Position Source #

Constructors

Position |

Fields

- posLine :: !Int
- posCol :: !Int
- posOffset :: !Int

  Since: 1.2.0

#### Instances

Instances details

Show Position Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods showsPrec :: Int -> Position -> ShowS Source # show :: Position -> String Source # showList :: [Position] -> ShowS Source #
Eq Position Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods (==) :: Position -> Position -> Bool Source # (/=) :: Position -> Position -> Bool Source #
Ord Position Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods compare :: Position -> Position -> Ordering Source # (<) :: Position -> Position -> Bool Source # (<=) :: Position -> Position -> Bool Source # (>) :: Position -> Position -> Bool Source # (>=) :: Position -> Position -> Bool Source # max :: Position -> Position -> Position Source # min :: Position -> Position -> Position Source #

data PositionRange Source #

Constructors

PositionRange |

Fields

- posRangeStart :: !Position
- posRangeEnd :: !Position

#### Instances

Instances details

Show PositionRange Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods showsPrec :: Int -> PositionRange -> ShowS Source # show :: PositionRange -> String Source # showList :: [PositionRange] -> ShowS Source #
Eq PositionRange Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods (==) :: PositionRange -> PositionRange -> Bool Source # (/=) :: PositionRange -> PositionRange -> Bool Source #
Ord PositionRange Source # |

Instance details

Defined in Data.Conduit.Attoparsec

Methods

compare :: PositionRange -> PositionRange -> Ordering Source #

(<) :: PositionRange -> PositionRange -> Bool Source #

(<=) :: PositionRange -> PositionRange -> Bool Source #

(>) :: PositionRange -> PositionRange -> Bool Source #

(>=) :: PositionRange -> PositionRange -> Bool Source #

max :: PositionRange -> PositionRange -> PositionRange Source #

min :: PositionRange -> PositionRange -> PositionRange Source #

# Classes

class AttoparsecInput a Source #

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

Minimal complete definition

parseA, feedA, empty, isNull, getLinesCols, stripFromEnd

#### Instances

Instances details

AttoparsecInput ByteString Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods parseA :: Parser ByteString b -> ByteString -> IResult ByteString b feedA :: IResult ByteString b -> ByteString -> IResult ByteString b empty :: ByteString isNull :: ByteString -> Bool getLinesCols :: ByteString -> Position stripFromEnd :: ByteString -> ByteString -> ByteString
AttoparsecInput Text Source # |
Instance details Defined in Data.Conduit.Attoparsec Methods parseA :: Parser Text b -> Text -> IResult Text b feedA :: IResult Text b -> Text -> IResult Text b empty :: Text isNull :: Text -> Bool getLinesCols :: Text -> Position stripFromEnd :: Text -> Text -> Text