git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: simplified type on doMacros'.
5bd852cJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+1−1
@@ -1509,7 +1509,7 @@ letmacro = do
1509 -- \let\foo hello if we have previously \def\bar{hello}
1509 -- \let\foo hello if we have previously \def\bar{hello}
1510 contents <- bracedOrToken
1510 contents <- bracedOrToken
1511 return (name, contents)
1511 return (name, contents)
1512− contents' <- fromMaybe contents <$> doMacros' 0 contents
1512+ contents' <- doMacros' 0 contents
1513 return (name, Macro ExpandWhenDefined [] Nothing contents')
1513 return (name, Macro ExpandWhenDefined [] Nothing contents')
1514
1514
1515defmacro :: PandocMonad m => LP m (Text, Macro)
1515defmacro :: PandocMonad m => LP m (Text, Macro)
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+8−11
@@ -389,13 +389,10 @@ doMacros = do
389 expanded <- sExpanded <$> getState
389 expanded <- sExpanded <$> getState
390 verbatimMode <- sVerbatimMode <$> getState
390 verbatimMode <- sVerbatimMode <$> getState
391 unless (expanded || verbatimMode) $ do
391 unless (expanded || verbatimMode) $ do
392− mbNewInp <- getInput >>= doMacros' 1
392+ getInput >>= doMacros' 1 >>= setInput
393− case mbNewInp of
394− Nothing -> return ()
395− Just inp -> setInput inp
396 updateState $ \st -> st{ sExpanded = True }
393 updateState $ \st -> st{ sExpanded = True }
397
394
398−doMacros' :: PandocMonad m => Int -> [Tok] -> LP m (Maybe [Tok])
395+doMacros' :: PandocMonad m => Int -> [Tok] -> LP m [Tok]
399doMacros' n inp = do
396doMacros' n inp = do
400 case inp of
397 case inp of
401 Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
398 Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" :
@@ -405,10 +402,11 @@ doMacros' n inp = do
405 Tok _ Word name : Tok _ Symbol "}" : ts
402 Tok _ Word name : Tok _ Symbol "}" : ts
406 -> handleMacros n spos ("end" <> name) ts
403 -> handleMacros n spos ("end" <> name) ts
407 Tok _ (CtrlSeq "expandafter") _ : t : ts
404 Tok _ (CtrlSeq "expandafter") _ : t : ts
408− -> (fmap (combineTok t)) <$> doMacros' n ts
405+ -> combineTok t <$> doMacros' n ts
409 Tok spos (CtrlSeq name) _ : ts
406 Tok spos (CtrlSeq name) _ : ts
410 -> handleMacros n spos name ts
407 -> handleMacros n spos name ts
411− _ -> return Nothing
408+ _ -> return inp
409+ <|> return inp
412
410
413 where
411 where
414 combineTok (Tok spos (CtrlSeq name) x) (Tok _ Word w : ts)
412 combineTok (Tok spos (CtrlSeq name) x) (Tok _ Word w : ts)
@@ -454,7 +452,7 @@ doMacros' n inp = do
454 $ throwError $ PandocMacroLoop (T.unpack name)
452 $ throwError $ PandocMacroLoop (T.unpack name)
455 macros <- sMacros <$> getState
453 macros <- sMacros <$> getState
456 case M.lookup name macros of
454 case M.lookup name macros of
457− Nothing -> return Nothing
455+ Nothing -> mzero
458 Just (Macro expansionPoint argspecs optarg newtoks) -> do
456 Just (Macro expansionPoint argspecs optarg newtoks) -> do
459 let getargs' = do
457 let getargs' = do
460 args <- case optarg of
458 args <- case optarg of
@@ -475,9 +473,8 @@ doMacros' n inp = do
475 -- expand #1 etc.)
473 -- expand #1 etc.)
476 let result = foldr (addTok False args spos) rest newtoks
474 let result = foldr (addTok False args spos) rest newtoks
477 case expansionPoint of
475 case expansionPoint of
478− ExpandWhenUsed ->
476+ ExpandWhenUsed -> doMacros' (n' + 1) result
479− maybe (Just result) Just <$> doMacros' (n' + 1) result
480− ExpandWhenDefined -> return $ Just result
477+ ExpandWhenDefined -> return result
481
478
482setpos :: SourcePos -> Tok -> Tok
479setpos :: SourcePos -> Tok -> Tok
483setpos spos (Tok _ tt txt) = Tok spos tt txt
480setpos spos (Tok _ tt txt) = Tok spos tt txt