git.iko.soy/typeable/pandoc
on master help sign in
Parsing: Removed charsInBalanced', added param to charsInBalanced.

The extra parameter is a character parser. This is needed for proper handling of escapes, etc.

commitfa255f68ba4d75e327427ed9802ac7484fe03e63 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 5 Dec 2011, 20:54 (15 years ago) parentc39cdc1
1 file changed+13−20
src/Text/Pandoc/Parsing.hs+13−20
src/Text/Pandoc/Parsing.hs+13−20
@@ -42,7 +42,6 @@ module Text.Pandoc.Parsing ( (>>~),
4242 parseFromString,
4343 lineClump,
4444 charsInBalanced,
45− charsInBalanced',
4645 romanNumeral,
4746 emailAddress,
4847 uri,
@@ -174,29 +173,23 @@ lineClump = blanklines
174173-- | Parse a string of characters between an open character
175174-- and a close character, including text between balanced
176175-- pairs of open and close, which must be different. For example,
177−-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
178−-- and return "hello (there)". Stop if a blank line is
179−-- encountered.
180−charsInBalanced :: Char -> Char -> GenParser Char st String
181−charsInBalanced open close = try $ do
176+-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
177+-- and return "hello (there)".
178+charsInBalanced :: Char -> Char -> GenParser Char st Char
179+ -> GenParser Char st String
180+charsInBalanced open close parser = try $ do
182181 char open
183− raw <- many $ (many1 (satisfy $ \c ->
184− c /= open && c /= close && c /= '\n'))
185− <|> (do res <- charsInBalanced open close
186− return $ [open] ++ res ++ [close])
187− <|> try (string "\n" >>~ notFollowedBy' blanklines)
182+ let isDelim c = c == open || c == close
183+ raw <- many $ many1 (notFollowedBy (satisfy isDelim) >> parser)
184+ <|> (do res <- charsInBalanced open close parser
185+ return $ [open] ++ res ++ [close])
188186 char close
189187 return $ concat raw
190188
191−-- | Like @charsInBalanced@, but allow blank lines in the content.
192−charsInBalanced' :: Char -> Char -> GenParser Char st String
193−charsInBalanced' open close = try $ do
194− char open
195− raw <- many $ (many1 (satisfy $ \c -> c /= open && c /= close))
196− <|> (do res <- charsInBalanced' open close
197− return $ [open] ++ res ++ [close])
198− char close
199− return $ concat raw
189+-- old charsInBalanced would be:
190+-- charsInBalanced open close (noneOf "\n" <|> char '\n' >> notFollowedBy blankline)
191+-- old charsInBalanced' would be:
192+-- charsInBalanced open close anyChar
200193
201194-- Auxiliary functions for romanNumeral:
202195