[antlr-interest] why <if(y==2 )> in Stringtemplate does not work?

YingAnnie yimm8369 at hotmail.com
Fri Mar 6 15:46:58 PST 2009



 So, what I expect is that when the code is "a=b*c", and c==2, then change * to /.

 

multiplicativeExpression
    :^(STAR u1=unaryExpression u2=unaryExpression)  -> assgin(x={$u1.text},y={$u2.text},z={"/"})  
    ;

 

group T;
assgin(x,y,z)::= <<
<if(y==2)><x><z><y><else><"error"><endif>

 

If I can not test the value of attributes within ST,Then it has to be done in the tree grammar. can I do something like this:

 

multiplicativeExpression
    :^(STAR u1=unaryExpression u2='2')  -> assgin(x={$u1.text},y={$u2.text},z={"/"})  
    ;

 

thanks.


> 
> Hi. you cannot test the value of attributes within ST; it violates 
> model view separation. please read the following paper to catch the 
> philosophical approach of ST:
> 
> http://www.cs.usfca.edu/~parrt/papers/mvc.templates.pdf
> 
> Ter
> On Mar 6, 2009, at 1:13 PM, YingAnnie wrote:
> 
> >
> >
> > Hi,
> >
> > I used the following stg, the aim is when y is equal to 2 ,print out 
> > <x><z><y>, but <if(y==2 )> does not work.
> > group T;
> > assgin(x,y,z)::= <<
> > <if(y==2)><x><z><y><else><"fsdfsdfsdf"><endif>
> >
> > >>
> >
> > How can I use if...else in Stringtemplate?
> >
> >
> > Thanks in advance.
> >
> >
> > Annie
> >
> >
> > 微软地图实时路况,为您节省的不仅仅是时间! 立即查看!
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
> 


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


More information about the antlr-interest mailing list