[antlr-interest] Text attribute for tree parser rule not working
Richard Thrippleton
richard.thrippleton at progress.com
Thu Jun 24 05:09:48 PDT 2010
Jan F wrote:
> 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.
By my understanding the .text attribute on a tree-walker rule will only
return you the text from the top node of the tree. Is your parser
constructing the BYINDEX / BYFIELD tokens with any useful text in them? By
default, imaginary nodes get constructed with empty text.
Richard
--
\o/
More information about the antlr-interest
mailing list