pRepeat
Returns a Parser that runs parser exactly count times in sequence, collecting each output into a List.
The runs are applied left-to-right; each run starts where the previous one left off. If any run fails the whole parser fails at that position, without consuming the tokens matched by the successful preceding runs.
A count of zero always succeeds immediately with an empty list.
Behaviour
| Condition | Result |
|---|---|
count == 0 | Success with an empty list; index unchanged |
| All count runs succeed | Success with a list of count values; index advanced past all |
| Any run fails | Failure from that run |
Type parameters
O — the output type of parser; each successful value is collected.
U — the user context type threaded through unchanged.
Example
val digit = pSatisfy<Char, Unit> { it.isDigit() }
val threeDigits = pRepeat(3, digit)
val input = ParserInput.of("123x".toList(), Unit)
val result = threeDigits(input) // Success(['1','2','3'], nextIndex=3, ...)Content copied to clipboard
Return
Parameters
count
the exact number of times to run parser; must be >= 0.
parser
the parser to repeat.