list
Parsing expression that represents a list of elements with the optionally defined separator, prefix, and postfix. Optionally you can also define the allowed size of the list, both min and max.
It worth noting that the resulting list will contain only its elements.
Samples
import io.kpeg.pe.Symbol.Rule
fun main() {
//sampleStart
// Array of digits
// [1,3,6,2] - OK - listOf('1', '3', '6', '2')
// [2] - OK - listOf('2')
// [] - OK - listOf()
// [a, 3] - FAIL
// 1, 2 - FAIL
// [1, 2 - FAIL
// 1, 2] - FAIL
// [1; 2] - FAIL
DIGIT // EvalPE<Char>
.list(
separator = char(','),
prefix = char('['),
postfix = char(']'), // EvalPE<List<Char>>
) // DOES NOT CONTAIN '[', ']', and ','
//sampleEnd
}
Sources
JVM source
Link copied to clipboard