pMany1

fun <I : Any, O, U : Any> pMany1(parser: Parser<I, O, U>): Parser<I, List<O>, U>

Returns a Parser that runs parser one or more times, collecting each output into a List. Fails if parser does not match at least once.

Equivalent to requiring one mandatory match followed by pMany: the first run of parser must succeed, after which further runs are collected until failure.

Behaviour

ConditionResult
parser fails on first attemptFailure from parser
parser succeeds N times then fails (N ≥ 1)Success with N values; index advanced past all

Type parameters

  • I — the token type consumed by parser.

  • 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 digits = pMany1(digit)

val input = ParserInput.of("42!".toList(), Unit)
val result = digits(input) // Success(['4','2'], nextIndex=2, ...)

Return

a Parser that succeeds with a non-empty list, or fails if parser does not match at least once.

Parameters

parser

the parser to run one or more times.

See also