git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: avoid reparsing at the top level

Blocks following paragraphs are parsed only once at the top level. Lists still take exponential time to parse, but this time is not doubled anymore when this list terminates paragraph.

commitfe5fd12812e657c720cc2c2ddff314ad7c1547fd authorAlexander Krotov <ilabdsf@gmail.com> dateMon 5 Feb 2018, 15:41 (9 years ago) parente645510
1 file changed+14−2
src/Text/Pandoc/Readers/Muse.hs+14−2
src/Text/Pandoc/Readers/Muse.hs+14−2
@@ -130,8 +130,7 @@ instance HasLogMessages MuseState where
130130parseMuse :: PandocMonad m => MuseParser m Pandoc
131131parseMuse = do
132132 many directive
133− blocks <- mconcat <$> many parseBlock
134− eof
133+ blocks <- parseBlocks
135134 st <- getState
136135 let doc = runF (do Pandoc _ bs <- B.doc <$> blocks
137136 meta <- museMeta st
@@ -250,6 +249,19 @@ directive = do
250249-- block parsers
251250--
252251
252+parseBlocks :: PandocMonad m
253+ => MuseParser m (F Blocks)
254+parseBlocks =
255+ try (mempty <$ eof) <|>
256+ try blockStart <|>
257+ try paraStart
258+ where
259+ blockStart = do first <- blockElements
260+ rest <- parseBlocks
261+ return $ first B.<> rest
262+ paraStart = do (first, rest) <- paraUntil ((mempty <$ eof) <|> (blankline >> blockStart))
263+ return $ first B.<> rest
264+
253265parseBlock :: PandocMonad m => MuseParser m (F Blocks)
254266parseBlock = do
255267 res <- blockElements <|> para