From 86cc8c8bf2e61c60d4aa98ed563ff36c77cfde98 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Wed, 29 Aug 2007 01:50:36 +0000 Subject: Rewrote charsInBalanced and charsInBalanced'. - Documented restriction: open and close must be distinct characters. - Rearranged options for greater efficiency. - Changed inner call to charsInBalanced inside charsInBalanced' to charsInBalanced'. git-svn-id: https://pandoc.googlecode.com/svn/trunk@951 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Shared.hs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index fe46bec97..ac22a6155 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -293,28 +293,28 @@ lineClump = do -- | Parse a string of characters between an open character -- and a close character, including text between balanced --- pairs of open and close. For example, +-- 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 char open - raw <- manyTill ( (do res <- charsInBalanced open close - return $ [open] ++ res ++ [close]) - <|> (do notFollowedBy (blankline >> blanklines >> return '\n') - count 1 anyChar)) - (char close) + raw <- many $ (many1 (noneOf [open, close, '\n'])) + <|> (do res <- charsInBalanced open close + return $ [open] ++ res ++ [close]) + <|> try (string "\n" >>~ notFollowedBy' blanklines) + 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 <- manyTill ( (do res <- charsInBalanced open close + raw <- many $ (many1 (noneOf [open, close])) + <|> (do res <- charsInBalanced' open close return $ [open] ++ res ++ [close]) - <|> count 1 anyChar) - (char close) + char close return $ concat raw -- | Parses a roman numeral (uppercase or lowercase), returns number. -- cgit v1.2.3