summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Parsing.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2011-12-05 20:54:46 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2011-12-05 20:54:46 -0800
commitfa255f68ba4d75e327427ed9802ac7484fe03e63 (patch)
tree7fc65d61926384a92cfc04b201f62deb1c81164f /src/Text/Pandoc/Parsing.hs
parentc39cdc15baaded62b5af066d99dd779120f7b298 (diff)
Parsing: Removed charsInBalanced', added param to charsInBalanced.
The extra parameter is a character parser. This is needed for proper handling of escapes, etc.
Diffstat (limited to 'src/Text/Pandoc/Parsing.hs')
-rw-r--r--src/Text/Pandoc/Parsing.hs33
1 files changed, 13 insertions, 20 deletions
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: