From aa154a5c4b67a1d1952044d310cf5557d571b117 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 27 Mar 2014 16:05:28 +0200 Subject: [PATCH] conduit 1.1 support --- Data/Yaml.hs | 11 ++++++----- Data/Yaml/Builder.hs | 1 + Data/Yaml/Parser.hs | 7 +++++++ yaml.cabal | 6 +++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Data/Yaml.hs b/Data/Yaml.hs index fc0441f..5912be4 100644 --- a/Data/Yaml.hs +++ b/Data/Yaml.hs @@ -91,14 +91,15 @@ import Data.Scientific (fromFloatDigits) #else import Data.Attoparsec.Number #endif +import Control.Monad.Trans.Resource (ResourceT, runResourceT) encode :: ToJSON a => a -> ByteString encode obj = unsafePerformIO $ - C.runResourceT $ CL.sourceList (objToEvents $ toJSON obj) + runResourceT $ CL.sourceList (objToEvents $ toJSON obj) C.$$ Y.encode encodeFile :: ToJSON a => FilePath -> a -> IO () -encodeFile fp obj = C.runResourceT +encodeFile fp obj = runResourceT $ CL.sourceList (objToEvents $ toJSON obj) C.$$ Y.encodeFile fp @@ -187,7 +188,7 @@ instance MonadTrans PErrorT where instance MonadIO m => MonadIO (PErrorT m) where liftIO = lift . liftIO -type Parse = StateT (Map.Map String Value) (C.ResourceT IO) +type Parse = StateT (Map.Map String Value) (ResourceT IO) requireEvent :: Event -> C.Sink Event Parse () requireEvent e = do @@ -320,7 +321,7 @@ decodeFileEither => FilePath -> IO (Either ParseException a) decodeFileEither fp = do - x <- try $ C.runResourceT $ flip evalStateT Map.empty $ Y.decodeFile fp C.$$ parse + x <- try $ runResourceT $ flip evalStateT Map.empty $ Y.decodeFile fp C.$$ parse case x of Left e | Just pe <- fromException e -> return $ Left pe @@ -356,7 +357,7 @@ decodeHelper :: FromJSON a => C.Source Parse Y.Event -> IO (Either ParseException (Either String a)) decodeHelper src = do - x <- try $ C.runResourceT $ flip evalStateT Map.empty $ src C.$$ parse + x <- try $ runResourceT $ flip evalStateT Map.empty $ src C.$$ parse case x of Left e | Just pe <- fromException e -> return $ Left pe diff --git a/Data/Yaml/Builder.hs b/Data/Yaml/Builder.hs index 298e8cc..49e1f46 100644 --- a/Data/Yaml/Builder.hs +++ b/Data/Yaml/Builder.hs @@ -22,6 +22,7 @@ import qualified Data.Conduit.List as CL import System.IO.Unsafe (unsafePerformIO) import Control.Arrow (second) import qualified Data.ByteString.Char8 as S8 +import Control.Monad.Trans.Resource (runResourceT) (.=) :: ToYaml a => Text -> a -> (Text, YamlBuilder) k .= v = (k, toYaml v) diff --git a/Data/Yaml/Parser.hs b/Data/Yaml/Parser.hs index e6842b4..75dd55a 100644 --- a/Data/Yaml/Parser.hs +++ b/Data/Yaml/Parser.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE OverloadedStrings #-} -- | NOTE: This module is a highly experimental preview release. It may change @@ -10,9 +11,15 @@ import Data.Monoid (Monoid (..)) import Control.Monad (MonadPlus (..), liftM, ap) import Control.Monad.Trans.Writer.Strict (tell, WriterT) import Control.Monad.Trans.Class (lift) +import Control.Monad.Trans.Resource (MonadThrow, monadThrow, runResourceT) import qualified Data.Map as Map import Data.Conduit +#if MIN_VERSION_conduit(1,1,0) +import Data.Conduit.Lift (runWriterC) +#define runWriterSC runWriterC +#else import Data.Conduit.Lift (runWriterSC) +#endif import Data.Text (Text, pack, unpack) import Data.Text.Encoding (decodeUtf8) import Data.ByteString (ByteString) diff --git a/yaml.cabal b/yaml.cabal index 86f5262..ae6d787 100644 --- a/yaml.cabal +++ b/yaml.cabal @@ -1,5 +1,5 @@ name: yaml -version: 0.8.8 +version: 0.8.8.1 license: BSD3 license-file: LICENSE author: Michael Snoyman , Anton Ageev ,Kirill Simonov @@ -41,8 +41,8 @@ library build-depends: base >= 4 && < 5 , transformers >= 0.1 && < 0.4 , bytestring >= 0.9.1.4 - , conduit >= 1.0.11 && < 1.1 - , resourcet >= 0.3 && < 0.5 + , conduit >= 1.0.11 && < 1.2 + , resourcet >= 0.3 && < 1.2 , aeson >= 0.5 , containers , unordered-containers