diff --git a/Data/Yaml.hs b/Data/Yaml.hs index 3c5f234..f1851f8 100644 --- a/Data/Yaml.hs +++ b/Data/Yaml.hs @@ -78,7 +78,11 @@ import Data.Aeson , Object, Array , withObject, withText, withArray, withScientific, withBool ) +#if MIN_VERSION_aeson(1,0,0) +import Data.Aeson.Text (encodeToTextBuilder) +#else import Data.Aeson.Encode (encodeToTextBuilder) +#endif import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser) import Data.ByteString (ByteString) import qualified Data.Conduit as C diff --git a/Data/Yaml/Builder.hs b/Data/Yaml/Builder.hs index 1305baf..db18ed7 100644 --- a/Data/Yaml/Builder.hs +++ b/Data/Yaml/Builder.hs @@ -22,7 +22,11 @@ import Prelude hiding (null) import Control.Arrow (second) import Control.Monad.Trans.Resource (runResourceT) +#if MIN_VERSION_aeson(1,0,0) +import Data.Aeson.Text (encodeToTextBuilder) +#else import Data.Aeson.Encode (encodeToTextBuilder) +#endif import Data.Aeson.Types (Value(..)) import Data.ByteString (ByteString) import qualified Data.ByteString.Char8 as S8 diff --git a/Data/Yaml/Parser.hs b/Data/Yaml/Parser.hs index 86d0821..2b9ee23 100644 --- a/Data/Yaml/Parser.hs +++ b/Data/Yaml/Parser.hs @@ -13,12 +13,7 @@ import Control.Monad.Trans.Resource (MonadThrow, monadThrow, runResourceT) import Control.Monad.Trans.Writer.Strict (tell, WriterT) import Data.ByteString (ByteString) 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 qualified Data.Map as Map #if !MIN_VERSION_base(4,8,0) import Data.Monoid (Monoid (..)) @@ -193,7 +188,7 @@ sinkValue = Just e -> monadThrow $ UnexpectedEvent e sinkRawDoc :: MonadThrow m => Consumer Event m RawDoc -sinkRawDoc = uncurry RawDoc <$> runWriterSC sinkValue +sinkRawDoc = uncurry RawDoc <$> runWriterC sinkValue readYamlFile :: FromYaml a => FilePath -> IO a readYamlFile fp = runResourceT (decodeFile fp $$ sinkRawDoc) >>= parseRawDoc diff --git a/Text/Libyaml.hs b/Text/Libyaml.hs index 7ed538e..ed9e05d 100644 --- a/Text/Libyaml.hs +++ b/Text/Libyaml.hs @@ -479,12 +479,7 @@ newtype ToEventRawException = ToEventRawException CInt deriving (Show, Typeable) instance Exception ToEventRawException -decode :: MonadResource m => B.ByteString -#if MIN_VERSION_conduit(1, 0, 0) - -> Producer m Event -#else - -> GSource m Event -#endif +decode :: MonadResource m => B.ByteString -> Producer m Event decode bs | B8.null bs = return () decode bs = bracketP alloc cleanup (runParser . fst) @@ -526,12 +521,7 @@ openFile file rawOpenFlags openMode = do then withCString openMode $ \openMode' -> c_fdopen fd openMode' else return nullPtr -decodeFile :: MonadResource m => FilePath -#if MIN_VERSION_conduit(1, 0, 0) - -> Producer m Event -#else - -> GSource m Event -#endif +decodeFile :: MonadResource m => FilePath -> Producer m Event decodeFile file = bracketP alloc cleanup (runParser . fst) where @@ -559,12 +549,7 @@ decodeFile file = c_yaml_parser_delete ptr free ptr -runParser :: MonadResource m => Parser -#if MIN_VERSION_conduit(1, 0, 0) - -> Producer m Event -#else - -> GSource m Event -#endif +runParser :: MonadResource m => Parser -> Producer m Event runParser parser = do e <- liftIO $ parserParseOne' parser case e of @@ -588,12 +573,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do return $ Left $ YamlParseException problem context problemMark else Right <$> getEvent er -encode :: MonadResource m -#if MIN_VERSION_conduit(1, 0, 0) - => Consumer Event m ByteString -#else - => GSink Event m ByteString -#endif +encode :: MonadResource m => Consumer Event m ByteString encode = runEmitter alloc close where @@ -610,11 +590,7 @@ encode = encodeFile :: MonadResource m => FilePath -#if MIN_VERSION_conduit(1, 0, 0) -> Consumer Event m () -#else - -> GInfSink Event m -#endif encodeFile filePath = bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u) where @@ -628,13 +604,8 @@ encodeFile filePath = runEmitter :: MonadResource m => (Emitter -> IO a) -- ^ alloc -#if MIN_VERSION_conduit(1, 0, 0) -> (() -> a -> IO b) -- ^ close -> Consumer Event m b -#else - -> (u -> a -> IO b) -- ^ close - -> Pipe l Event o u m b -#endif runEmitter allocI closeI = bracketP alloc cleanup go where @@ -654,11 +625,7 @@ runEmitter allocI closeI = go (emitter, a) = loop where -#if MIN_VERSION_conduit(1, 0, 0) loop = await >>= maybe (close ()) push -#else - loop = awaitE >>= either close push -#endif push e = do _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter