From 1bc585837c75f9ab21e49e2dccb6bcd905b1a5bc Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sun, 7 Jan 2007 00:48:46 +0000 Subject: Fixed performance problems with '--strict' option: + Replaced skipEndline with "option ' ' newline" where possible. + Replaced "notFollowedBy' header" in definition of endline with a faster but equally accurate test for a folliwng header. + Removed check at the beginning of 'reference' for a noteStart: This is not needed, because note comes before referenceKey in the definition of block. + Replaced check for a following anyHtmlBlockTag in autoLink with a check for anyHtmlTag or anyHtmlEndTag. + Other small code cleanups. git-svn-id: https://pandoc.googlecode.com/svn/trunk@444 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Readers/Markdown.hs | 32 +++++++++++++++++--------------- src/Text/ParserCombinators/Pandoc.hs | 3 +-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index ba4274c1c..b578e85c9 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -285,7 +285,7 @@ note = try (do ref <- noteMarker char ':' skipSpaces - skipEndline + skipEndline raw <- sepBy rawLines (try (do {blankline; indentSpaces})) option "" blanklines -- parse the extracted text, which may contain various block elements: @@ -510,7 +510,7 @@ referenceKey = try (do blanklines state <- getState let keysUsed = stateKeysUsed state - updateState (\st -> st { stateKeysUsed = (label:keysUsed) }) + setState state { stateKeysUsed = (label:keysUsed) } return $ Key label (Src (removeTrailingSpace src) tit)) -- @@ -652,7 +652,6 @@ emDash = try (do skipSpaces oneOfStrings ["---", "--"] skipSpaces - option ' ' newline return EmDash) whitespace = do @@ -684,7 +683,9 @@ endline = try (do if stateStrict st then do notFollowedBy' emailBlockQuoteStart - notFollowedBy' header + notFollowedBy (char atxHChar) -- atx header + notFollowedBy (try (do{manyTill anyChar newline; + oneOf setextHChars})) -- setext header else return () -- parse potential list-starts differently if in a list: if (stateParserContext st) == ListItemState @@ -705,7 +706,6 @@ rawLabel = try $ do -- a reference label for a link reference = try $ do - notFollowedBy (try (do{char labelStart; char noteStart})) raw <- rawLabel oldInput <- getInput setInput raw @@ -726,13 +726,13 @@ source = try (do titleWith startChar endChar = try (do skipSpaces - skipEndline -- a title can be on the next line from the source + option ' ' newline -- a title can be on the next line from the source skipSpaces char startChar tit <- manyTill anyChar (try (do char endChar skipSpaces - followedBy' (char ')' <|> newline))) + notFollowedBy (noneOf ")\n"))) let tit' = gsub "\"" """ tit return tit') @@ -753,13 +753,14 @@ referenceLink = choice [referenceLinkDouble, referenceLinkSingle] referenceLinkDouble = try (do label <- reference skipSpaces - skipEndline + option ' ' newline skipSpaces ref <- reference let ref' = if null ref then label else ref state <- getState if ref' `elem` (stateKeysUsed state) - then return () else fail "no corresponding key" + then return () + else fail "no corresponding key" return (Link label (Ref ref'))) -- a link like [this] @@ -767,12 +768,13 @@ referenceLinkSingle = try (do label <- reference state <- getState if label `elem` (stateKeysUsed state) - then return () else fail "no corresponding key" + then return () + else fail "no corresponding key" return (Link label (Ref label))) -- a link autoLink = try (do - notFollowedBy' anyHtmlBlockTag + notFollowedBy' (anyHtmlTag <|> anyHtmlEndTag) src <- between (char autoLinkStart) (char autoLinkEnd) (many (noneOf (spaceChars ++ endLineChars ++ [autoLinkEnd]))) case (matchRegex emailAddress src) of @@ -797,7 +799,7 @@ noteRef = try (do ref <- noteMarker state <- getState let identifiers = (stateNoteIdentifiers state) ++ [ref] - updateState (\st -> st {stateNoteIdentifiers = identifiers}) + setState state {stateNoteIdentifiers = identifiers} return (NoteRef (show (length identifiers)))) inlineNote = try (do @@ -809,9 +811,9 @@ inlineNote = try (do let identifiers = stateNoteIdentifiers state let ref = show $ (length identifiers) + 1 let noteBlocks = stateNoteBlocks state - updateState (\st -> st {stateNoteIdentifiers = (identifiers ++ [ref]), - stateNoteBlocks = - (Note ref [Para contents]):noteBlocks}) + setState state {stateNoteIdentifiers = (identifiers ++ [ref]), + stateNoteBlocks = + (Note ref [Para contents]):noteBlocks} return (NoteRef ref)) rawLaTeXInline' = do diff --git a/src/Text/ParserCombinators/Pandoc.hs b/src/Text/ParserCombinators/Pandoc.hs index 55481b8dc..b55ceb23d 100644 --- a/src/Text/ParserCombinators/Pandoc.hs +++ b/src/Text/ParserCombinators/Pandoc.hs @@ -81,8 +81,7 @@ blankline = try (do -- | Parses one or more blank lines and returns a string of newlines. blanklines :: GenParser Char st [Char] -blanklines = try (do - many1 blankline) +blanklines = try (many1 blankline) -- | Parses backslash, then applies character parser. escaped :: GenParser Char st Char -- ^ Parser for character to escape -- cgit v1.2.3