aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-08 22:12:04 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:41 +0100
commit4111fdbaf0a21eb48177af8d9815f21008f505e9 (patch)
treec48001c5ef45b5efbe401ad8fd41512cbcf5bfe9 /src/Text
parent54932ade677b48ec42f6461028a3b58bb85aaa50 (diff)
downloadpandoc-4111fdbaf0a21eb48177af8d9815f21008f505e9.tar.gz
Instances of PandocMonad for common transformers.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Class.hs81
1 files changed, 79 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index f6c4cd553..b1e05f42a 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveFunctor, DeriveDataTypeable, TypeSynonymInstances,
-FlexibleInstances, GeneralizedNewtypeDeriving, FlexibleContexts #-}
+FlexibleInstances, GeneralizedNewtypeDeriving, FlexibleContexts,
+MultiParamTypeClasses, UndecidableInstances #-}
{-
Copyright (C) 2016 Jesse Rosenthal <jrosenthal@jhu.edu>
@@ -91,6 +92,9 @@ import System.FilePath ((</>))
import qualified System.FilePath.Glob as IO (glob)
import qualified System.Directory as IO (getModificationTime)
import Control.Monad.State hiding (fail)
+import Control.Monad.Reader (ReaderT)
+import Control.Monad.Writer (WriterT)
+import Control.Monad.RWS (RWST)
import Control.Monad.Except hiding (fail)
import Data.Word (Word8)
import Data.Default
@@ -98,7 +102,8 @@ import System.IO.Error
import qualified Data.Map as M
import Text.Pandoc.Error
-class (Functor m, Applicative m, Monad m, MonadError PandocError m) => PandocMonad m where
+class (Functor m, Applicative m, Monad m, MonadError PandocError m)
+ => PandocMonad m where
lookupEnv :: String -> m (Maybe String)
getCurrentTime :: m UTCTime
getCurrentTimeZone :: m TimeZone
@@ -400,3 +405,75 @@ instance PandocMonad m => PandocMonad (ParserT s st m) where
getCommonState = lift getCommonState
putCommonState = lift . putCommonState
+instance PandocMonad m => PandocMonad (ReaderT r m) where
+ lookupEnv = lift . lookupEnv
+ getCurrentTime = lift getCurrentTime
+ getCurrentTimeZone = lift getCurrentTimeZone
+ getDefaultReferenceDocx = lift . getDefaultReferenceDocx
+ getDefaultReferenceODT = lift . getDefaultReferenceODT
+ newStdGen = lift newStdGen
+ newUniqueHash = lift newUniqueHash
+ readFileLazy = lift . readFileLazy
+ readDataFile mbuserdir = lift . readDataFile mbuserdir
+ fail = lift . fail
+ fetchItem media = lift . fetchItem media
+ fetchItem' media sourceUrl = lift . fetchItem' media sourceUrl
+ glob = lift . glob
+ getModificationTime = lift . getModificationTime
+ getCommonState = lift getCommonState
+ putCommonState = lift . putCommonState
+
+instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
+ lookupEnv = lift . lookupEnv
+ getCurrentTime = lift getCurrentTime
+ getCurrentTimeZone = lift getCurrentTimeZone
+ getDefaultReferenceDocx = lift . getDefaultReferenceDocx
+ getDefaultReferenceODT = lift . getDefaultReferenceODT
+ newStdGen = lift newStdGen
+ newUniqueHash = lift newUniqueHash
+ readFileLazy = lift . readFileLazy
+ readDataFile mbuserdir = lift . readDataFile mbuserdir
+ fail = lift . fail
+ fetchItem media = lift . fetchItem media
+ fetchItem' media sourceUrl = lift . fetchItem' media sourceUrl
+ glob = lift . glob
+ getModificationTime = lift . getModificationTime
+ getCommonState = lift getCommonState
+ putCommonState = lift . putCommonState
+
+instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
+ lookupEnv = lift . lookupEnv
+ getCurrentTime = lift getCurrentTime
+ getCurrentTimeZone = lift getCurrentTimeZone
+ getDefaultReferenceDocx = lift . getDefaultReferenceDocx
+ getDefaultReferenceODT = lift . getDefaultReferenceODT
+ newStdGen = lift newStdGen
+ newUniqueHash = lift newUniqueHash
+ readFileLazy = lift . readFileLazy
+ readDataFile mbuserdir = lift . readDataFile mbuserdir
+ fail = lift . fail
+ fetchItem media = lift . fetchItem media
+ fetchItem' media sourceUrl = lift . fetchItem' media sourceUrl
+ glob = lift . glob
+ getModificationTime = lift . getModificationTime
+ getCommonState = lift getCommonState
+ putCommonState = lift . putCommonState
+
+instance PandocMonad m => PandocMonad (StateT st m) where
+ lookupEnv = lift . lookupEnv
+ getCurrentTime = lift getCurrentTime
+ getCurrentTimeZone = lift getCurrentTimeZone
+ getDefaultReferenceDocx = lift . getDefaultReferenceDocx
+ getDefaultReferenceODT = lift . getDefaultReferenceODT
+ newStdGen = lift newStdGen
+ newUniqueHash = lift newUniqueHash
+ readFileLazy = lift . readFileLazy
+ readDataFile mbuserdir = lift . readDataFile mbuserdir
+ fail = lift . fail
+ fetchItem media = lift . fetchItem media
+ fetchItem' media sourceUrl = lift . fetchItem' media sourceUrl
+ glob = lift . glob
+ getModificationTime = lift . getModificationTime
+ getCommonState = lift getCommonState
+ putCommonState = lift . putCommonState
+