[antlr-interest] tree rewriting - change not propagating upwards
Michael Bedward
michael.bedward at gmail.com
Sun Nov 8 22:34:38 PST 2009
Hi folks,
I have a grammar to rewrite an AST, most of which works wonderfully
well. But one bit has had me pulling what remains of my hair out...
The relevant excerpts are:
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)
| var
| ...other stuff...
;
expr_list : ^(EXPR_LIST expr*)
;
var :ID
-> {isPosVar($ID.text)}? POS_VAR[$ID.text]
-> {isImageVar($ID.text)}? IMAGE_VAR[$ID.text]
-> {isLocalVar($ID.text)}? LOCAL_VAR[$ID.text]
-> {isJiffleConstant($ID.text)}? CONSTANT[$ID.text]
-> NON_LOCAL_VAR[$ID.text]
;
The "var" rule categorizes an ID token, using some helper methods, and
rewrites it as a specific token type. This works fine for most
expressions but doesn't seem to work when the expression (expr) is an
element in an expression list (expr_list) used with function calls.
When I follow the generated Java code in the debugger the rewriting
from ID to CONSTANT (for example) works. When the parser moves back up
to the expr_list rule the rewritten token is still visible. However,
when I get back to the FUNC_CALL branch of the expr rule the rewritten
token has been lost and there is just the original ID token type.
I know this will be something stupid and obvious and trivial but I
just can't spot it. Any tips would be much appreciated.
I'm using ANTLR 3.2, Java target.
cheers
Michael
More information about the antlr-interest
mailing list