【发布时间】:2016-05-24 07:15:02
【问题描述】:
好的,所以我想在访问节点时访问它的注释。举个例子:
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
标签: rascal