on master help sign in
conduit 1.0
commitdee4776d27863b32d4a70c7f23d732426ccafb84 authorMichael Snoyman <michael@snoyman.com> dateSun 10 Feb 2013, 18:15 (14 years ago) parentf3436f3
2 files changed+55−5
Text/Libyaml.hs+54−4 yaml.cabal+1−1
Text/Libyaml.hs+54−4
@@ -8,6 +8,7 @@
88{-# LANGUAGE GeneralizedNewtypeDeriving #-}
99{-# LANGUAGE RankNTypes #-}
1010{-# LANGUAGE CPP #-}
11+{-# LANGUAGE TypeFamilies #-}
1112
1213-- | Low-level, streaming YAML interface. For a higher-level interface, see
1314-- "Data.Yaml".
@@ -464,7 +465,12 @@ newtype ToEventRawException = ToEventRawException CInt
464465 deriving (Show, Typeable)
465466instance Exception ToEventRawException
466467
467−decode :: MonadResource m => B.ByteString -> GSource m Event
468+decode :: MonadResource m => B.ByteString
469+#if MIN_VERSION_conduit(1, 0, 0)
470+ -> MonadSource m Event
471+#else
472+ -> GSource m Event
473+#endif
468474decode bs | B8.null bs = return ()
469475decode bs =
470476 bracketP alloc cleanup (runParser . fst)
@@ -488,7 +494,12 @@ decode bs =
488494 c_yaml_parser_delete ptr
489495 free ptr
490496
491−decodeFile :: MonadResource m => FilePath -> GSource m Event
497+decodeFile :: MonadResource m => FilePath
498+#if MIN_VERSION_conduit(1, 0, 0)
499+ -> MonadSource m Event
500+#else
501+ -> GSource m Event
502+#endif
492503decodeFile file =
493504 bracketP alloc cleanup (runParser . fst)
494505 where
@@ -519,11 +530,24 @@ decodeFile file =
519530 c_yaml_parser_delete ptr
520531 free ptr
521532
522−runParser :: MonadResource m => Parser -> GSource m Event
533+runParser :: MonadResource m => Parser
534+#if MIN_VERSION_conduit(1, 0, 0)
535+ -> MonadSource m Event
536+#else
537+ -> GSource m Event
538+#endif
523539runParser parser = do
540+#if MIN_VERSION_conduit(1, 0, 0)
541+ e <- liftStreamIO $ parserParseOne' parser
542+#else
524543 e <- liftIO $ parserParseOne' parser
544+#endif
525545 case e of
546+#if MIN_VERSION_conduit(1, 0, 0)
547+ Left err -> liftStreamIO $ throwIO err
548+#else
526549 Left err -> liftIO $ throwIO err
550+#endif
527551 Right Nothing -> return ()
528552 Right (Just ev) -> yield ev >> runParser parser
529553
@@ -543,7 +567,12 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
543567 return $ Left $ YamlParseException problem context problemMark
544568 else Right <$> getEvent er
545569
546−encode :: MonadResource m => GSink Event m ByteString
570+encode :: MonadResource m
571+#if MIN_VERSION_conduit(1, 0, 0)
572+ => MonadSink Event m ByteString
573+#else
574+ => GSink Event m ByteString
575+#endif
547576encode =
548577 runEmitter alloc close
549578 where
@@ -560,7 +589,11 @@ encode =
560589
561590encodeFile :: MonadResource m
562591 => FilePath
592+#if MIN_VERSION_conduit(1, 0, 0)
593+ -> MonadSink Event m ()
594+#else
563595 -> GInfSink Event m
596+#endif
564597encodeFile filePath =
565598 bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u)
566599 where
@@ -576,8 +609,13 @@ encodeFile filePath =
576609
577610runEmitter :: MonadResource m
578611 => (Emitter -> IO a) -- ^ alloc
612+#if MIN_VERSION_conduit(1, 0, 0)
613+ -> (() -> a -> IO b) -- ^ close
614+ -> MonadSink Event m b
615+#else
579616 -> (u -> a -> IO b) -- ^ close
580617 -> Pipe l Event o u m b
618+#endif
581619runEmitter allocI closeI =
582620 bracketP alloc cleanup go
583621 where
@@ -594,11 +632,23 @@ runEmitter allocI closeI =
594632 go (emitter, a) =
595633 loop
596634 where
635+#if MIN_VERSION_conduit(1, 0, 0)
636+ loop = await >>= maybe (close ()) push
637+#else
597638 loop = awaitE >>= either close push
639+#endif
640+
641+#if MIN_VERSION_conduit(1, 0, 0)
642+ push e = do
643+ _ <- liftStreamIO $ toEventRaw e $ c_yaml_emitter_emit emitter
644+ loop
645+ close u = liftStreamIO $ closeI u a
646+#else
598647 push e = do
599648 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
600649 loop
601650 close u = liftIO $ closeI u a
651+#endif
602652
603653-- | The pointer position
604654data YamlMark = YamlMark { yamlIndex :: Int, yamlLine :: Int, yamlColumn :: Int }
yaml.cabal+1−1
@@ -36,7 +36,7 @@ library
3636 build-depends: base >= 4 && < 5
3737 , transformers >= 0.1 && < 0.4
3838 , bytestring >= 0.9.1.4
39− , conduit >= 0.5 && < 0.6
39+ , conduit >= 0.5 && < 1.1
4040 , resourcet >= 0.3 && < 0.5
4141 , aeson >= 0.5
4242 , containers