[antlr-interest] Getting foreach working with StringTemplate for C#

Christopher Brown chris77550 at gmail.com
Fri Feb 29 09:39:32 PST 2008


Hi,

I'm still struggling with StringTemplate for C#, having looked through
the lists, searched the web, and looked at the source code.

I can't get the following working (much simplified version of what I'm
trying to achieve):

  string tpl = "$foreach f in foo$ $f$ $end$";
  //string tpl = "$foo$";
			
  StringTemplate st = new StringTemplate(tpl);
  st.SetAttribute("foo", new string[] {"a", "b", "c"});
  Console.Out.WriteLine(st.ToString());

If I switch the comment onto the first line, I get the array collapsed
into a string with no separators.

In my "real" scenario, which works with simple values, I just can't
merge in arrays, lists, or anything enumerable.  I hope I'm doing
something wrong -- that someone can explain to me -- because it seems
such a basic task, I have trouble believing that it isn't
implemented...!

In the "real" scenario, I've also tried with group files and varying
"dollar" and "angle bracket syntaxes", with no luck.

Can anyone help?

Thanks in advance,
Christopher


More information about the antlr-interest mailing list