[stringtemplate-interest] multivalue checking

John RW rw1836 at yahoo.com
Thu May 25 14:14:36 PDT 2006


Well, I think this does not quite answer my question:
   
  You code is
    $if(foo)$  foo $else$ bar $endif$
   
  what I want is something like:
   
  $if there_is_one_true(foos)$ foo $else$ bar $endif$
   
  Please help.  

Kay Roepke <kroepke at dolphin-services.de> wrote:
  
On 25. May 2006, at 22:13 Uhr, John RW wrote:

> So it boils down to checking if any of the attributes has certain 
> value. I don't know how to do that in stringtemplate.

Depending on the template lexer you use (if you don't know, it's the 
one with the $-signs ;)) you can do this:

classDump:/tmp kroepke$ cat ST.java
import org.antlr.stringtemplate.*;

public class ST {
public static void main(String[] args) throws Exception {
StringTemplate st = new StringTemplate("foo ::= \"$if(foo) 
$foo exists$else$foo is fubar$endif$\"");
st.setAttribute("foo", null);
System.out.println(st.toString());
}
}


In other words: use $if(namespace)$namespace is not null$endif$ to 
check for a value.

HTH,

-k


		
---------------------------------
Ring'em or ping'em. Make  PC-to-phone calls as low as 1¢/min with Yahoo! Messenger with Voice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20060525/7228743c/attachment.html


More information about the stringtemplate-interest mailing list