git.iko.soy/typeable/pandoc
on master help sign in
Parsing: Removed charsInBalanced', added param to charsInBalanced.
fa255f6John MacFarlane
src/Text/Pandoc/Parsing.hs+13−20
@@ -42,7 +42,6 @@ module Text.Pandoc.Parsing ( (>>~),
42 parseFromString,
42 parseFromString,
43 lineClump,
43 lineClump,
44 charsInBalanced,
44 charsInBalanced,
45− charsInBalanced',
46 romanNumeral,
45 romanNumeral,
47 emailAddress,
46 emailAddress,
48 uri,
47 uri,
@@ -174,29 +173,23 @@ lineClump = blanklines
174-- | Parse a string of characters between an open character
173-- | Parse a string of characters between an open character
175-- and a close character, including text between balanced
174-- and a close character, including text between balanced
176-- pairs of open and close, which must be different. For example,
175-- pairs of open and close, which must be different. For example,
177−-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
176+-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
178−-- and return "hello (there)". Stop if a blank line is
177+-- and return "hello (there)".
179−-- encountered.
180−charsInBalanced :: Char -> Char -> GenParser Char st String
178+charsInBalanced :: Char -> Char -> GenParser Char st Char
179+ -> GenParser Char st String
181−charsInBalanced open close = try $ do
180+charsInBalanced open close parser = try $ do
182 char open
181 char open
182+ let isDelim c = c == open || c == close
183− raw <- many $ (many1 (satisfy $ \c ->
183+ raw <- many $ many1 (notFollowedBy (satisfy isDelim) >> parser)
184− c /= open && c /= close && c /= '\n'))
185− <|> (do res <- charsInBalanced open close
184+ <|> (do res <- charsInBalanced open close parser
186− return $ [open] ++ res ++ [close])
185+ return $ [open] ++ res ++ [close])
187− <|> try (string "\n" >>~ notFollowedBy' blanklines)
188 char close
186 char close
189 return $ concat raw
187 return $ concat raw
190
188
191−-- | Like @charsInBalanced@, but allow blank lines in the content.
189+-- old charsInBalanced would be:
192−charsInBalanced' :: Char -> Char -> GenParser Char st String
193−charsInBalanced' open close = try $ do
190+-- charsInBalanced open close (noneOf "\n" <|> char '\n' >> notFollowedBy blankline)
194− char open
195− raw <- many $ (many1 (satisfy $ \c -> c /= open && c /= close))
196− <|> (do res <- charsInBalanced' open close
191+-- old charsInBalanced' would be:
197− return $ [open] ++ res ++ [close])
192+-- charsInBalanced open close anyChar
198− char close
199− return $ concat raw
200
193
201-- Auxiliary functions for romanNumeral:
194-- Auxiliary functions for romanNumeral:
202
195