pMany
Returns a Parser that runs parser repeatedly until it fails, collecting each output into a List. Always succeeds, returning an empty list if parser fails on the first attempt.
pMany is the zero-or-more repetition combinator. For one-or-more, pair it with an initial required match using pAnd or pBind.
Note: parser must consume at least one token on each success. If it succeeds without advancing the index,
pManystops immediately to prevent an infinite loop.
Behaviour
| Condition | Result |
|---|---|
| parser fails on first attempt | Success with an empty list; index unchanged |
| parser succeeds N times then fails | Success with N values; index advanced past all |
| parser succeeds without advancing | Success with values collected so far; loop stops |
Type parameters
O — the output type of parser; each successful value is collected.
U — the user context type threaded through unchanged.
Example
val letter = pSatisfy<Char, Unit> { it.isLetter() }
val word = pMany(letter)
val input = ParserInput.of("abc!".toList(), Unit)
val result = word(input) // Success(['a','b','c'], nextIndex=3, ...)Content copied to clipboard
Return
a Parser that always succeeds with a (possibly empty) list of values.
Parameters
parser
the parser to run repeatedly.