From 91c325c714050313429f6d553d7fa1bef15892a2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 23 Oct 2019 09:42:46 -0700 Subject: T.P.Readers.LaTeX.Parsing: add `[Tok]` parameter to rawLaTeXParser. This allows us to avoid retokenizing multiple times in e.g. rawLaTeXBlock. (Unexported module, so not an API change.) --- src/Text/Pandoc/Readers/LaTeX.hs | 19 +++++++++++++------ src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 7 +++---- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 7313dd90c..c20efce38 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -126,14 +126,16 @@ rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s) => ParserT String s m String rawLaTeXBlock = do lookAhead (try (char '\\' >> letter)) - snd <$> (rawLaTeXParser False macroDef blocks - <|> (rawLaTeXParser True + inp <- getInput + let toks = tokenize "source" $ T.pack inp + snd <$> (rawLaTeXParser toks False macroDef blocks + <|> (rawLaTeXParser toks True (do choice (map controlSeq ["include", "input", "subfile", "usepackage"]) skipMany opt braced return mempty) blocks) - <|> rawLaTeXParser True + <|> rawLaTeXParser toks True (environment <|> blockCommand) (mconcat <$> (many (block <|> beginOrEndCommand)))) @@ -155,11 +157,13 @@ rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s) => ParserT String s m String rawLaTeXInline = do lookAhead (try (char '\\' >> letter)) + inp <- getInput + let toks = tokenize "source" $ T.pack inp raw <- snd <$> - ( rawLaTeXParser True + ( rawLaTeXParser toks True (mempty <$ (controlSeq "input" >> skipMany opt >> braced)) inlines - <|> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') + <|> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand') inlines ) finalbraces <- mconcat <$> many (try (string "{}")) -- see #5439 @@ -168,7 +172,10 @@ rawLaTeXInline = do inlineCommand :: PandocMonad m => ParserT String ParserState m Inlines inlineCommand = do lookAhead (try (char '\\' >> letter)) - fst <$> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') inlines + inp <- getInput + let toks = tokenize "source" $ T.pack inp + fst <$> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand') + inlines -- inline elements: diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index 018ee2578..af354843a 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -200,10 +200,9 @@ withVerbatimMode parser = do return result rawLaTeXParser :: (PandocMonad m, HasMacros s, HasReaderOptions s) - => Bool -> LP m a -> LP m a -> ParserT String s m (a, String) -rawLaTeXParser retokenize parser valParser = do - inp <- getInput - let toks = tokenize "source" $ T.pack inp + => [Tok] -> Bool -> LP m a -> LP m a + -> ParserT String s m (a, String) +rawLaTeXParser toks retokenize parser valParser = do pstate <- getState let lstate = def{ sOptions = extractReaderOptions pstate } let lstate' = lstate { sMacros = extractMacros pstate } -- cgit v1.2.3