Sequence Builder
Sequence builder, you will interact with it only by using the seq operator. To register a parsing expression as an element of the sequence, use the unary plus operator. You also must use the value block, which yields the result of the sequence.
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
}
Types
ValueBuilder
Link copied to clipboard
object ValueBuilder
Content copied to clipboard
Value builder, you will interact with it only by using the value function.
Functions
char
Link copied to clipboard
joinToString
Link copied to clipboard
fun <T> EvalPE<List<T>>.joinToString(separator: CharSequence = "", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (T) -> CharSequence? = null): EvalPE<String>
Content copied to clipboard
This function works just like the joinToString from the standard library, but for the parsing expressions.
list
Link copied to clipboard
Parsing expression that represents a list of elements with the optionally defined separator, prefix, and postfix.
literal
Link copied to clipboard
orDefault
Link copied to clipboard
repeated
Link copied to clipboard
repeatedExactly
Link copied to clipboard
zeroOrMore
Link copied to clipboard
Repeat parsing expression 0 or more times.
Properties
ANY
Link copied to clipboard
Parsing expression that represents any possible character.
DIGIT
Link copied to clipboard
Parsing expression that represents any decimal digit, that is, any character in '0'..'9'.
HEX_DIGIT
Link copied to clipboard
Parsing expression that represents any hexadecimal digit, that is, any character in '0'..'9', 'a'..'f', or 'A'..'F'.
LETTER
Link copied to clipboard
Parsing expression that represents any letter, that is, any character for which
it.isLetter()
equals true
.Sources
JVM source
Link copied to clipboard