|
| |
| Navigation |
Synopsis Actions are functions that are called when parse trees are constructed (right after parsing).
Description A so-called Action is a normal rascal Function that overloads a SyntaxDefinition. A SyntaxDefinition, very similar to AlgebraicDataType definitions, defines a constructor for a parse tree node. This constructor is the default Function, and when it is overloaded by a non-default function this overloaded function will be tried first. You can overload any labeled SyntaxDefinition using the name of an alternative.
For example: syntax A = a: B C;
public A a(B b, C c) {
return f(b, c);
}
In this example Action function the a is replaced by whatever A the f function returns.
Actions are executed every time a parse tree is constructed:
filter statement, as in:
syntax E = id: Id i;
set[Id] types = {};
public E id(Id i) {
if (i in types)
filter; // remove this parse tree and all its parents up to the first amb node
else
fail; // just build the parse tree "E = id: Id i", by defaulting to the constructor
}
|