add

Add an OrderToken to the orderNodes


Add an OrderFragment to the orderNodes. All instances of the fragment object are removed from the list before the OrderNode from fragment is added.

The reason why all instances of fragment are removed is to ensure consistent behavior of de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.or. de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.or might receive OrderFragments as arguments. OrderFragments can only be built with Order DSL functions which will add their resulting OrderFragment directly to the orderNodes list. This means that de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.or must remove the OrderFragments from the orderNodes list to prevent them from appearing multiple times. An example would be:

order {
maybe(TestClass::a)
maybe(TestClass::a) or some(TestClass::b)
}

The regex would be (a* (a* | b+)). If the OrderFragments from maybe(TestClass::a) and some(TestClass::b) were not removed from the orderNodes, the regex would be (a* a* b+ (a* | b+)) which is incorrect.

However, problems arise if we consider a second example:

order {
val maybeA = maybe(TestClass::a)
maybeA or some(TestClass::b)
}

The desired regex would still be (a* (a* | b+)). However, this is a problem for de.fraunhofer.aisec.codyze.specificationLanguages.coko.core.dsl.or. It cannot differentiate if a OrderFragment was stored in a variable or not. Therefore, the OrderFragment is always removed. This means that the resulting regex is actually (a* | b+).

To resolve this inconsistency, we decided to disallow the same OrderFragment object (object reference equality, not functional equality) appearing multiple times in the orderNodes list. Instead, the last appearance is used as position for the OrderFragment object. This means, that for the example:

order {
val maybeA = maybe(TestClass::a)
add(maybeA)
some(TestClass::b)
add(maybeA)
}

the regex is (b+ a*).

If the desired regex is (a* a* b+ a*), please declare the a* with separate function calls like:

order {
maybe(TestClass::a)
maybe(TestClass::a)
some(TestClass::b)
maybe(TestClass::a)
}

fun add(op: Op): OrderNode(source)

Add an Op to the userDefinedOps.