attoparsec-conduit 0.4.0 → 0.4.0.1
raw patch · 2 files changed
+27/−18 lines, 2 filesdep ~attoparsecdep ~basedep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: attoparsec, base, bytestring, conduit, text
API changes (from Hackage documentation)
Files
- Data/Conduit/Attoparsec.hs +26/−17
- attoparsec-conduit.cabal +1/−1
Data/Conduit/Attoparsec.hs view
@@ -18,6 +18,7 @@ import Data.Typeable (Typeable) import qualified Data.ByteString as B import qualified Data.Text as T+import Control.Monad.Trans.Class (lift) import qualified Data.Attoparsec.ByteString import qualified Data.Attoparsec.Text@@ -60,21 +61,29 @@ -- -- If parsing fails, a 'ParseError' will be thrown with 'C.monadThrow'. sinkParser :: (AttoparsecInput a, C.MonadThrow m) => A.Parser a b -> C.Sink a m b-sinkParser p0 = C.sinkState- (parseA p0)- push- close+sinkParser =+ sink . parseA where- push parser c | isNull c = return (C.StateProcessing parser)- push parser c =- case parser c of- A.Done leftover x ->- let lo = if isNull leftover then Nothing else Just leftover- in return (C.StateDone lo x)- A.Fail _ contexts msg -> C.monadThrow $ ParseError contexts msg- A.Partial p -> return (C.StateProcessing p)- close parser = do- case feedA (parser empty) empty of- A.Done _leftover y -> return y- A.Fail _ contexts msg -> C.monadThrow $ ParseError contexts msg- A.Partial _ -> C.monadThrow DivergentParser+ sink parser = C.NeedInput (push parser) (close parser)++ push parser c | isNull c = sink parser+ push parser c = go (parser c) sink++ close parser = go+ (feedA (parser empty) empty)+ (const $ C.PipeM exc $ lift exc)+ where+ exc = C.monadThrow DivergentParser++ go (A.Done leftover x) _ =+ C.Done lo x+ where+ lo+ | isNull leftover = Nothing+ | otherwise = Just leftover+ go (A.Fail _ contexts msg) _ =+ C.PipeM exc $ lift exc+ where+ exc = C.monadThrow $ ParseError contexts msg++ go (A.Partial parser') onPartial = onPartial parser'
attoparsec-conduit.cabal view
@@ -1,5 +1,5 @@ Name: attoparsec-conduit-Version: 0.4.0+Version: 0.4.0.1 Synopsis: Turn attoparsec parsers into sinks. Description: Turn attoparsec parsers into sinks. License: BSD3