[antlr-interest] How to add SEMI of variable declaration in the result tree?

Fan Yang <yhhf_dy at yahoo.com> yhhf_dy at yahoo.com
Fri Feb 7 08:36:16 PST 2003


Hi all,

I want to preserve all whitespaces and comments for java code, so I 
have to modify java.g and java.tree.g in order to let all SEMI be 
added to the result AST tree.

But I was stuck in how to incorperate SEMI which exists in variable 
declaration rule. Problem is that "field" rule suffixed with "!" will 
not add his tree to the result tree. so the SEMI which is at the end 
of "v:variableDefinitions[#mods,#t] SEMI" will not appear in the 
result tree. I have tried to add SEMI into "variableDeclarator" 
subrule, finally I failed to do that.

Would you please help me to deal with this problem. Any suggestion 
will be appreciated.

Good Wishes,

Fan Yang



---- fraction of Java.g ---
field!:
.
.
.
v:variableDefinitions[#mods,#t] SEMI
//{#field = #(#[VARIABLE_DEF,"VARIABLE_DEF"], v);}
{#field = #v;}
.
.
.
variableDefinitions[AST mods, AST t]
 : variableDeclarator[getASTFactory().dupTree(mods),
   getASTFactory().dupTree(t)]
   (COMMA!
     variableDeclarator[getASTFactory().dupTree(mods),
	getASTFactory().dupTree(t)]
    )*
    ;

variableDeclarator![AST mods, AST t]
 :id:IDENT d:declaratorBrackets[t] v:varInitializer
 {#variableDeclarator = #(#[VARIABLE_DEF,"VARIABLE_DEF"], mods, #(#  
[TYPE,"TYPE"],d), id, v);}
 ;

declaratorBrackets[AST typ]
 :{#declaratorBrackets=typ;}
  (lb:LBRACK^ {#lb.setType(ARRAY_DECLARATOR);} RBRACK)*
  ;

varInitializer
 :( ASSIGN^ initializer )?
 ;
 

 


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list