[antlr-interest] Creation of new tree nodes
Greg Smolyn
greg at smolyn.org
Fri Aug 22 22:07:13 PDT 2008
Hi,
I'm trying to perform an AST transformation that will effectively
replace a node + subnodes with a mostly artificial new node.
However, ANTLR 3.1 seems to be unhappy with the syntax.
Here's the problem code in question (assume DocumentWriteContents
gets set somewhere down in the expression rule):
statement
scope { IToken DocumentWriteContents; }
: ^(STMT emptyStatement)
| ^(STMT variableDeclaration)
| ^(STMT expression) -> { $statement::DocumentWriteContents!=null }?
^(STMT
(BLOCK
(STMT (VAR["var"] (ASSIGN["="]
Identifier["_SL_temp"] (CALL (BYFIELD Identifier["document"]
Identifier["createElement"]) (ARGS StringLiteral["'div'"])))))
(STMT (ASSIGN["var"] (BYFIELD
Identifier["_SL_Temp"] Identifier["innerHTML"])
$statement::DocumentWriteContents ))
(STMT (CALL (BYFIELD (BYFIELD
Identifier["document"] Identifier["body"]) Identifier["appendChild"])
(ARGS Identifier["_SL_Temp"])))))
-> ^(STMT expression)
| ^(STMT ifStatement)
| ^(STMT doStatement)
| ^(STMT whileStatement)
| ^(STMT forStatement)
| ^(STMT continueStatement)
| ^(STMT breakStatement)
| ^(STMT returnStatement)
| ^(STMT withStatement)
| ^(STMT labelledStatement)
| ^(STMT switchStatement)
| ^(STMT throwStatement)
| ^(STMT tryStatement )
;
STMT, BLOCK, CALL, BYFIELD and ARGS are all artificial tokens.
Thanks for your help!
-greg
More information about the antlr-interest
mailing list