aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-12-02 09:11:24 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:40 +0100
commit221f878c0ec691dd09cf388d4d86ebecc8bf8355 (patch)
tree9ce36a5b89858f59bd6369f39c03279c2fc499f2 /src/Text
parent912eee362b029bd1a5524434c55ff0496df5dfcf (diff)
downloadpandoc-221f878c0ec691dd09cf388d4d86ebecc8bf8355.tar.gz
Class: cleanup and clarification.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Class.hs28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index 18f22a41b..0881878ed 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -114,13 +114,10 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m, MonadState C
fail :: String -> m b
glob :: String -> m [FilePath]
getModificationTime :: FilePath -> m UTCTime
- -- The following are common to all instantiations of the monad, up
- -- to the record names, so I'd like to work out a better way to deal
- -- with it.
---Some functions derived from Primitives:
+-- Functions defined for all PandocMonad instances
warn :: PandocMonad m => String -> m ()
warn msg = modify $ \st -> st{stWarnings = msg : stWarnings st}
@@ -144,11 +141,6 @@ getInputFiles = gets stInputFiles
getOutputFile :: PandocMonad m => m (Maybe FilePath)
getOutputFile = gets stOutputFile
-
-
-
-
-
getPOSIXTime :: (PandocMonad m) => m POSIXTime
getPOSIXTime = utcTimeToPOSIXSeconds <$> getCurrentTime
@@ -167,6 +159,11 @@ addWarningWithPos mbpos msg =
warn $
msg ++ maybe "" (\pos -> " " ++ show pos) mbpos
+--
+
+-- All PandocMonad instances should be an instance MonadState of this
+-- datatype:
+
data CommonState = CommonState { stWarnings :: [String]
, stMediaBag :: MediaBag
, stInputFiles :: Maybe [FilePath]
@@ -180,8 +177,6 @@ instance Default CommonState where
, stOutputFile = Nothing
}
--- Nothing in this for now, but let's put it there anyway.
-
runIO :: PandocIO a -> IO (Either PandocError a)
runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
@@ -190,14 +185,6 @@ withMediaBag ma = ((,)) <$> ma <*> getMediaBag
runIOorExplode :: PandocIO a -> IO a
runIOorExplode ma = handleError <$> runIO ma
- -- eitherVal <- runIO ma
- -- case eitherVal of
- -- Right x -> return x
- -- Left (PandocFileReadError fp) -> error $ "problem reading " ++ fp
- -- Left (PandocShouldNeverHappenError s) -> error s
- -- Left (PandocParseError s) -> error $ "parse error" ++ s
- -- Left (PandocSomeError s) -> error s
-
newtype PandocIO a = PandocIO {
unPandocIO :: ExceptT PandocError (StateT CommonState IO) a
@@ -300,9 +287,6 @@ runPure x = flip evalState def $
runExceptT $
unPandocPure x
--- setPureState :: PureState -> PandocPure ()
--- setPureState st = PandocPure $ lift $ lift $ lift $ put st
-
instance PandocMonad PandocPure where
lookupEnv s = PandocPure $ do
env <- lift $ lift $ gets envEnv