on master help sign in
Removed MyReaderT by moving to c-m-f
48b5ad5Michael Snoyman
Text/Libyaml.hs+12−19
@@ -39,10 +39,9 @@ import Foreign.Ptr
39import Foreign.ForeignPtr
39import Foreign.ForeignPtr
40import Foreign.Marshal.Alloc
40import Foreign.Marshal.Alloc
41import "transformers" Control.Monad.Trans
41import "transformers" Control.Monad.Trans
42−import Control.Failure
42+import Control.Monad.Failure.Transformers
43import qualified Control.Monad.Trans.Error as ErrorT
43import qualified Control.Monad.Trans.Error as ErrorT
44import Control.Monad.Trans.Reader
44import Control.Monad.Trans.Reader
45−import Control.Applicative
46
45
47import Control.Exception (throwIO, Exception, SomeException)
46import Control.Exception (throwIO, Exception, SomeException)
48import Data.Typeable (Typeable)
47import Data.Typeable (Typeable)
@@ -126,8 +125,11 @@ data YamlException =
126 | YamlInvalidStartingEvent Event
125 | YamlInvalidStartingEvent Event
127 | YamlFileNotFound FilePath
126 | YamlFileNotFound FilePath
128 | YamlOtherException SomeException
127 | YamlOtherException SomeException
128+ | YamlStringException String
129 deriving (Show, Typeable)
129 deriving (Show, Typeable)
130instance Exception YamlException
130instance Exception YamlException
131+instance ErrorT.Error YamlException where
132+ strMsg = YamlStringException
131
133
132data ParserStruct
134data ParserStruct
133type Parser = Ptr ParserStruct
135type Parser = Ptr ParserStruct
@@ -409,7 +411,7 @@ emitEvent :: (MonadIO m, MonadFailure YamlException m)
409 => Event
411 => Event
410 -> YamlEncoder m ()
412 -> YamlEncoder m ()
411emitEvent e = do
413emitEvent e = do
412− emitter <- MyReaderT ask
414+ emitter <- ask
413 res <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
415 res <- liftIO $ toEventRaw e $ c_yaml_emitter_emit emitter
414 when (res == 0) $ do
416 when (res == 0) $ do
415 problem <- liftIO $ makeString c_get_emitter_error emitter
417 problem <- liftIO $ makeString c_get_emitter_error emitter
@@ -417,19 +419,10 @@ emitEvent e = do
417
419
418parseEvent :: (With m, MonadFailure YamlException m)
420parseEvent :: (With m, MonadFailure YamlException m)
419 => YamlDecoder m Event
421 => YamlDecoder m Event
420−parseEvent = MyReaderT ask >>= parserParseOne
422+parseEvent = ask >>= parserParseOne
421
423
422−runMyReaderT :: MyReaderT r m a -> r -> m a
423−runMyReaderT (MyReaderT (ReaderT f)) = f
424−
425−newtype MyReaderT r m a = MyReaderT (ReaderT r m a)
426− deriving (MonadTrans, MonadIO, Functor, Applicative,
427− Alternative, Monad, MonadPlus, With)
428−type YamlDecoder = MyReaderT Parser
424+type YamlDecoder = ReaderT Parser
429−type YamlEncoder = MyReaderT Emitter
425+type YamlEncoder = ReaderT Emitter
430−
431−instance MonadFailure e m => Failure e (MyReaderT r m) where
432− failure = lift . failure
433
426
434foreign import ccall unsafe "yaml_stream_start_event_initialize"
427foreign import ccall unsafe "yaml_stream_start_event_initialize"
435 c_yaml_stream_start_event_initialize :: EventRaw -> CInt -> IO CInt
428 c_yaml_stream_start_event_initialize :: EventRaw -> CInt -> IO CInt
@@ -544,22 +537,22 @@ instance Exception ToEventRawException
544encode :: (With m, MonadFailure YamlException m)
537encode :: (With m, MonadFailure YamlException m)
545 => YamlEncoder m ()
538 => YamlEncoder m ()
546 -> m B.ByteString
539 -> m B.ByteString
547−encode = withEmitter . runMyReaderT
540+encode = withEmitter . runReaderT
548
541
549encodeFile :: (With m, MonadFailure YamlException m)
542encodeFile :: (With m, MonadFailure YamlException m)
550 => FilePath
543 => FilePath
551 -> YamlEncoder m ()
544 -> YamlEncoder m ()
552 -> m ()
545 -> m ()
553−encodeFile filePath = withEmitterFile filePath . runMyReaderT
546+encodeFile filePath = withEmitterFile filePath . runReaderT
554
547
555decode :: (With m, MonadFailure YamlException m)
548decode :: (With m, MonadFailure YamlException m)
556 => B.ByteString
549 => B.ByteString
557 -> YamlDecoder m a
550 -> YamlDecoder m a
558 -> m a
551 -> m a
559−decode bs dec = withParser bs $ runMyReaderT dec
552+decode bs dec = withParser bs $ runReaderT dec
560
553
561decodeFile :: (With m, MonadFailure YamlException m)
554decodeFile :: (With m, MonadFailure YamlException m)
562 => FilePath
555 => FilePath
563 -> YamlDecoder m a
556 -> YamlDecoder m a
564 -> m a
557 -> m a
565−decodeFile fp dec = withFileParser fp $ runMyReaderT dec
558+decodeFile fp dec = withFileParser fp $ runReaderT dec
yaml.cabal+2−2
@@ -29,7 +29,7 @@ library
29 Buildable: True
29 Buildable: True
30 build-depends: base >= 4 && < 5,
30 build-depends: base >= 4 && < 5,
31 transformers >= 0.1 && < 0.2,
31 transformers >= 0.1 && < 0.2,
32− failure >= 0.0.0.1 && < 0.1,
32+ control-monad-failure >= 0.6.0 && < 0.7,
33 bytestring >= 0.9.1.4 && < 0.10
33 bytestring >= 0.9.1.4 && < 0.10
34 exposed-modules: Text.Libyaml
34 exposed-modules: Text.Libyaml
35 ghc-options: -Wall -auto-all -caf-all
35 ghc-options: -Wall -auto-all -caf-all
@@ -55,7 +55,7 @@ executable runtests
55 QuickCheck >= 1 && < 2,
55 QuickCheck >= 1 && < 2,
56 base >= 4 && < 5,
56 base >= 4 && < 5,
57 transformers >= 0.1 && < 0.2,
57 transformers >= 0.1 && < 0.2,
58− failure >= 0.0.0.1 && < 0.1,
58+ control-monad-failure >= 0.6.0 && < 0.7,
59 bytestring >= 0.9.1.4 && < 0.10
59 bytestring >= 0.9.1.4 && < 0.10
60 else
60 else
61 Buildable: False
61 Buildable: False