[antlr-interest] failed predicate problem
Michael Bedward
michael.bedward at gmail.com
Mon Mar 16 19:37:32 PDT 2009
So back to your rule...
callExpression
: ^(CALL_EXPRESSION memberExpression indexSuffix*
propertyReferenceSuffix* argumentSuffix*)
-> {$memberExpression.text.equals("Math.abs")}?
mathabs(x={$argumentSuffix.text})
-> /* discard rule */
;
You want to rewrite the node if memberExpression is "Math.abs" but
your specification of the new node
mathabs(x={$argumentSuffix.text})
...doesn't look right. It seems to have action syntax mixed up in it.
Shouldn't it be something like:
^(mathabs $argumentSuffix.text)
where mathabs is a rule already defined in your grammar. Or, it not
already defined then something like:
^(MATHABS $argumentSuffix.text)
where MATHABS appears in the tokens section of your tree rewriting grammar.
As an example, I have a tree grammar with this rewrite statement in it...
expr: ^(FUNC_CALL id=ID expr_list)
-> {isPosFunc($id.text)}?
IMAGE_POS_LOOKUP[getProxyVar($id.text)]
-> {isInfoFunc($id.text)}?
IMAGE_INFO_LOOKUP[getProxyVar($id.text)]
-> ^(FUNC_CALL ID expr_list)
where isPosFunc(), isInfoFunc() and getProxyVar are simple methods
defined in the members section of this grammar (just to keep the
grammar a little more readable).
I hope I'm answering the right question !
Michael
More information about the antlr-interest
mailing list