[antlr-interest] Fwd: ST#, attribute renderers, and format

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


I guess I'm going to have to conclude that this isn't implemented and
that maybe StringTemplate isn't a safe bet for anything other than
Java.  :-(



---------- Forwarded message ----------
From: Christopher Brown <chris77550 at gmail.com>
Date: 22 Feb 2008 13:40
Subject: ST#, attribute renderers, and format
To: antlr-interest at antlr.org


Hi,

 The StringTemplate format option doesn't seem to be supported in
 StringTemplate 3.0.1 for C#.  This is described here:

 http://www.antlr.org/wiki/display/ST/Object+rendering

 ...on the second part of the page, under the "Format Options" header.
 As a quick reminder, it should allow me to register a formatter that
 lets me use a template variable as follows:

 $name;format="html"$
 $name;format="javascript"$

 ...so that I can apply appropriate escaping in the template, instead
 of forcing the underlying data to the output format.  In many cases,
 I'm rendering business objects, and I can't for example replace the
 business object's string properties with some custom wrapper class.

 I *can* register a basic attribute renderer, for example:

 public class FmtRenderer : IAttributeRenderer {
  public string ToString(object o) {
  return o.ToString();
  }
  public string ToString(object o, string formatName) {
  return formatName;
  }
 }

 ...but only the first ToString(object o) method is ever called.
 Suspiciously enough, the Wiki example page I referred to above doesn't
 provide a C# example.

 I've tried searching on the web, looking through the source code, and
 so on, with no success.  How can I get this working?

 Thanks,

Christopher


More information about the antlr-interest mailing list