Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CPP MIN_VERSION_* checks #109

Merged
merged 2 commits into from Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Data/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Data/Yaml/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions Data/Yaml/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..))
Expand Down Expand Up @@ -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
41 changes: 4 additions & 37 deletions Text/Libyaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down