1
好的,所以我想在访问它时访问节点的注释。举个例子:Rascal AST访问访问注释
visit (myAST) {
case someNode(str name): {
// How do I now access the @src annotation of someNode here?
}
};
我已经尝试了以下但这不起作用:
visit (myAST) {
case someNode(str name): {
parents = getTraversalContext();
iprintln(parents[0]); // This print shows someNode with the @src annotation.
iprintln(parents[0]@src); // This gives the error: get-annotation not supported on value at...
}
};
什么我错在这里做什么?我的方法错了吗?
如果您将'parents [0]'与声明注释的类型或针对'node'匹配,则第二种解决方案将起作用。这是因为'getAnnotation'函数只为'node'定义,而不是'value'。然而,保罗的解决方案是优先于使用'getTraversalContext' – jurgenv