Make readWithM accept Text input as well as String (API change)

This commit is contained in:
Alexander Krotov 2018-11-01 13:43:54 +03:00 committed by John MacFarlane
parent 95eccb94b0
commit e5cc24fb61

View file

@ -1044,19 +1044,13 @@ gridTableFooter = blanklines
--- ---
-- | Removes the ParsecT layer from the monad transformer stack -- | Removes the ParsecT layer from the monad transformer stack
readWithM :: (Monad m, Stream s m Char) readWithM :: (Monad m, Stream s m Char, ToString s)
=> ParserT s st m a -- ^ parser => ParserT s st m a -- ^ parser
-> st -- ^ initial state -> st -- ^ initial state
-> s -- ^ input -> s -- ^ input
-> m (Either PandocError a) -> m (Either PandocError a)
readWithM parser state input = do readWithM parser state input =
res <- runParserT parser state "source" input mapLeft (PandocParsecError $ toString input) `liftM` runParserT parser state "source" input
case res of
Right x -> return $ Right x
Left e -> do
inp <- either (const "") id
<$> runParserT (many1 anyChar) state "source" input
return $ Left $ PandocParsecError inp e
-- | Parse a string with a given parser and state -- | Parse a string with a given parser and state
readWith :: Parser [Char] st a readWith :: Parser [Char] st a