From b1e71013933f0f5b98188639ea7e11f0c5f65ec8 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 28 Oct 2018 18:11:57 -0700 Subject: Roff tokenizer: refactor escString. --- src/Text/Pandoc/Readers/Roff.hs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Roff.hs b/src/Text/Pandoc/Readers/Roff.hs index 7bcf5305d..cf9056aa7 100644 --- a/src/Text/Pandoc/Readers/Roff.hs +++ b/src/Text/Pandoc/Readers/Roff.hs @@ -212,7 +212,7 @@ escapeNormal = do 'C' -> quoteArg >>= resolveGlyph '\'' 'f' -> escFont 's' -> escFontSize - '*' -> escStar + '*' -> escString '"' -> mempty <$ skipMany (satisfy (/='\n')) -- line comment '#' -> mempty <$ manyTill anyChar newline '%' -> return mempty @@ -568,23 +568,14 @@ lexArgs = do char '"' return [RoffStr "\""] -escStar :: PandocMonad m => RoffLexer m [LinePart] -escStar = try $ do +escString :: PandocMonad m => RoffLexer m [LinePart] +escString = try $ do pos <- getPosition - c <- anyChar - case c of - '(' -> do - cs <- count 2 anyChar - resolveString cs pos - '[' -> do - cs <- many (noneOf "\t\n\r ]") - char ']' - resolveString cs pos - 'S' -> return mempty -- switch back to default font size - _ -> resolveString [c] pos + (do cs <- escapeArg + resolveString cs pos) + <|> mempty <$ char 'S' where - -- strings and macros share namespace resolveString stringname pos = do RoffTokens ts <- resolveMacro stringname [] pos -- cgit v1.2.3