好的,所以当我访问节点时,我想访问它的注释。举一个例子:
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...
}
};我在这里做错什么了?我的方法错了吗?
发布于 2016-05-24 08:12:01
好问题,最好的方法是引入一个变量,比如模式中的sn,并使用它来获取注释。
visit (myAST) {
case sn:someNode(str name): {
// Access the @src annotation of someNode here by sn@src
}
};顺便提一句:您使用的是函数getTraversalContext,但我强烈建议您避免使用它,因为它是实验性的,很可能在将来发生变化。承认:我们应该把它标记成这样。
https://stackoverflow.com/questions/37406762
复制相似问题