@@ -40,6 +40,7 @@ module Text.Pandoc.Parsing ( takeWhileP,
4040 anyLineNewline,
4141 indentWith,
4242 many1Till,
43+ manyUntil,
4344 notFollowedBy',
4445 oneOfStrings,
4546 oneOfStringsCI,
@@ -325,6 +326,20 @@ many1Till p end = do
325326 rest <- manyTill p end
326327 return (first:rest)
327328
329+-- | Like @manyTill@, but also returns the result of end parser.
330+manyUntil :: (Stream s m t)
331+ => ParserT s u m a
332+ -> ParserT s u m b
333+ -> ParserT s u m ([a], b)
334+manyUntil p end = scan
335+ where scan =
336+ (do e <- end
337+ return ([], e)
338+ ) <|>
339+ (do x <- p
340+ (xs, e) <- scan
341+ return (x:xs, e))
342+
328343-- | A more general form of @notFollowedBy@. This one allows any
329344-- type of parser to be specified, and succeeds only if that parser fails.
330345-- It does not consume any input.