[antlr-interest] Text attribute for tree parser rule not working
Jan F
netjan42 at gmail.com
Wed Jun 23 07:53:48 PDT 2010
Hello fellow ANTLRs, I have a problem with obtaining text and positions for
one of my rules ion a tree walker, and since I ran out of ideas on what
might be wrong I am here to ask :-)
My rule looks like this:
memberExpression returns [ Expression expression = null ]
@after { post ($expression, $memberExpression.start,
$memberExpression.text); }
: ^( BYINDEX parenLeftHandSideExpression expressionSt ) {
$expression = new NIndexRefExpression (0, 0,
$parenLeftHandSideExpression.expression, $expressionSt.statement);
}
| ^( BYFIELD parenLeftHandSideExpression Identifier ) {
$expression = new NFieldRefExpression (0, 0,
$parenLeftHandSideExpression.expression, $Identifier.text);
}
;
and the problem is that $memberExpression.text returns empty string, caused
by the fact that $memberExpression.start has the start/stop indexes as -1.
I have a second rule for something else, which looks very similar, and that
one (as well as all others) work perfectly fine, the $rule.text containing
the text corresponding to what the rule matched.
Any ideas why this may be happening?
-Jan
More information about the antlr-interest
mailing list