either
fun <T> ExpectationReceiver<T>.either(branchBuilder: EitherBranchBuilder<T>.() -> Unit): EitherBuilder<T>
Build an "either" construct, with different branches the parsing process can take.
The branches are checked in the order they are declared.
Typical use may look like:
MyNode {
expect(...)
either {
// Expectations for branch one...
expect(tokenX1)
expect(OtherNode)
} or {
// Expectations for branch two...
expect(SomethingElse)
expect(tokenY2) storeIn "hello"
} or {
// Expectations for branch three
expect(EvenMoreDifferent)
}
expect(...)
}
Content copied to clipboard
Anything stored within a branch will be available for the constructed node, provided that the branch was executed.
Note: The lambda receives a builder for a single branch, but this function returns the builder for the entire either construct, meaning that:
You cannot add branches from a branch
The recommended way to add branches is to call or, like in the example above.