[stringtemplate-interest] H2 test a value

Jesper Goertz jesper.goertz at gmail.com
Wed Nov 23 07:36:29 PST 2005


I see, rest() is not needed, the filter below works fine.

    String templates =
      "group test;" +newline+
      "t(m,ns) ::= << <ns:{n|<if (!m.(n))><n><endif>};
separator=\",\"> >>" +newline;
    StringTemplateGroup group = new StringTemplateGroup(new
StringReader(templates), AngleBracketTemplateLexer.class);

    HashMap filter = new HashMap();
    filter.put("42", Boolean.TRUE);
    String[] numbers = new String[]{"3","11","42","87"};

    StringTemplate a = group.getInstanceOf("t");
    a.setAttribute("m", filter);
    a.setAttribute("ns", numbers);

    String expecting =" 3,11,87 ";
    String result = a.toString();
    assertEqual(result, expecting);

And I found stringtemplates at www.codegeneration.net looking for a
tool to generate wrapper classes from remote interfaces. The filter is
needed because the wrapper methods should not throw
java.rmi.RemoteException.

Jesper

On 11/22/05, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> On Nov 21, 2005, at 1:27 PM, Jesper Goertz wrote:
>
> > Hi Terence,
> >
> > StringTemplate is a fine tool, thank you!
>
> Thanks!  How did you find it?
>
> > In the documentation (of List construction) you write that
> > "This ability to rearrange attributes is consistent with model-view
> > separation
> > because the template cannot alter the data structure nor test its
> > values"
> >
> > However, it seems to be possible to test for specific values by
> > means of
> > a map attribute with boolean values, e.g., with
> >
> > map.put("b", Boolean.TRUE);
>
> Well, yes, booleans are the only exception but in a sense they are ok
> as you are merely testing the result of a computation in the model.
>
> > you can test for the value "b" like in
> >
> > t(m,n) ::= "$if (!m.(n))$ $n$ $endif$"
>
> Doesn't this simply yield a property name, which is stored in
> attribute n, such as "salary" of object m?  So if you say m is a map
> with "salary":"99000" and n="salary", it will show text "salary" when
> m.get("salary") is non null.  You are deciding whether to display not
> testing its value to see if it's 42 or whatever.
>
> > When the rest bug has been squashed this can be used to filter out
> > values from a list and solve "the last empty value problem" in
> > testEmptyIteratedConditionalValueGetsNoSeparator.
>
> Ah, well you can always filter for empty values.  My rule is "you can
> test presence/absence or size or anything else that does not test the
> value of an attribute"
>
> > Is this kosher or a vile hack?
>
> Seems kosher...filtering for nonempty values is trivial:
>
> $names:{n | $if(n)$ $n$ $endif$}$
>
> Ter
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
>


More information about the stringtemplate-interest mailing list