Skip to content

Commit

Permalink
conduit 1.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Mar 27, 2014
1 parent 1dad547 commit aa154a5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
11 changes: 6 additions & 5 deletions Data/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Data/Yaml/Builder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions Data/Yaml/Parser.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE OverloadedStrings #-}
-- | NOTE: This module is a highly experimental preview release. It may change
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions yaml.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yaml
version: 0.8.8
version: 0.8.8.1
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>, Anton Ageev <antage@gmail.com>,Kirill Simonov
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa154a5

Please sign in to comment.