From 1d8fe2653a7e67da06c15588a5940b20b0d8587e Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Tue, 28 Aug 2007 02:33:53 +0000 Subject: Performance improvements: + Rearranged parsers in definition of 'inline' so that the most frequently used would (by and large) be tried first. + Removed some unneeded 'try's. + Removed tabchar parser, as whitespace handles tabs anyway. + All in all, these changes, together with the last two commits, cut almost in half the time it takes pandoc to parse a large test file. git-svn-id: https://pandoc.googlecode.com/svn/trunk@924 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index ed447e9c6..eedf0311d 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -617,6 +617,11 @@ table = failIfStrict >> (simpleTable <|> multilineTable) "table" inline = choice [ rawLaTeXInline' , escapedChar + , smartPunctuation + , linebreak + , endline + , whitespace + , str , charRef , note , inlineNote @@ -631,15 +636,9 @@ inline = choice [ rawLaTeXInline' , strikeout , superscript , subscript - , smartPunctuation , code - , ltSign , symbol - , str - , linebreak - , tabchar - , whitespace - , endline ] "inline" + , ltSign ] "inline" escapedChar = try $ do char '\\' @@ -649,10 +648,11 @@ escapedChar = try $ do else satisfy (not . isAlphaNum) return $ Str [result] -ltSign = try $ do - notFollowedBy (noneOf "<") -- continue only if it's a < - notFollowedBy' rawHtmlBlocks -- don't return < if it starts html - char '<' +ltSign = do + st <- getState + if stateStrict st + then char '<' + else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html return $ Str ['<'] specialCharsMinusLt = filter (/= '<') specialChars @@ -760,8 +760,6 @@ emDash = try $ skipSpaces >> oneOfStrings ["---", "--"] >> whitespace = (many1 (oneOf spaceChars) >> return Space) "whitespace" -tabchar = tab >> return (Str "\t") - -- hard line break linebreak = try $ oneOf spaceChars >> many1 (oneOf spaceChars) >> endline >> return LineBreak -- cgit v1.2.3