git.iko.soy/typeable/pandoc
on master help sign in
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.)

commit91c325c714050313429f6d553d7fa1bef15892a2 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 23 Oct 2019, 09:42 (7 years ago) parentd50f46d
2 files changed+16−10
src/Text/Pandoc/Readers/LaTeX.hs+13−6 src/Text/Pandoc/Readers/LaTeX/Parsing.hs+3−4
src/Text/Pandoc/Readers/LaTeX.hs+13−6
@@ -126,14 +126,16 @@ rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
126126 => ParserT String s m String
127127rawLaTeXBlock = do
128128 lookAhead (try (char '\\' >> letter))
129− snd <$> (rawLaTeXParser False macroDef blocks
130− <|> (rawLaTeXParser True
129+ inp <- getInput
130+ let toks = tokenize "source" $ T.pack inp
131+ snd <$> (rawLaTeXParser toks False macroDef blocks
132+ <|> (rawLaTeXParser toks True
131133 (do choice (map controlSeq
132134 ["include", "input", "subfile", "usepackage"])
133135 skipMany opt
134136 braced
135137 return mempty) blocks)
136− <|> rawLaTeXParser True
138+ <|> rawLaTeXParser toks True
137139 (environment <|> blockCommand)
138140 (mconcat <$> (many (block <|> beginOrEndCommand))))
139141
@@ -155,11 +157,13 @@ rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
155157 => ParserT String s m String
156158rawLaTeXInline = do
157159 lookAhead (try (char '\\' >> letter))
160+ inp <- getInput
161+ let toks = tokenize "source" $ T.pack inp
158162 raw <- snd <$>
159− ( rawLaTeXParser True
163+ ( rawLaTeXParser toks True
160164 (mempty <$ (controlSeq "input" >> skipMany opt >> braced))
161165 inlines
162− <|> rawLaTeXParser True (inlineEnvironment <|> inlineCommand')
166+ <|> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand')
163167 inlines
164168 )
165169 finalbraces <- mconcat <$> many (try (string "{}")) -- see #5439
@@ -168,7 +172,10 @@ rawLaTeXInline = do
168172inlineCommand :: PandocMonad m => ParserT String ParserState m Inlines
169173inlineCommand = do
170174 lookAhead (try (char '\\' >> letter))
171− fst <$> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') inlines
175+ inp <- getInput
176+ let toks = tokenize "source" $ T.pack inp
177+ fst <$> rawLaTeXParser toks True (inlineEnvironment <|> inlineCommand')
178+ inlines
172179
173180-- inline elements:
174181
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+3−4
@@ -200,10 +200,9 @@ withVerbatimMode parser = do
200200 return result
201201
202202rawLaTeXParser :: (PandocMonad m, HasMacros s, HasReaderOptions s)
203− => Bool -> LP m a -> LP m a -> ParserT String s m (a, String)
204−rawLaTeXParser retokenize parser valParser = do
205− inp <- getInput
206− let toks = tokenize "source" $ T.pack inp
203+ => [Tok] -> Bool -> LP m a -> LP m a
204+ -> ParserT String s m (a, String)
205+rawLaTeXParser toks retokenize parser valParser = do
207206 pstate <- getState
208207 let lstate = def{ sOptions = extractReaderOptions pstate }
209208 let lstate' = lstate { sMacros = extractMacros pstate }