The thing is that Rascal data is immutable, so you can not update anything using an assignment. The assignment will simply give you a new binding for cx
with the annotation set, but will not change the original tree.
To change the original tree, you can either use the =>
operator for case statements, or the insert
statement as follows:
case LinkedList x => x[@parent=...] // replace x by a new x that is annotated
or:
case LinkedList x : {
...
x@parent= ...;
insert x; // replace original x by new x in tree
}
Some other tip, in the Traversal.rsc
library you can find a function called getTraversalContext()
which produces a list of parents of the currently visited node if called from the body of a case:
import Traversal;
visit (...) {
case somePattern: {
parents = getTraversalContext();
parent = parents[1];
}
}