ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.
case 9:
localctx = new SubstringExprContext(this, new ExprContext(this, _parentctx, _parentState));
localctx.str = _prevctx;
this.pushNewRecursionContext(localctx, _startState, DeterminatorParser.RULE_expr);
this.state = 673;
if (!( this.precpred(this._ctx, 21))) {
throw new antlr4.error.FailedPredicateException(this, "this.precpred(this._ctx, 21)");
}
this.state = 674;
this.match(DeterminatorParser.OPEN_PAREN);
this.state = 675;
localctx.start = this.expr(0); // <== problem here
this.state = 676;
this.match(DeterminatorParser.COLON);
this.state = 677;
localctx.len = this.expr(0);
this.state = 678;
this.match(DeterminatorParser.CLOSE_PAREN);
break;
The line with the "problem here" comment illustrates the problem.
All context objects have "start" and "stop" attributes that reference Tokens. When this statement executes, it replaces my start token with with my start expression.
We should be able to work around it with a rename in our grammar, but there should probably be an error (at least some warning) during code generation if there are naming conflicts like this (better yet, some sort of renaming (i.e. conflict on "start" in grammar results in "_start" attribute in generated code)).
We have a grammar with this parser rule:
generated code includes the following:
The line with the "problem here" comment illustrates the problem.
All context objects have "start" and "stop" attributes that reference Tokens. When this statement executes, it replaces my start token with with my start expression.
We should be able to work around it with a rename in our grammar, but there should probably be an error (at least some warning) during code generation if there are naming conflicts like this (better yet, some sort of renaming (i.e. conflict on "start" in grammar results in "_start" attribute in generated code)).