git.iko.soy/typeable/pandoc
on master help sign in
T.P.Parsing: Generalize readWithM to any Char Stream.

[API change]

commitc721d28c332929e0a06a32577886beb48ea1484a authorJohn MacFarlane <jgm@berkeley.edu> dateFri 2 Nov 2018, 18:23 (8 years ago) parent9e369e9
2 files changed+14−6
pandoc.cabal+2−1 src/Text/Pandoc/Parsing.hs+12−5
pandoc.cabal+2−1
@@ -394,7 +394,8 @@ library
394394 http-types >= 0.8 && < 0.13,
395395 case-insensitive >= 1.2 && < 1.3,
396396 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
398399 if impl(ghc < 8.0)
399400 build-depends: semigroups == 0.18.*,
400401 -- basement 0.0.8 and foundation 0.0.21, transitive
src/Text/Pandoc/Parsing.hs+12−5
@@ -198,6 +198,7 @@ where
198198
199199import Prelude
200200import Control.Monad.Identity
201+import Control.Monad.Loops (unfoldM)
201202import Control.Monad.Reader
202203import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
203204 isPunctuation, isSpace, ord, toLower, toUpper)
@@ -221,6 +222,7 @@ import Text.Pandoc.Shared
221222import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
222223import Text.Pandoc.XML (fromEntities)
223224import Text.Parsec hiding (token)
225+import qualified Text.Parsec (uncons)
224226import Text.Parsec.Pos (initialPos, newPos, updatePosString)
225227
226228import Control.Monad.Except
@@ -1044,13 +1046,18 @@ gridTableFooter = blanklines
10441046---
10451047
10461048-- | Removes the ParsecT layer from the monad transformer stack
1047−readWithM :: Monad m
1048− => ParserT [Char] st m a -- ^ parser
1049+readWithM :: (Monad m, Stream s m Char)
1050+ => ParserT s st m a -- ^ parser
10491051 -> st -- ^ initial state
1050− -> String -- ^ input
1052+ -> s -- ^ input
10511053 -> m (Either PandocError a)
1052−readWithM parser state input =
1053− mapLeft (PandocParsecError input) `liftM` runParserT parser state "source" input
1054+readWithM parser state input = do
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
10541061
10551062
10561063-- | Parse a string with a given parser and state