pSepBy1
fun <I : Any, O, S, U : Any> pSepBy1(item: Parser<I, O, U>, separator: Parser<I, S, U>): Parser<I, List<O>, U>
Returns a Parser that parses one or more occurrences of item separated by separator, collecting the item values (not the separators) into a non-empty List.
The grammar matched is item (separator item)*. The trailing separator, if present, is not consumed.
Behaviour
| Condition | Result |
|---|---|
| item fails on the first attempt | Failure from item |
| item succeeds N times (N ≥ 1) | Success with N values; index advanced past all items and separators |
Type parameters
I — the shared token type consumed by both parsers.
U — the user context type threaded through unchanged.
Example
val digit = pSatisfy<Char, Unit> { it.isDigit() }
val comma = pSatisfy<Char, Unit> { it == ',' }
val parser = pSepBy1(digit, comma)
val input = ParserInput.of("1,2,3".toList(), Unit)
val result = parser(input) // Success(['1','2','3'], nextIndex=5, ...)Content copied to clipboard
Return
a Parser that succeeds with a non-empty list of item values.
Parameters
item
the parser for each item.
separator
the parser for the delimiter between items; its value is discarded.