Optional- Additional conditions on the LHS part of rules

The optional block is working like the iterated block, but matches the contained subpattern at most once; further occurrences of the subpattern are left unmatched. If the nested pattern is available, it will get matched, otherwise it won’t; matching of the optional block will succeed either way.

Example code:

1  rule optionalBlock{
//checks if LegoPart fulfills a LegoFunction and prints a statement.
2    
3    part:LegoPart
4    
5    optional{
6      part -:Legofulfills->func:LegoFunction;
7      
8      modify{}
9    }
//if LegoPart fulfills LegoFunction func the optional block succeeds.
10   modify{
11     emit(part.name " fulfills " func.name ".");
12   }
//prints inserted statement.
13 }

This code example can be found in our Manual.

How to use it:

More Examples can be found in these Packages:

Was this article helpful?

Related Articles