[antlr-interest] Why insertAfter does not work?

YINGAnnie yimm8369 at hotmail.com
Wed Mar 25 15:39:41 PDT 2009


 

Hi again,

 

I want to change "Math.floor(1.5)"  to  "int(1.5)+1" using Tokenrewritestream, the way  I am doing is first changing "Math.floor" to "int", and then insert "+1" at  the end of callExpression, there is my grammar:

 

callExpression
    :  m= memberExpression (indexSuffix |propertyReferenceSuffix|a=argumentSuffix )*  
    {if($m.text.equals("Math.floor"))
   {
    tokens.replace($m.start, $m.stop, "int");
    tokens.insertAfter($callExpression.stop, "+1");
   }   
    }
   )
    ;

 

 

But I got java.lang.NullPointerException error.The test code is  

 

 var b:int=Math.floor(1.5);

 

I tried: 

 tokens.insertBefore($callExpression.start, "+1"); 

 

It works.I got var b:int=+1Math.floor(1.5);  but that is not what I want. 

 

Why insertAfter does not work?


Thanks.


Annie

_________________________________________________________________
MSN安全保护中心,免费修复系统漏洞,保护MSN安全!
http://im.live.cn/safe/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090326/5d872972/attachment.html 


More information about the antlr-interest mailing list