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.
This commit is contained in:
Alexander Krotov 2018-02-05 15:41:51 +03:00
parent e645510d54
commit fe5fd12812

View file

@ -130,8 +130,7 @@ instance HasLogMessages MuseState where
parseMuse :: PandocMonad m => MuseParser m Pandoc
parseMuse = do
many directive
blocks <- mconcat <$> many parseBlock
eof
blocks <- parseBlocks
st <- getState
let doc = runF (do Pandoc _ bs <- B.doc <$> blocks
meta <- museMeta st
@ -250,6 +249,19 @@ directive = do
-- block parsers
--
parseBlocks :: PandocMonad m
=> MuseParser m (F Blocks)
parseBlocks =
try (mempty <$ eof) <|>
try blockStart <|>
try paraStart
where
blockStart = do first <- blockElements
rest <- parseBlocks
return $ first B.<> rest
paraStart = do (first, rest) <- paraUntil ((mempty <$ eof) <|> (blankline >> blockStart))
return $ first B.<> rest
parseBlock :: PandocMonad m => MuseParser m (F Blocks)
parseBlock = do
res <- blockElements <|> para