summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-11-27 15:55:02 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:40 +0100
commitbf8fb78389c0d2dc06ad91bc379fde5bd7e1f768 (patch)
treeb821c7f87f6e5c61a3fb0a2778df8baa50d98f39
parent8978689c0841d3c7cf47fc0de0ebb50a901f779d (diff)
Text.Pandoc: Change Reader to Reader m.
For now I just replaced occurences of Reader with Reader IO, so nothing is really different. When we move readers into instances of PandocMonad, though, we can change things here so that the readers will work with any instance of PandocMonad.
-rw-r--r--src/Text/Pandoc.hs20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs
index 106c8b6bb..70d1300b3 100644
--- a/src/Text/Pandoc.hs
+++ b/src/Text/Pandoc.hs
@@ -213,14 +213,16 @@ parseFormatSpec = parse formatSpec ""
'-' -> Set.delete ext
_ -> Set.insert ext
+-- TODO: when we get the PandocMonad stuff all sorted out,
+-- we can simply these types considerably. Errors/MediaBag can be
+-- part of the monad's internal state.
+data Reader m = StringReader (ReaderOptions -> String -> m (Either PandocError Pandoc))
+ | ByteStringReader (ReaderOptions -> BL.ByteString -> m (Either PandocError (Pandoc,MediaBag)))
-data Reader = StringReader (ReaderOptions -> String -> IO (Either PandocError Pandoc))
- | ByteStringReader (ReaderOptions -> BL.ByteString -> IO (Either PandocError (Pandoc,MediaBag)))
-
-mkStringReader :: (ReaderOptions -> String -> Either PandocError Pandoc) -> Reader
+mkStringReader :: (ReaderOptions -> String -> Either PandocError Pandoc) -> Reader IO
mkStringReader r = StringReader (\o s -> return $ r o s)
-mkStringReaderWithWarnings :: (ReaderOptions -> String -> Either PandocError (Pandoc, [String])) -> Reader
+mkStringReaderWithWarnings :: (ReaderOptions -> String -> Either PandocError (Pandoc, [String])) -> Reader IO
mkStringReaderWithWarnings r = StringReader $ \o s ->
case r o s of
Left err -> return $ Left err
@@ -228,10 +230,10 @@ mkStringReaderWithWarnings r = StringReader $ \o s ->
mapM_ warn warnings
return (Right doc)
-mkBSReader :: (ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag)) -> Reader
+mkBSReader :: (ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag)) -> Reader IO
mkBSReader r = ByteStringReader (\o s -> return $ r o s)
-mkBSReaderWithWarnings :: (ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag, [String])) -> Reader
+mkBSReaderWithWarnings :: (ReaderOptions -> BL.ByteString -> Either PandocError (Pandoc, MediaBag, [String])) -> Reader IO
mkBSReaderWithWarnings r = ByteStringReader $ \o s ->
case r o s of
Left err -> return $ Left err
@@ -240,7 +242,7 @@ mkBSReaderWithWarnings r = ByteStringReader $ \o s ->
return $ Right (doc, mediaBag)
-- | Association list of formats and readers.
-readers :: [(String, Reader)]
+readers :: [(String, Reader IO)]
readers = [ ("native" , StringReader $ \_ s -> return $ readNative s)
,("json" , mkStringReader readJSON )
,("markdown" , mkStringReaderWithWarnings readMarkdownWithWarnings)
@@ -349,7 +351,7 @@ getDefaultExtensions "epub" = Set.fromList [Ext_raw_html,
getDefaultExtensions _ = Set.fromList [Ext_auto_identifiers]
-- | Retrieve reader based on formatSpec (format+extensions).
-getReader :: String -> Either String Reader
+getReader :: String -> Either String (Reader IO)
getReader s =
case parseFormatSpec s of
Left e -> Left $ intercalate "\n" [m | Message m <- errorMessages e]