Rascal implements the Visitor pattern for this. You could do something like this on your ast
variable:
visit(ast){
case \if(icond,ithen,ielse): {
println(" if-then-else statement with condition <icond> found"); }
case \if(icond,ithen): {
println(" if-then statement with condition <icond> found"); }
};
This example returns the if
statements from the code.
You can find the definitions of patterns to use as case patterns in the package lang::java::m3::AST.