[stringtemplate-interest] Problems with counting using i/i0

Terence Parr parrt at cs.usfca.edu
Sat Nov 13 13:15:03 PST 2010


Can you set a parameter to data_n? Using the default i0 is a little unconventional. If you name the parameter, then there is no ambiguity about what i0 means .
Ter
On Nov 9, 2010, at 8:35 AM, Morten Olav Hansen wrote:

> Hi
> 
> I'm having a problem with using a counter in my stringtemplate (also
> using ANTLR3).
> 
> In my StringTemplate I have:
> 
> datavalues(datas) ::= <<
> <datas: data_n()>
>>> 
> 
> data_n() ::= <<
> Data <i0>;
> <it.values: value_n(i0)>
>>> 
> 
> value_n() ::= <<
> Value <n>_<i0>;
>>> 
> 
> data(values) ::= << >>
> value() ::= << >>
> 
> data and value has corresponding -> data/value template rewrites in
> the antlr-grammar.
> 
> This does not work, since it seems the i0 parameter to value_n is
> evaluated in value_n, so <i0> == <n>, I'm looking for something like:
> 
> Data 0;
> Value 0_0;
> Value 0_1;
> 
> Data 1;
> Value 1_0;
> Value 1_1;
> 
> Is there something I can do about this behavior ? or are there any
> other ways of accomplishing this? any ideas would be appreciated.
> 
> Regards,
> Morten
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest



More information about the stringtemplate-interest mailing list