@@ -64,6 +64,7 @@ module Text.Pandoc.Parsing ( anyLine,
64 widthsFromIndices,
64 widthsFromIndices,
65 gridTableWith,
65 gridTableWith,
67 testStringWith,
68 testStringWith,
68 guardEnabled,
69 guardEnabled,
69 guardDisabled,
70 guardDisabled,
@@ -825,15 +826,16 @@ gridTableFooter = blanklines
828−-- | Parse a string with a given parser and state.
829+-- | Removes the ParsecT layer from the monad transformer stack
829−readWith :: (Stream [Char] Identity Char)
830+readWithM :: (Monad m, Functor m)
830− => ParserT [Char] st Identity a -- ^ parser
831+ => ParserT [Char] st m a -- ^ parser
831− -> st -- ^ initial state
832+ -> st -- ^ initial state
832− -> [Char] -- ^ input
833+ -> String -- ^ input
834−readWith parser state input =
835+readWithM parser state input =
835− case runParser parser state "source" input of
836+ handleError <$> (runParserT parser state "source" input)
836− Left err' ->
838+ handleError (Left err') =
837 let errPos = errorPos err'
839 let errPos = errorPos err'
838 errLine = sourceLine errPos
840 errLine = sourceLine errPos
839 errColumn = sourceColumn errPos
841 errColumn = sourceColumn errPos
@@ -841,7 +843,14 @@ readWith parser state input =
841 in error $ "\nError at " ++ show err' ++ "\n" ++
843 in error $ "\nError at " ++ show err' ++ "\n" ++
842 theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++
844 theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++
844− Right result -> result
846+ handleError (Right result) = result
848+-- | Parse a string with a given parser and state
849+readWith :: Parser [Char] st a
853+readWith p t inp = runIdentity $ readWithM p t inp
846-- | Parse a string with @parser@ (for testing).
855-- | Parse a string with @parser@ (for testing).
847testStringWith :: (Show a, Stream [Char] Identity Char)
856testStringWith :: (Show a, Stream [Char] Identity Char)