on master help sign in
Clean up warnings
commitae4e1059aa8e7f941fd56d02fda03781ee633b3e authorMichael Snoyman <michael@snoyman.com> dateMon 15 Jan 2018, 15:00 (9 years ago) parent1bafb51
8 files changed+50−53
Data/Yaml.hs+7−8 Data/Yaml/Builder.hs+3−4 Data/Yaml/Include.hs+4−4 Data/Yaml/Internal.hs+11−11 Data/Yaml/Parser.hs+4−4 Text/Libyaml.hs+6−6 test/Data/YamlSpec.hs+14−15 yaml.cabal+1−1
Data/Yaml.hs+7−8
@@ -71,7 +71,6 @@ module Data.Yaml
7171import Control.Applicative((<$>))
7272#endif
7373import Control.Exception
74−import Control.Monad.Trans.Resource (runResourceT)
7574import Data.Aeson
7675 ( Value (..), ToJSON (..), FromJSON (..), object
7776 , (.=) , (.:) , (.:?) , (.!=)
@@ -85,7 +84,7 @@ import Data.Aeson.Encode (encodeToTextBuilder)
8584#endif
8685import Data.Aeson.Types (Pair, parseMaybe, parseEither, Parser)
8786import Data.ByteString (ByteString)
88−import qualified Data.Conduit as C
87+import Data.Conduit ((.|), runConduitRes)
8988import qualified Data.Conduit.List as CL
9089import qualified Data.HashMap.Strict as M
9190import qualified Data.HashSet as HashSet
@@ -101,14 +100,14 @@ import Text.Libyaml hiding (encode, decode, encodeFile, decodeFile)
101100import qualified Text.Libyaml as Y
102101
103102encode :: ToJSON a => a -> ByteString
104−encode obj = unsafePerformIO $
105− runResourceT $ CL.sourceList (objToEvents $ toJSON obj)
106− C.$$ Y.encode
103+encode obj = unsafePerformIO $ runConduitRes
104+ $ CL.sourceList (objToEvents $ toJSON obj)
105+ .| Y.encode
107106
108107encodeFile :: ToJSON a => FilePath -> a -> IO ()
109−encodeFile fp obj = runResourceT
110− $ CL.sourceList (objToEvents $ toJSON obj)
111− C.$$ Y.encodeFile fp
108+encodeFile fp obj = runConduitRes
109+ $ CL.sourceList (objToEvents $ toJSON obj)
110+ .| Y.encodeFile fp
112111
113112objToEvents :: Value -> [Y.Event]
114113objToEvents o = (:) EventStreamStart
Data/Yaml/Builder.hs+3−4
@@ -21,7 +21,6 @@ module Data.Yaml.Builder
2121import Prelude hiding (null)
2222
2323import Control.Arrow (second)
24−import Control.Monad.Trans.Resource (runResourceT)
2524#if MIN_VERSION_aeson(1,0,0)
2625import Data.Aeson.Text (encodeToTextBuilder)
2726#else
@@ -107,11 +106,11 @@ toEvents :: YamlBuilder -> [Event]
107106toEvents (YamlBuilder front) =
108107 EventStreamStart : EventDocumentStart : front [EventDocumentEnd, EventStreamEnd]
109108
110−toSource :: (Monad m, ToYaml a) => a -> Source m Event
109+toSource :: (Monad m, ToYaml a) => a -> ConduitM i Event m ()
111110toSource = mapM_ yield . toEvents . toYaml
112111
113112toByteString :: ToYaml a => a -> ByteString
114−toByteString yb = unsafePerformIO $ runResourceT $ toSource yb $$ encode
113+toByteString yb = unsafePerformIO $ runConduitRes $ toSource yb .| encode
115114
116115writeYamlFile :: ToYaml a => FilePath -> a -> IO ()
117−writeYamlFile fp yb = runResourceT $ toSource yb $$ encodeFile fp
116+writeYamlFile fp yb = runConduitRes $ toSource yb .| encodeFile fp
Data/Yaml/Include.hs+4−4
@@ -27,19 +27,19 @@ import qualified Text.Libyaml as Y
2727eventsFromFile
2828 :: MonadResource m
2929 => FilePath
30− -> Producer m Event
30+ -> ConduitM i Event m ()
3131eventsFromFile = go []
3232 where
33− go :: MonadResource m => [FilePath] -> FilePath -> Producer m Event
33+ go :: MonadResource m => [FilePath] -> FilePath -> ConduitM i Event m ()
3434 go seen fp = do
3535 cfp <- liftIO $ handleNotFound $ canonicalizePath fp
3636 when (cfp `elem` seen) $ do
3737 liftIO $ throwIO CyclicIncludes
38− Y.decodeFile cfp $= do
38+ Y.decodeFile cfp .| do
3939 awaitForever $ \event -> case event of
4040 EventScalar f (UriTag "!include") _ _ -> do
4141 let includeFile = takeDirectory cfp </> unpack (decodeUtf8 f)
42− go (cfp : seen) includeFile $= CL.filter (`notElem` irrelevantEvents)
42+ go (cfp : seen) includeFile .| CL.filter (`notElem` irrelevantEvents)
4343 _ -> yield event
4444
4545 irrelevantEvents = [EventStreamStart, EventDocumentStart, EventDocumentEnd, EventStreamEnd]
Data/Yaml/Internal.hs+11−11
@@ -27,7 +27,7 @@ import Data.Aeson.Types hiding (parse)
2727import qualified Data.Attoparsec.Text as Atto
2828import Data.ByteString (ByteString)
2929import Data.Char (toUpper)
30−import qualified Data.Conduit as C
30+import Data.Conduit ((.|), ConduitM, runConduit)
3131import qualified Data.Conduit.List as CL
3232import qualified Data.HashMap.Strict as M
3333import qualified Data.HashSet as HashSet
@@ -125,12 +125,12 @@ instance MonadIO m => MonadIO (PErrorT m) where
125125
126126type Parse = StateT (Map.Map String Value) (ResourceT IO)
127127
128−requireEvent :: Event -> C.Sink Event Parse ()
128+requireEvent :: Event -> ConduitM Event o Parse ()
129129requireEvent e = do
130130 f <- CL.head
131131 unless (f == Just e) $ liftIO $ throwIO $ UnexpectedEvent f $ Just e
132132
133−parse :: C.Sink Event Parse Value
133+parse :: ConduitM Event o Parse Value
134134parse = do
135135 streamStart <- CL.head
136136 case streamStart of
@@ -152,7 +152,7 @@ parse = do
152152 _ -> liftIO $ throwIO $ UnexpectedEvent streamStart Nothing
153153
154154parseScalar :: ByteString -> Anchor -> Style -> Tag
155− -> C.Sink Event Parse Text
155+ -> ConduitM Event o Parse Text
156156parseScalar v a style tag = do
157157 let res = decodeUtf8With lenientDecode v
158158 case a of
@@ -178,7 +178,7 @@ textToValue _ _ t
178178textToScientific :: Text -> Either String Scientific
179179textToScientific = Atto.parseOnly (Atto.scientific <* Atto.endOfInput)
180180
181−parseO :: C.Sink Event Parse Value
181+parseO :: ConduitM Event o Parse Value
182182parseO = do
183183 me <- CL.head
184184 case me of
@@ -194,7 +194,7 @@ parseO = do
194194
195195parseS :: Y.Anchor
196196 -> ([Value] -> [Value])
197− -> C.Sink Event Parse Value
197+ -> ConduitM Event o Parse Value
198198parseS a front = do
199199 me <- CL.peek
200200 case me of
@@ -212,7 +212,7 @@ parseS a front = do
212212
213213parseM :: Y.Anchor
214214 -> M.HashMap Text Value
215− -> C.Sink Event Parse Value
215+ -> ConduitM Event o Parse Value
216216parseM a front = do
217217 me <- CL.peek
218218 case me of
@@ -249,13 +249,13 @@ parseM a front = do
249249 merge' al _ = al
250250
251251decodeHelper :: FromJSON a
252− => C.Source Parse Y.Event
252+ => ConduitM () Y.Event Parse ()
253253 -> IO (Either ParseException (Either String a))
254254decodeHelper src = do
255255 -- This used to be tryAny, but the fact is that catching async
256256 -- exceptions is fine here. We'll rethrow them immediately in the
257257 -- otherwise clause.
258− x <- try $ runResourceT $ flip evalStateT Map.empty $ src C.$$ parse
258+ x <- try $ runResourceT $ flip evalStateT Map.empty $ runConduit $ src .| parse
259259 case x of
260260 Left e
261261 | Just pe <- fromException e -> return $ Left pe
@@ -264,10 +264,10 @@ decodeHelper src = do
264264 Right y -> return $ Right $ parseEither parseJSON y
265265
266266decodeHelper_ :: FromJSON a
267− => C.Source Parse Event
267+ => ConduitM () Event Parse ()
268268 -> IO (Either ParseException a)
269269decodeHelper_ src = do
270− x <- try $ runResourceT $ flip evalStateT Map.empty $ src C.$$ parse
270+ x <- try $ runResourceT $ flip evalStateT Map.empty $ runConduit $ src .| parse
271271 return $ case x of
272272 Left e
273273 | Just pe <- fromException e -> Left pe
Data/Yaml/Parser.hs+4−4
@@ -9,7 +9,7 @@ import Control.Applicative
99import Control.Exception (Exception)
1010import Control.Monad (MonadPlus (..), liftM, ap)
1111import Control.Monad.Trans.Class (lift)
12−import Control.Monad.Trans.Resource (MonadThrow, throwM, runResourceT)
12+import Control.Monad.Trans.Resource (MonadThrow, throwM)
1313import Control.Monad.Trans.Writer.Strict (tell, WriterT)
1414import Data.ByteString (ByteString)
1515import Data.Conduit
@@ -147,7 +147,7 @@ data YamlParseException
147147 deriving (Show, Typeable)
148148instance Exception YamlParseException
149149
150−sinkValue :: MonadThrow m => Consumer Event (WriterT AnchorMap m) YamlValue
150+sinkValue :: MonadThrow m => ConduitM Event o (WriterT AnchorMap m) YamlValue
151151sinkValue =
152152 start
153153 where
@@ -194,8 +194,8 @@ sinkValue =
194194 goM (front . ((k, v):))
195195 Just e -> throwM $ UnexpectedEvent e
196196
197−sinkRawDoc :: MonadThrow m => Consumer Event m RawDoc
197+sinkRawDoc :: MonadThrow m => ConduitM Event o m RawDoc
198198sinkRawDoc = uncurry RawDoc <$> runWriterC sinkValue
199199
200200readYamlFile :: FromYaml a => FilePath -> IO a
201−readYamlFile fp = runResourceT (decodeFile fp $$ sinkRawDoc) >>= parseRawDoc
201+readYamlFile fp = runConduitRes (decodeFile fp .| sinkRawDoc) >>= parseRawDoc
Text/Libyaml.hs+6−6
@@ -479,7 +479,7 @@ newtype ToEventRawException = ToEventRawException CInt
479479 deriving (Show, Typeable)
480480instance Exception ToEventRawException
481481
482−decode :: MonadResource m => B.ByteString -> Producer m Event
482+decode :: MonadResource m => B.ByteString -> ConduitM i Event m ()
483483decode bs | B8.null bs = return ()
484484decode bs =
485485 bracketP alloc cleanup (runParser . fst)
@@ -521,7 +521,7 @@ openFile file rawOpenFlags openMode = do
521521 then withCString openMode $ \openMode' -> c_fdopen fd openMode'
522522 else return nullPtr
523523
524−decodeFile :: MonadResource m => FilePath -> Producer m Event
524+decodeFile :: MonadResource m => FilePath -> ConduitM i Event m ()
525525decodeFile file =
526526 bracketP alloc cleanup (runParser . fst)
527527 where
@@ -549,7 +549,7 @@ decodeFile file =
549549 c_yaml_parser_delete ptr
550550 free ptr
551551
552−runParser :: MonadResource m => Parser -> Producer m Event
552+runParser :: MonadResource m => Parser -> ConduitM i Event m ()
553553runParser parser = do
554554 e <- liftIO $ parserParseOne' parser
555555 case e of
@@ -573,7 +573,7 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
573573 return $ Left $ YamlParseException problem context problemMark
574574 else Right <$> getEvent er
575575
576−encode :: MonadResource m => Consumer Event m ByteString
576+encode :: MonadResource m => ConduitM Event o m ByteString
577577encode =
578578 runEmitter alloc close
579579 where
@@ -590,7 +590,7 @@ encode =
590590
591591encodeFile :: MonadResource m
592592 => FilePath
593− -> Consumer Event m ()
593+ -> ConduitM Event o m ()
594594encodeFile filePath =
595595 bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u)
596596 where
@@ -605,7 +605,7 @@ encodeFile filePath =
605605runEmitter :: MonadResource m
606606 => (Emitter -> IO a) -- ^ alloc
607607 -> (() -> a -> IO b) -- ^ close
608− -> Consumer Event m b
608+ -> ConduitM Event o m b
609609runEmitter allocI closeI =
610610 bracketP alloc cleanup go
611611 where
test/Data/YamlSpec.hs+14−15
@@ -11,8 +11,7 @@ import qualified Data.ByteString.Char8 as B8
1111
1212import Test.HUnit hiding (Test, path)
1313
14−import qualified Data.Conduit as C
15−import qualified Control.Monad.Trans.Resource as C
14+import Data.Conduit (runConduitRes, (.|), ConduitM)
1615import qualified Data.Conduit.List as CL
1716
1817import Control.Monad
@@ -172,7 +171,7 @@ specialStrings =
172171 , "foo\nbar\nbaz\n"
173172 ]
174173
175−counter :: Monad m => (Y.Event -> Bool) -> C.Sink Y.Event m Int
174+counter :: Monad m => (Y.Event -> Bool) -> ConduitM Y.Event o m Int
176175counter pred' =
177176 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
178177
@@ -181,7 +180,7 @@ caseHelper :: String
181180 -> Int
182181 -> Assertion
183182caseHelper yamlString pred' expRes = do
184− res <- C.runResourceT $ Y.decode (B8.pack yamlString) C.$$ counter pred'
183+ res <- runConduitRes $ Y.decode (B8.pack yamlString) .| counter pred'
185184 res @?= expRes
186185
187186caseCountScalarsWithAnchor :: Assertion
@@ -218,7 +217,7 @@ caseCountAliases =
218217
219218caseCountScalars :: Assertion
220219caseCountScalars = do
221− res <- C.runResourceT $ Y.decode yamlBS C.$$ CL.fold adder accum
220+ res <- runConduitRes $ Y.decode yamlBS .| CL.fold adder accum
222221 res @?= (7, 1, 2)
223222 where
224223 yamlString = "foo:\n baz: [bin1, bin2, bin3]\nbaz: bazval"
@@ -231,7 +230,7 @@ caseCountScalars = do
231230
232231caseLargestString :: Assertion
233232caseLargestString = do
234− res <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.fold adder accum
233+ res <- runConduitRes $ Y.decodeFile filePath .| CL.fold adder accum
235234 res @?= (length expected, expected)
236235 where
237236 expected = "this one is just a little bit bigger than the others"
@@ -251,9 +250,9 @@ instance Eq MyEvent where
251250
252251caseEncodeDecode :: Assertion
253252caseEncodeDecode = do
254− eList <- C.runResourceT $ Y.decode yamlBS C.$$ CL.consume
255− bs <- C.runResourceT $ CL.sourceList eList C.$$ Y.encode
256− eList2 <- C.runResourceT $ Y.decode bs C.$$ CL.consume
253+ eList <- runConduitRes $ Y.decode yamlBS .| CL.consume
254+ bs <- runConduitRes $ CL.sourceList eList .| Y.encode
255+ eList2 <- runConduitRes $ Y.decode bs .| CL.consume
257256 map MyEvent eList @=? map MyEvent eList2
258257 where
259258 yamlString = "foo: bar\nbaz:\n - bin1\n - bin2\n"
@@ -261,17 +260,17 @@ caseEncodeDecode = do
261260
262261caseEncodeDecodeFile :: Assertion
263262caseEncodeDecodeFile = withFile "" $ \tmpPath -> do
264− eList <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
265− C.runResourceT $ CL.sourceList eList C.$$ Y.encodeFile tmpPath
266− eList2 <- C.runResourceT $ Y.decodeFile filePath C.$$ CL.consume
263+ eList <- runConduitRes $ Y.decodeFile filePath .| CL.consume
264+ runConduitRes $ CL.sourceList eList .| Y.encodeFile tmpPath
265+ eList2 <- runConduitRes $ Y.decodeFile filePath .| CL.consume
267266 map MyEvent eList @=? map MyEvent eList2
268267 where
269268 filePath = "test/largest-string.yaml"
270269
271270caseInterleave :: Assertion
272271caseInterleave = withFile "" $ \tmpPath -> withFile "" $ \tmpPath2 -> do
273− () <- C.runResourceT $ Y.decodeFile filePath C.$$ Y.encodeFile tmpPath
274− () <- C.runResourceT $ Y.decodeFile tmpPath C.$$ Y.encodeFile tmpPath2
272+ () <- runConduitRes $ Y.decodeFile filePath .| Y.encodeFile tmpPath
273+ () <- runConduitRes $ Y.decodeFile tmpPath .| Y.encodeFile tmpPath2
275274 f1 <- readFile tmpPath
276275 f2 <- readFile tmpPath2
277276 f1 @=? f2
@@ -280,7 +279,7 @@ caseInterleave = withFile "" $ \tmpPath -> withFile "" $ \tmpPath2 -> do
280279
281280caseDecodeInvalidDocument :: Assertion
282281caseDecodeInvalidDocument = do
283− x <- try $ C.runResourceT $ Y.decode yamlBS C.$$ CL.sinkNull
282+ x <- try $ runConduitRes $ Y.decode yamlBS .| CL.sinkNull
284283 case x of
285284 Left (_ :: SomeException) -> return ()
286285 Right y -> do
yaml.cabal+1−1
@@ -48,7 +48,7 @@ library
4848 build-depends: base >= 4 && < 5
4949 , transformers >= 0.1
5050 , bytestring >= 0.9.1.4
51− , conduit >= 1.1.0 && < 1.4
51+ , conduit >= 1.2.8 && < 1.4
5252 , resourcet >= 0.3 && < 1.3
5353 , aeson >= 0.7
5454 , containers