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:
  • right after parsing.
  • on the way back from a visit statement.
  • when a ConcreteSyntax expression is executed.
  • when a ParseTree is constructed "manually".
They can be used as a Disambiguation method, using the 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
    fail; // just build the parse tree "E = id: Id i", by defaulting to the constructor
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit