[antlr-interest] StringTemplate attribute problem in Target Language generator
Alan Condit
acondit at ipns.com
Sat Jul 3 12:52:11 PDT 2010
Hi,
I am trying to get type and name attributes to work for return values specified in a rule. For example,
if someone specifies the following rule:
kfloat returns [ double value ]
| KFLOAT
;
In the target language generator I need to be able to generate:
\@property (assign, getter=get<it.name>, setter=set<it.name>\:) <it.type> <it.name>;
where <it.type> is "double" and <it.name> is "value" (of course without the quotes)
Currently all I have figured out how to get is:
double value;
using:
<ruleDescriptor.returnScope.attribute:{ <it.dec>; }; separator="\n">
I also need to use the same items to generate the getter and setter methods like:
@synthesize value;
- (double)getValue
{
return( value );
}
- (void)setValue:(double)aVal
{
value = aVal;
}
So I have been trying something like this:
<scope.attributes:{\@synthesize <it.name>;}; separator="\n">
<scope.attributes.decl:{<"\n">- (<it.type>)get<it.name><"\n">{<"\n"> return( <it.name> );<"\n">}<"\n\n">
- (void)set<it.name>:(<it.type>)aVal<"\n">{<"\n"> <it.name> = aVal;<"\n">}<"\n\n">}; separator="\n">
Or this:
<scope.attributes.decl:{
- (<it.type>)get<it.name>
{
return( <it.name> );
}
- (void)set<it.name>\:(<it.type>)aVal
{
<it.name> = aVal;
}
}; separator="\n">
Any help would be greatly appreciated. I am just learning StringTemplate and it may be something simple
biting me in the butt.
Thanks again,
Alan
---
Alan Condit
1085 Tierra Ct.
Woodburn, OR 97071
Email -- acondit at ipns.com
Home-Office (503) 982-0906
More information about the antlr-interest
mailing list