diff options
author | John MacFarlane <jgm@berkeley.edu> | 2011-01-19 15:06:56 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2011-01-19 15:06:56 -0800 |
commit | a400cfe10f0a1c29a6dd2b3a7d2a73f25d0fa981 (patch) | |
tree | e83e2eb4e72165e447da3eba5968640edddba82d /src/Text/Pandoc | |
parent | c09518eefd0c1aadf705b13acedb73ed61d2a809 (diff) | |
download | pandoc-a400cfe10f0a1c29a6dd2b3a7d2a73f25d0fa981.tar.gz |
Replaced uses of oneOf with more efficient parsers.
This speeds up the markdown reader.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 4ab3f9275..e3258f1a9 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -57,11 +57,17 @@ readMarkdown state s = (readWith parseMarkdown) state (s ++ "\n\n") -- Constants and data structure definitions -- -bulletListMarkers :: [Char] -bulletListMarkers = "*+-" - -hruleChars :: [Char] -hruleChars = "*-_" +isBulletListMarker :: Char -> Bool +isBulletListMarker '*' = True +isBulletListMarker '+' = True +isBulletListMarker '-' = True +isBulletListMarker _ = False + +isHruleChar :: Char -> Bool +isHruleChar '*' = True +isHruleChar '-' = True +isHruleChar '_' = True +isHruleChar _ = False setextHChars :: [Char] setextHChars = "=-" @@ -132,7 +138,8 @@ authorsLine :: GenParser Char ParserState [[Inline]] authorsLine = try $ do char '%' skipSpaces - authors <- sepEndBy (many (notFollowedBy (oneOf ";\n") >> inline)) + authors <- sepEndBy (many (notFollowedBy (satisfy $ \c -> + c == ';' || c == '\n') >> inline)) (char ';' <|> try (newline >> notFollowedBy blankline >> spaceChar)) newline @@ -201,9 +208,9 @@ referenceKey = try $ do let nl = char '\n' >> notFollowedBy blankline >> return ' ' let sourceURL = liftM unwords $ many $ try $ do notFollowedBy' referenceTitle - skipMany (oneOf " \t") + skipMany spaceChar optional nl - skipMany (oneOf " \t") + skipMany spaceChar notFollowedBy' reference many1 (noneOf " \t\n") let betweenAngles = try $ char '<' >> @@ -335,7 +342,7 @@ setextHeader = try $ do hrule :: GenParser Char st Block hrule = try $ do skipSpaces - start <- oneOf hruleChars + start <- satisfy isHruleChar count 2 (skipSpaces >> char start) skipMany (spaceChar <|> char start) newline @@ -493,7 +500,7 @@ bulletListStart = try $ do optional newline -- if preceded by a Plain block in a list context skipNonindentSpaces notFollowedBy' hrule -- because hrules start out just like lists - oneOf bulletListMarkers + satisfy isBulletListMarker spaceChar skipSpaces @@ -1098,9 +1105,9 @@ source' = do let nl = char '\n' >>~ notFollowedBy blankline let sourceURL = liftM unwords $ many $ try $ do notFollowedBy' linkTitle - skipMany (oneOf " \t") + skipMany spaceChar optional nl - skipMany (oneOf " \t") + skipMany spaceChar many1 (noneOf " \t\n") let betweenAngles = try $ char '<' >> manyTill (noneOf ">\n" <|> nl) (char '>') |