From 8f841297df2aa4dcb1789843e562d4404baf1bf0 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Wed, 19 Sep 2018 16:34:14 +0300 Subject: Muse reader: parse Text instead of String Benchmark shows 7% improvement --- src/Text/Pandoc/Readers/Muse.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Muse.hs b/src/Text/Pandoc/Readers/Muse.hs index a1f0e19ac..a0069827a 100644 --- a/src/Text/Pandoc/Readers/Muse.hs +++ b/src/Text/Pandoc/Readers/Muse.hs @@ -56,10 +56,11 @@ import Text.Pandoc.Builder (Blocks, Inlines) import qualified Text.Pandoc.Builder as B import Text.Pandoc.Class (PandocMonad (..)) import Text.Pandoc.Definition +import Text.Pandoc.Error (PandocError (PandocParsecError)) import Text.Pandoc.Logging import Text.Pandoc.Options import Text.Pandoc.Parsing hiding (F, enclosed) -import Text.Pandoc.Shared (crFilter, underlineSpan) +import Text.Pandoc.Shared (crFilter, underlineSpan, mapLeft) -- | Read Muse from an input string and return a Pandoc document. readMuse :: PandocMonad m @@ -67,7 +68,8 @@ readMuse :: PandocMonad m -> Text -> m Pandoc readMuse opts s = do - res <- readWithM parseMuse def{ museOptions = opts } (unpack (crFilter s)) + let input = crFilter s + res <- mapLeft (PandocParsecError $ unpack input) `liftM` runParserT parseMuse def{ museOptions = opts } "source" input case res of Left e -> throwError e Right d -> return d @@ -97,7 +99,7 @@ instance Default MuseState where , museInPara = False } -type MuseParser = ParserT String MuseState +type MuseParser = ParserT Text MuseState instance HasReaderOptions MuseState where extractReaderOptions = museOptions -- cgit v1.2.3