From fa255f68ba4d75e327427ed9802ac7484fe03e63 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 5 Dec 2011 20:54:46 -0800 Subject: Parsing: Removed charsInBalanced', added param to charsInBalanced. The extra parameter is a character parser. This is needed for proper handling of escapes, etc. --- src/Text/Pandoc/Parsing.hs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index acfdda2c4..937deb484 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -42,7 +42,6 @@ module Text.Pandoc.Parsing ( (>>~), parseFromString, lineClump, charsInBalanced, - charsInBalanced', romanNumeral, emailAddress, uri, @@ -174,29 +173,23 @@ lineClump = blanklines -- | Parse a string of characters between an open character -- and a close character, including text between balanced -- pairs of open and close, which must be different. For example, --- @charsInBalanced '(' ')'@ will parse "(hello (there))" --- and return "hello (there)". Stop if a blank line is --- encountered. -charsInBalanced :: Char -> Char -> GenParser Char st String -charsInBalanced open close = try $ do +-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))" +-- and return "hello (there)". +charsInBalanced :: Char -> Char -> GenParser Char st Char + -> GenParser Char st String +charsInBalanced open close parser = try $ do char open - raw <- many $ (many1 (satisfy $ \c -> - c /= open && c /= close && c /= '\n')) - <|> (do res <- charsInBalanced open close - return $ [open] ++ res ++ [close]) - <|> try (string "\n" >>~ notFollowedBy' blanklines) + let isDelim c = c == open || c == close + raw <- many $ many1 (notFollowedBy (satisfy isDelim) >> parser) + <|> (do res <- charsInBalanced open close parser + return $ [open] ++ res ++ [close]) char close return $ concat raw --- | Like @charsInBalanced@, but allow blank lines in the content. -charsInBalanced' :: Char -> Char -> GenParser Char st String -charsInBalanced' open close = try $ do - char open - raw <- many $ (many1 (satisfy $ \c -> c /= open && c /= close)) - <|> (do res <- charsInBalanced' open close - return $ [open] ++ res ++ [close]) - char close - return $ concat raw +-- old charsInBalanced would be: +-- charsInBalanced open close (noneOf "\n" <|> char '\n' >> notFollowedBy blankline) +-- old charsInBalanced' would be: +-- charsInBalanced open close anyChar -- Auxiliary functions for romanNumeral: -- cgit v1.2.3