From 37c29bfa3d3dda3cb4a59a3026c28c9cf202daba Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 6 Sep 2012 13:49:43 -0700 Subject: Textile reader: Improved speed of hyphenedWords. This speeds up the textile reader by about a factor of 4. But the reader is still very slow, compared to others readers. --- src/Text/Pandoc/Readers/Textile.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc/Readers/Textile.hs') diff --git a/src/Text/Pandoc/Readers/Textile.hs b/src/Text/Pandoc/Readers/Textile.hs index 1be2e3cd1..dc95d9a56 100644 --- a/src/Text/Pandoc/Readers/Textile.hs +++ b/src/Text/Pandoc/Readers/Textile.hs @@ -61,6 +61,7 @@ import Text.Pandoc.Parsing import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag ) import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock ) import Text.HTML.TagSoup.Match +import Data.List ( intercalate ) import Data.Char ( digitToInt, isUpper ) import Control.Monad ( guard, liftM ) import Control.Applicative ((<$>), (*>), (<*)) @@ -426,14 +427,15 @@ wordBoundaries = markupChars ++ stringBreakers -- | Parse a hyphened sequence of words hyphenedWords :: Parser [Char] ParserState String -hyphenedWords = try $ do +hyphenedWords = intercalate "-" <$> sepBy1 wordChunk (char '-') + +wordChunk :: Parser [Char] ParserState String +wordChunk = try $ do hd <- noneOf wordBoundaries tl <- many ( (noneOf wordBoundaries) <|> try (notFollowedBy' note *> oneOf markupChars <* lookAhead (noneOf wordBoundaries) ) ) - let wd = hd:tl - option wd $ try $ - (\r -> concat [wd, "-", r]) <$> (char '-' *> hyphenedWords) + return $ hd:tl -- | Any string str :: Parser [Char] ParserState Inline -- cgit v1.2.3