更新时间:2023-12-01 18:17:10
我相信这是一个错误.在运行时源代码中,最新javascript运行时(4.5.2)中的ParseTreeVisitor.visit
与python2版本(4.5.3)略有不同.在python2版本中,ParseTreeVisitor.visit
利用RuleContext.accept
方法来触发不同的访问者事件.我以为Antlr4的开发人员忘了更新javascript运行时.
I believed this is a bug. In runtime source code, ParseTreeVisitor.visit
in the latest javascript runtime(4.5.2) is a bit different from python2 version(4.5.3). In python2 version, ParseTreeVisitor.visit
leverage RuleContext.accept
method to trigger different visitor events. I assumed developers of Antlr4 forgot to update javascript runtime.
有一个快速的解决方法.
There is quick workaround.
antlr4/tree/Tree.js
antlr4/tree/Tree.js
ParseTreeVisitor.prototype.visit = function(ctx) {
// if (Utils.isArray(ctx)) {
// var self = this;
// return ctx.map(function(child) { return visitAtom(self, child)});
// } else {
// return visitAtom(this, ctx);
// }
return ctx.accept(this)
};
有一种不修改库函数的更好方法.
There is a better way which doesn't modify library function.
ValidatorVisitor.prototype.visitExpr = function(ctx) {
return ctx.accept(this);
}