diff options
author | Alexander Krotov <ilabdsf@gmail.com> | 2018-11-01 13:43:54 +0300 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-11-03 10:17:32 -0700 |
commit | e5cc24fb6171f0befe4d1f0a5a7b7d5194cfd72b (patch) | |
tree | 563ff33947c50585fb16becc41e4c3bda4a8aee5 /src/Text/Pandoc | |
parent | 95eccb94b074a25fae7ac10523e38988bbeacada (diff) | |
download | pandoc-e5cc24fb6171f0befe4d1f0a5a7b7d5194cfd72b.tar.gz |
Make readWithM accept Text input as well as String (API change)
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index 788744db3..1c2c6408c 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -1044,19 +1044,13 @@ gridTableFooter = blanklines --- -- | Removes the ParsecT layer from the monad transformer stack -readWithM :: (Monad m, Stream s m Char) - => ParserT s st m a -- ^ parser - -> st -- ^ initial state - -> s -- ^ input +readWithM :: (Monad m, Stream s m Char, ToString s) + => ParserT s st m a -- ^ parser + -> st -- ^ initial state + -> s -- ^ input -> m (Either PandocError a) -readWithM parser state input = do - res <- 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 +readWithM parser state input = + mapLeft (PandocParsecError $ toString input) `liftM` runParserT parser state "source" input -- | Parse a string with a given parser and state readWith :: Parser [Char] st a |