git.iko.soy/typeable/pandoc
on master help sign in
T.P.Parsing: Generalize readWithM to any Char Stream.
c721d28John MacFarlane
pandoc.cabal+2−1
@@ -394,7 +394,8 @@ library
394 http-types >= 0.8 && < 0.13,
394 http-types >= 0.8 && < 0.13,
395 case-insensitive >= 1.2 && < 1.3,
395 case-insensitive >= 1.2 && < 1.3,
396 unicode-transforms >= 0.3 && < 0.4,
396 unicode-transforms >= 0.3 && < 0.4,
397− HsYAML >= 0.1.1.1 && < 0.2
397+ HsYAML >= 0.1.1.1 && < 0.2,
398+ monad-loops >= 0.4 && < 0.5
398 if impl(ghc < 8.0)
399 if impl(ghc < 8.0)
399 build-depends: semigroups == 0.18.*,
400 build-depends: semigroups == 0.18.*,
400 -- basement 0.0.8 and foundation 0.0.21, transitive
401 -- basement 0.0.8 and foundation 0.0.21, transitive
src/Text/Pandoc/Parsing.hs+12−5
@@ -198,6 +198,7 @@ where
198
198
199import Prelude
199import Prelude
200import Control.Monad.Identity
200import Control.Monad.Identity
201+import Control.Monad.Loops (unfoldM)
201import Control.Monad.Reader
202import Control.Monad.Reader
202import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
203import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
203 isPunctuation, isSpace, ord, toLower, toUpper)
204 isPunctuation, isSpace, ord, toLower, toUpper)
@@ -221,6 +222,7 @@ import Text.Pandoc.Shared
221import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
222import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
222import Text.Pandoc.XML (fromEntities)
223import Text.Pandoc.XML (fromEntities)
223import Text.Parsec hiding (token)
224import Text.Parsec hiding (token)
225+import qualified Text.Parsec (uncons)
224import Text.Parsec.Pos (initialPos, newPos, updatePosString)
226import Text.Parsec.Pos (initialPos, newPos, updatePosString)
225
227
226import Control.Monad.Except
228import Control.Monad.Except
@@ -1044,13 +1046,18 @@ gridTableFooter = blanklines
1044---
1046---
1045
1047
1046-- | Removes the ParsecT layer from the monad transformer stack
1048-- | Removes the ParsecT layer from the monad transformer stack
1047−readWithM :: Monad m
1049+readWithM :: (Monad m, Stream s m Char)
1048− => ParserT [Char] st m a -- ^ parser
1050+ => ParserT s st m a -- ^ parser
1049 -> st -- ^ initial state
1051 -> st -- ^ initial state
1050− -> String -- ^ input
1052+ -> s -- ^ input
1051 -> m (Either PandocError a)
1053 -> m (Either PandocError a)
1052−readWithM parser state input =
1054+readWithM parser state input = do
1053− mapLeft (PandocParsecError input) `liftM` runParserT parser state "source" input
1055+ res <- runParserT parser state "source" input
1056+ case res of
1057+ Right x -> return $ Right x
1058+ Left e -> do
1059+ inp <- map fst <$> unfoldM (Text.Parsec.uncons input)
1060+ return $ Left $ PandocParsecError inp e
1054
1061
1055
1062
1056-- | Parse a string with a given parser and state
1063-- | Parse a string with a given parser and state