[stringtemplate-interest] Different formats for data
Mark Wright
markwright at internode.on.net
Tue Feb 12 17:00:21 PST 2008
Some ideas:
(1)
http://www.antlr.org/wiki/display/ST/Object+rendering
(2)
You can create a variable in the tree grammar action code that
has 2 attributes, one for each way the date is formatted:
public class NameSTV {
protected String name;
protected String typeVariableName;
public NameSTV(String theName, String theTypeVariableName) {
name = theName;
typeVariableName = theTypeVariableName;
}
public final String getName() {
return name;
}
public final String getTypeVariableName() {
return typeVariableName;
}
}
Which can be set in the tree grammar something like:
base_specifier
: ^(BASE IDENTIFIER FULLY_QUALIFIED_NAMESPACE TYPE_VARIABLE_NAME)
{
NameNamespaceSTV b = new NameNamespaceSTV($IDENTIFIER.text, $FULLY_QUALIFIED_NAMESPACE.text, $TYPE_VARIABLE_NAME.text);
$st = %baseSpecifier();
%{$st}.variable=b;
}
;
Although I wrote this, I am still trying to figure it out myself.
I do not currently understand what the baseSpecifier string template
does.
Anyway, in the string template if you do:
<variable.name>
it calls the getName() property.
Regards, Mark
On Tue, 12 Feb 2008 16:32:54 -0500
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?
>
--
More information about the stringtemplate-interest
mailing list