aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-06 13:49:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-06 14:08:59 -0700
commit37c29bfa3d3dda3cb4a59a3026c28c9cf202daba (patch)
tree2f9d57ad82abe43dd906499c7cd16c65056c9bb5
parentc2b520fb3602722d39031697227971a57e5bd0a2 (diff)
downloadpandoc-37c29bfa3d3dda3cb4a59a3026c28c9cf202daba.tar.gz
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.
-rw-r--r--Makefile2
-rw-r--r--src/Text/Pandoc/Readers/Textile.hs10
2 files changed, 7 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index b308d74c2..de807334b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,7 +7,7 @@ all:
cabal-dev configure --enable-tests --enable-benchmarks && cabal-dev build
prof:
- cabal-dev configure --enable-library-profiling --enable-executable-profiling && cabal-dev build
+ cabal-dev configure --enable-tests --enable-library-profiling --enable-executable-profiling && cabal-dev build
prep: pandoc-types citeproc-hs
cabal-dev install-deps --enable-library-profiling --enable-tests --enable-benchmarks
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