From 85394d403464f25db2ffd586dcc9893fc984877c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 15 Oct 2018 17:28:37 -0700 Subject: LaTeX reader: small verbatim mode cleanups. --- src/Text/Pandoc/Readers/LaTeX.hs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/Text/Pandoc/Readers') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 543ebec5a..26ac781db 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1525,11 +1525,11 @@ defmacro = try $ argspecArg :: PandocMonad m => LP m ArgSpec argspecArg = do - Tok _ (Arg i) _ <- withVerbatimMode $ satisfyTok isArgTok + Tok _ (Arg i) _ <- satisfyTok isArgTok return $ ArgNum i argspecPattern :: PandocMonad m => LP m ArgSpec -argspecPattern = withVerbatimMode $ +argspecPattern = Pattern <$> many1 (satisfyTok (\(Tok _ toktype' txt) -> (toktype' == Symbol || toktype' == Word) && (txt /= "{" && txt /= "\\" && txt /= "}"))) @@ -1566,25 +1566,23 @@ newenvironment = do Tok _ (CtrlSeq mtype) _ <- controlSeq "newenvironment" <|> controlSeq "renewenvironment" <|> controlSeq "provideenvironment" - name <- withVerbatimMode $ do + withVerbatimMode $ do optional $ symbol '*' spaces - untokenize <$> braced - numargs <- withVerbatimMode $ do + name <- untokenize <$> braced spaces - option 0 $ try bracketedNum - let argspecs = map (\i -> ArgNum i) [1..numargs] - optarg <- withVerbatimMode $ do + numargs <- option 0 $ try bracketedNum spaces - option Nothing $ Just <$> try bracketedToks - startcontents <- withVerbatimMode $ spaces >> bracedOrToken - endcontents <- withVerbatimMode $ spaces >> bracedOrToken - when (mtype == "newenvironment") $ do - macros <- sMacros <$> getState - case M.lookup name macros of - Just _ -> report $ MacroAlreadyDefined (T.unpack name) pos - Nothing -> return () - return (name, Macro ExpandWhenUsed argspecs optarg startcontents, + optarg <- option Nothing $ Just <$> try bracketedToks + let argspecs = map (\i -> ArgNum i) [1..numargs] + startcontents <- spaces >> bracedOrToken + endcontents <- spaces >> bracedOrToken + when (mtype == "newenvironment") $ do + macros <- sMacros <$> getState + case M.lookup name macros of + Just _ -> report $ MacroAlreadyDefined (T.unpack name) pos + Nothing -> return () + return (name, Macro ExpandWhenUsed argspecs optarg startcontents, Macro ExpandWhenUsed [] Nothing endcontents) bracketedNum :: PandocMonad m => LP m Int -- cgit v1.2.3