[stringtemplate-interest] Different formats for data

Terence Parr parrt at cs.usfca.edu
Tue Feb 12 18:14:33 PST 2008


On Feb 12, 2008, at 1:32 PM, FranklinChen at cmu.edu wrote:

> I have an application using ANTLR3 and StringTemplate that basically
> parses data and then outputs it in two very different formats.  For
> example, dates need to be output as both 12-FEB-2008 and 2008-02-12.
> I would like advice on how to do this, using a single tree grammar and
> two ST group files.  E.g., if the tree grammar has
>
> birthdate
>    :
>        DATE
>        ->
>        birthdate(date={$DATE.text})
>    ;
>
> then there is a problem, because of the strict separation that
> apparently prevents me from having birthdate() in A.stg and B.stg do
> "computations" to reformat the date.  E.g., suppose DATE came from the
> lexer as 12-FEB-2008.  Then A.stg's birthdate() is trivial, but
> B.stg's birthdate() can't be done.  What is the solution

hi!  Use format option and set a renderer for Date object :)

Ter


More information about the stringtemplate-interest mailing list