aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-10-23 09:42:46 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-10-23 09:42:46 -0700
commit91c325c714050313429f6d553d7fa1bef15892a2 (patch)
tree66045d8fbd6ea4a9b9a3ee90c9d406eb92faab66 /src
parentd50f46d26d8584a03b775394de8878e028f8d8a4 (diff)
downloadpandoc-91c325c714050313429f6d553d7fa1bef15892a2.tar.gz
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.)
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs19
-rw-r--r--src/Text/Pandoc/Readers/LaTeX/Parsing.hs7
2 files changed, 16 insertions, 10 deletions
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 }