[antlr-interest] Able to emulate java.text.ChoiceFormat ?

Harald Mueller harald_m_mueller at gmx.de
Mon Nov 26 02:14:58 PST 2007


Hi -

The whole idea of StringTemplate is to separate "computation" from "string building". Even the $if$ is in a way a concession - one could do everything with lazily evaluated template names (things like $(abc)()$).

The favored way is the definition of a clean interface which provides all the attributes for the template; and do all the computation there.

Stringtemplate is, as I see it, NOT an abstraction layer on a FIXED value-providing machine (as are e.g. most report generators); rather, it is intended that the templates evolve together with the accessed interfaces.

In a way, Stringtemplate tries to do "MV(C)": It provides ONLY the VIEW for a model; and like in MVC, the view itself is not supposed to compute anything (even if some people with GUI builders in their hands prefer it otherwise ...).

Regards
Harald M.

-------- Original-Nachricht --------
> Datum: Mon, 26 Nov 2007 10:35:23 +0100
> Von: "Christopher Brown" <chris77550 at gmail.com>
> An: antlr-interest at antlr.org
> Betreff: [antlr-interest] Able to emulate java.text.ChoiceFormat ?

> Hi,
> 
> Is it possible to create templates that have the capabilities of
> ChoiceFormat with StringTemplate (I'm using ST#3)?
> 
> http://java.sun.com/javase/6/docs/api/java/text/ChoiceFormat.html
> 
> For example, the following template doesn't work:
> 
> fileInfo(fileName,fileSize) ::= <<
> File $fileName$, $fileSize$ $if(fileSize>1)$bytes$else$byte$endif$.
> >>
> 
> (I'm using a group template file with the default lexer, not the angle
> bracket one, as my target is HTML...).
> 
> There only seems to be support for conditions based on string equality
> or just non-nullity, not numeric comparisons.  I'm not wanting to add
> computation into the view, but it's important in many (human)
> languages to be able to vary the text along with a quantity, and I
> don't want to hard-code parts of the template into the code that calls
> it.
> 
> Thanks,
> Christopher

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger


More information about the antlr-interest mailing list