aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-08-29 01:50:36 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2007-08-29 01:50:36 +0000
commit86cc8c8bf2e61c60d4aa98ed563ff36c77cfde98 (patch)
tree4f330b62422c6dfed193aa9d7f38bdcf1bbeb5d1 /src
parent64023d8ba8fa1e8ed8bdc249fa3eb62d2f805c5a (diff)
downloadpandoc-86cc8c8bf2e61c60d4aa98ed563ff36c77cfde98.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Shared.hs18
1 files changed, 9 insertions, 9 deletions
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.