From 442eecc15c2b805872600e111a510e022d1920f7 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 6 May 2014 23:27:16 -0700 Subject: Textile reader: Rewrote simpleInline for clarity and efficiency. This way we only look once for the opening `[`. --- src/Text/Pandoc/Readers/Textile.hs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 622a41168..f83298d4c 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -381,6 +381,7 @@ inline = do -- | Inline parsers tried in order inlineParsers :: [Parser [Char] ParserState Inlines] inlineParsers = [ inlineMarkup + , groupedInlineMarkup , str , whitespace , endline @@ -602,17 +603,10 @@ surrounded :: Parser [Char] st t -- ^ surrounding parser surrounded border = enclosed (border *> notFollowedBy (oneOf " \t\n\r")) (try border) - simpleInline :: Parser [Char] ParserState t -- ^ surrounding parser - -> (Inlines -> Inlines) -- ^ Inline constructor - -> Parser [Char] ParserState Inlines -- ^ content parser (to be used repeatedly) -simpleInline border construct = groupedSimpleInline border construct - <|> ungroupedSimpleInline border construct - -ungroupedSimpleInline :: Parser [Char] ParserState t -- ^ surrounding parser - -> (Inlines -> Inlines) -- ^ Inline constructor - -> Parser [Char] ParserState Inlines -- ^ content parser (to be used repeatedly) -ungroupedSimpleInline border construct = try $ do + -> (Inlines -> Inlines) -- ^ Inline constructor + -> Parser [Char] ParserState Inlines -- ^ content parser (to be used repeatedly) +simpleInline border construct = try $ do st <- getState pos <- getPosition let afterString = stateLastStrPos st == Just pos @@ -627,13 +621,11 @@ ungroupedSimpleInline border construct = try $ do then body else B.spanWith attr body -groupedSimpleInline :: Parser [Char] ParserState t - -> (Inlines -> Inlines) - -> Parser [Char] ParserState Inlines -groupedSimpleInline border construct = try $ do +groupedInlineMarkup :: Parser [Char] ParserState Inlines +groupedInlineMarkup = try $ do char '[' sp1 <- option mempty $ B.space <$ whitespace - result <- withQuoteContext InSingleQuote (simpleInline border construct) + result <- withQuoteContext InSingleQuote inlineMarkup sp2 <- option mempty $ B.space <$ whitespace char ']' return $ sp1 <> result <> sp2 -- cgit v1.2.3