[stringtemplate-interest] [ST4] How to apply multiple "format"s to an expression?
Udo Borkowski
ub at abego-software.de
Sat Feb 19 00:27:23 PST 2011
Hi Collin,
I tried out your adapter and it works fine. Thanks.
However I had to work around a more general problem. Maybe somebody has a general solution?
I already defined my own ObjectModelAdaptor for Object. As ST4 only allows one ObjectModelAdapter per class I had to change my adaptor to "call" PublicMethodModelAdapter. In my case it was easy: if my adapter does not support the given format I call the PublicMethodModelAdapter.
This is fine because I own my code and I could change MyAdapter. But other people may want to use several third party adapters in one applications. How will this work? E.g. in the STRUM library there are already 4 adaptors for Object. What do I do if I want to use both the PublicMethodModelAdapter and the StaticMethodModelAdaptor?
Udo
On 18.02.2011, at 23:53, Collin Fagan wrote:
> This could actually be done by extending the ObjectModelAdaptor model adapter to have it check for such a method.
>
> Such an adapter is available as part of STRUM.
> PublicMethodModelAdapter - access any public method from ST
> Humm ... but it would be interesting to build a Renderer that took a delimited set of format parameters.
>
> <n;format="%15s,upper">
>
> Of course comma works great here but not for the general case .. maybe make the delimiter a parameter to the renderer? I might slap something together to try it out.
>
> Collin
>
> On Fri, Feb 18, 2011 at 4:29 PM, Sam Harwell <sharwell at pixelminegames.com> wrote:
> Does this work:
>
>
> <(upper(n)); format="%-15s">
>
>
> With this definition of upper(x)?
>
>
> upper(x) ::= <<
>
> <x; format="upper">
>
> >>
>
>
> Also, here’s an interesting case where if <x.y> checked for a method y() (zero parameters and non-void return value), you could use <n.toUpperCase; format="%-15s">. This could actually be done by extending the ObjectModelAdaptor model adapter to have it check for such a method.
>
>
> Sam
>
>
> From: stringtemplate-interest-bounces at antlr.org [mailto:stringtemplate-interest-bounces at antlr.org] On Behalf Of Udo Borkowski
> Sent: Friday, February 18, 2011 4:02 PM
> To: stringtemplate-interest List
> Subject: [stringtemplate-interest] [ST4] How to apply multiple "format"s to an expression?
>
>
> Hi,
>
>
> I would like to generate a constant definition like this:
>
>
> public static final int ABC = 123;
>
> public static final int GHIJKLMN = 456;
>
>
> To make sure the "="s are aligned I can use the Java String format padding feature, e.g. use a template like this:
>
>
> t1(n,v) ::= <<
>
> public static final int «n;format="%-15s"» = «v»;
>
> >>
>
>
> However the name is given in mixed case and I need to "upper" it, e.g. with something like this:
>
>
> t2(n,v) ::= <<
>
> public static final int «n;format="upper"» = «v»;
>
> >>
>
>
> Is there a way to combine both formats, so I get an uppercased, right padded name?
>
>
>
> Udo
>
>
>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org/mailman/listinfo/stringtemplate-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20110219/a1da8ec4/attachment.html
More information about the stringtemplate-interest
mailing list