seq

fun <T> seq(b: SequenceBuilderBlock<T>): EvalPE<T>

Sequence of parsing expressions, defined inside the b block. To register an element of the sequence, use the unary plus on any parsing expression inside the b block. You also must use the value block, which yields the result of this operator.

Samples

import io.kpeg.pe.Symbol.Rule
fun main() { 
   //sampleStart 
   // John 42     - OK
// John 402    - OK
// John -4     - FAIL
// John 0      - OK
// John 034034 - OK
// Jon 42      - FAIL

data class Person(val name: String, val age: Int)

seq<Person> {
    val name = +literal("John")                  // EvalPE<String>
    val age =
        +DIGIT.oneOrMore()                       // EvalPE<List<Char>>
            .joinToString().mapPe { it.toInt() } // EvalPE<Int>

    value { Person(name.get, age.get) }
}                                                // EvalPE<Person> 
   //sampleEnd
}

Sources

JVM source
Link copied to clipboard