@@ -8,6 +8,7 @@
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
8{-# LANGUAGE GeneralizedNewtypeDeriving #-}
9{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE CPP #-}
10{-# LANGUAGE CPP #-}
11+{-# LANGUAGE TypeFamilies #-}
12-- | Low-level, streaming YAML interface. For a higher-level interface, see
13-- | Low-level, streaming YAML interface. For a higher-level interface, see
13-- "Data.Yaml".
14-- "Data.Yaml".
@@ -464,7 +465,12 @@ newtype ToEventRawException = ToEventRawException CInt
464 deriving (Show, Typeable)
465 deriving (Show, Typeable)
465instance Exception ToEventRawException
466instance Exception ToEventRawException
467−decode :: MonadResource m => B.ByteString -> GSource m Event
468+decode :: MonadResource m => B.ByteString
469+#if MIN_VERSION_conduit(1, 0, 0)
470+ -> MonadSource m Event
468decode bs | B8.null bs = return ()
474decode bs | B8.null bs = return ()
469decode bs =
475decode bs =
470 bracketP alloc cleanup (runParser . fst)
476 bracketP alloc cleanup (runParser . fst)
@@ -488,7 +494,12 @@ decode bs =
488 c_yaml_parser_delete ptr
494 c_yaml_parser_delete ptr
491−decodeFile :: MonadResource m => FilePath -> GSource m Event
497+decodeFile :: MonadResource m => FilePath
498+#if MIN_VERSION_conduit(1, 0, 0)
499+ -> MonadSource m Event
492decodeFile file =
503decodeFile file =
493 bracketP alloc cleanup (runParser . fst)
504 bracketP alloc cleanup (runParser . fst)
@@ -519,11 +530,24 @@ decodeFile file =
519 c_yaml_parser_delete ptr
530 c_yaml_parser_delete ptr
522−runParser :: MonadResource m => Parser -> GSource m Event
533+runParser :: MonadResource m => Parser
534+#if MIN_VERSION_conduit(1, 0, 0)
535+ -> MonadSource m Event
523runParser parser = do
539runParser parser = do
540+#if MIN_VERSION_conduit(1, 0, 0)
541+ e <- liftStreamIO $ parserParseOne' parser
524 e <- liftIO $ parserParseOne' parser
543 e <- liftIO $ parserParseOne' parser
525 case e of
545 case e of
546+#if MIN_VERSION_conduit(1, 0, 0)
547+ Left err -> liftStreamIO $ throwIO err
526 Left err -> liftIO $ throwIO err
549 Left err -> liftIO $ throwIO err
527 Right Nothing -> return ()
551 Right Nothing -> return ()
528 Right (Just ev) -> yield ev >> runParser parser
552 Right (Just ev) -> yield ev >> runParser parser
@@ -543,7 +567,12 @@ parserParseOne' parser = allocaBytes eventSize $ \er -> do
543 return $ Left $ YamlParseException problem context problemMark
567 return $ Left $ YamlParseException problem context problemMark
544 else Right <$> getEvent er
568 else Right <$> getEvent er
570+encode :: MonadResource m
571+#if MIN_VERSION_conduit(1, 0, 0)
572+ => MonadSink Event m ByteString
546−encode :: MonadResource m => GSink Event m ByteString
574+ => GSink Event m ByteString
548 runEmitter alloc close
577 runEmitter alloc close
@@ -560,7 +589,11 @@ encode =
561encodeFile :: MonadResource m
590encodeFile :: MonadResource m
562 => FilePath
591 => FilePath
592+#if MIN_VERSION_conduit(1, 0, 0)
593+ -> MonadSink Event m ()
563 -> GInfSink Event m
595 -> GInfSink Event m
564encodeFile filePath =
597encodeFile filePath =
565 bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u)
598 bracketP getFile c_fclose $ \file -> runEmitter (alloc file) (\u _ -> return u)
@@ -576,8 +609,13 @@ encodeFile filePath =
577runEmitter :: MonadResource m
610runEmitter :: MonadResource m
578 => (Emitter -> IO a) -- ^ alloc
611 => (Emitter -> IO a) -- ^ alloc
612+#if MIN_VERSION_conduit(1, 0, 0)
613+ -> (() -> a -> IO b) -- ^ close
614+ -> MonadSink Event m b
579 -> (u -> a -> IO b) -- ^ close
616 -> (u -> a -> IO b) -- ^ close
580 -> Pipe l Event o u m b
617 -> Pipe l Event o u m b
581runEmitter allocI closeI =
619runEmitter allocI closeI =
582 bracketP alloc cleanup go
620 bracketP alloc cleanup go
@@ -594,11 +632,23 @@ runEmitter allocI closeI =
594 go (emitter, a) =
632 go (emitter, a) =
635+#if MIN_VERSION_conduit(1, 0, 0)
636+ loop = await >>= maybe (close ()) push
597 loop = awaitE >>= either close push
638 loop = awaitE >>= either close push
641+#if MIN_VERSION_conduit(1, 0, 0)
643+ _ <- liftStreamIO $ toEventRaw e $ c_yaml_emitter_emit emitter
645+ close u = liftStreamIO $ closeI u a
598 push e = do
647 push e = do
599 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
648 _ <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
601 close u = liftIO $ closeI u a
650 close u = liftIO $ closeI u a
603-- | The pointer position
653-- | The pointer position
604data YamlMark = YamlMark { yamlIndex :: Int, yamlLine :: Int, yamlColumn :: Int }
654data YamlMark = YamlMark { yamlIndex :: Int, yamlLine :: Int, yamlColumn :: Int }