SequenceBuilder

class SequenceBuilder<T> : Operators

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
Value builder, you will interact with it only by using the value function.

Functions

and
Link copied to clipboard
fun and(pe: EvalPE<*>): EvalPE<Unit>
"And" predicate on the pe parsing expression.
char
Link copied to clipboard
fun char(c: Char): EvalPE<Char>
Parsing expression that represents the character c.
fun char(b: CharacterBuilderBlock): EvalPE<Char>
Parsing expression that represents any character that satisfies the b lambda.
fun char(r: CharRange): EvalPE<Char>
Parsing expression that represents any character in the char range r.
fun char(firstC: Char, secondC: Char, vararg otherCs: Char): EvalPE<Char>
Parsing expression that represents any character from the firstC, secondC, or otherCs characters.
choice
Link copied to clipboard
fun <T> choice(firstPe: EvalPE<T>, secondPe: EvalPE<T>, vararg otherPes: EvalPE<T>): EvalPE<T>
Prioritized choice of parsing expressions.
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>
This function works just like the joinToString from the standard library, but for the parsing expressions.
list
Link copied to clipboard
fun <T> EvalPE<T>.list(separator: EvalPE<*>? = null, prefix: EvalPE<*>? = null, postfix: EvalPE<*>? = null, min: UInt = 0u, max: UInt = UInt.MAX_VALUE): EvalPE<List<T>>
Parsing expression that represents a list of elements with the optionally defined separator, prefix, and postfix.
literal
Link copied to clipboard
fun literal(l: String): EvalPE<String>
Parsing expression that represents the literal l.
fun literal(len: Int, b: LiteralBuilderBlock): EvalPE<String>
Parsing expression that represents any literal of length len that satisfies the b lambda.
mapPe
Link copied to clipboard
fun <T, R> EvalPE<T>.mapPe(transform: MapBuilderBlock<T, R>): EvalPE<R>
Map parsing expression using the transform lambda.
not
Link copied to clipboard
fun not(pe: EvalPE<*>): EvalPE<Unit>
"Not" predicate on the pe parsing expression.
oneOrMore
Link copied to clipboard
fun <T> EvalPE<T>.oneOrMore(): EvalPE<List<T>>
Repeat parsing expression 1 or more times.
optional
Link copied to clipboard
fun <T> EvalPE<T>.optional(): EvalPE<Option<T>>
Optional parsing expression that yields Some value of the type T on successful parsing, or None otherwise.
orDefault
Link copied to clipboard
fun <T> EvalPE<T>.orDefault(value: T): EvalPE<T>
repeated
Link copied to clipboard
fun <T> EvalPE<T>.repeated(range: UIntRange): EvalPE<List<T>>
Repeat parsing expression an arbitrary number of times in the specified range.
fun <T> EvalPE<T>.repeated(min: UInt = 0u, max: UInt = UInt.MAX_VALUE): EvalPE<List<T>>
Repeat parsing expression from the min to the max numbers of times.
repeatedExactly
Link copied to clipboard
fun <T> EvalPE<T>.repeatedExactly(times: UInt): EvalPE<List<T>>
Repeat parsing expression exactly the given times.
seq
Link copied to clipboard
fun <T> seq(b: SequenceBuilderBlock<T>): EvalPE<T>
Sequence of parsing expressions, defined inside the b block.
unaryPlus
Link copied to clipboard
operator fun <T> EvalPE<T>.unaryPlus(): StoredPE<T>
Registers the parsing expression as an element of the sequence.
value
Link copied to clipboard
fun value(block: ValueBuilderBlock<T>)
Used to define the resulting value of the sequence.
zeroOrMore
Link copied to clipboard
fun <T> EvalPE<T>.zeroOrMore(): EvalPE<List<T>>
Repeat parsing expression 0 or more times.

Properties

ANY
Link copied to clipboard
val ANY: EvalPE<Char>
Parsing expression that represents any possible character.
DIGIT
Link copied to clipboard
val DIGIT: EvalPE<Char>
Parsing expression that represents any decimal digit, that is, any character in '0'..'9'.
HEX_DIGIT
Link copied to clipboard
val HEX_DIGIT: EvalPE<Char>
Parsing expression that represents any hexadecimal digit, that is, any character in '0'..'9', 'a'..'f', or 'A'..'F'.
LETTER
Link copied to clipboard
val LETTER: EvalPE<Char>
Parsing expression that represents any letter, that is, any character for which it.isLetter() equals true.

Sources

JVM source
Link copied to clipboard