visitor-patternrascal

Rascal MPL print id of all traversed nodes in a visit


Is it possible to print all node ids / values that are traversed in a visit? Take the following code sample:

top-down visit(asts) {
    case x: println(typeOf(x));
}

I now get all types of the nodes that were visited. I would instead like to know the ids / values of all x that were encountered (without printing the entire tree). In other words, I am curious as to how Rascal traverses the list[Declaration] asts containing lang::java::m3::ASTs.

As a corrolary, is it possible to print direct ascendants / descendants of a Declaration regardless of their type? Or print the total number of children of an ast?

In the documentation (https://www.rascal-mpl.org/docs/rascal/expressions/visit/) there is no mention of this.


Solution