repeated

fun <T, R> ExpectationReceiver<T>.repeated(min: Int? = null, max: Int? = null, itemBuilder: ItemExpectationBuilder<R>.() -> Unit): ExpectationStateCallbackBuilder<T, List<R>>

Repeatedly runs the provided expectations until they no longer match, then collects the items (specified via storeIn item in one of the expectations in the repeated block) into a list that you can then store.

Usage can look like this:

data class ManyWords(val words: List<String>)

val parser = niwenParser<ManyWords> {
ManyWords root {
repeated {
expect(Word) storeIn item
} storeIn ManyWords::words
}
}

Type inference failure

For whatever reason, when using the legacy Kotlin compiler (i.e. not K2), builder inference can sometimes fail when using repeated. In this case, manually provide type parameters, either where you use repeated or on the niwenParser root call.

The ultimate fix is to wait for when K2 is released.