[antlr-interest] ANTLR stringTemplates ObjC cleanup

Alan Condit acondit at ipns.com
Sat Feb 12 10:48:46 PST 2011


Greetings all,

(I am reposting this because ANTLRInterest doesn't autowrap long lines and it makes it hard to read.)
I hacked around on the stringTemplates in ANTLR earlier and got things to work, but now I am trying to really understand them.

I am trying to clean up my Objective-C templates in order to facilitate implementation of ST.stg in Objective-C.

I have got the template <ruleAttributeScopeImplementation(scope)> defined in genericParser.
My question is how do I convert the template <ruleAttributeScopeImplementation(scope)>
into the next two templates (<ruleAttributeScopeImplementation(scope)> and 
<ruleAttributeScopeImplementation.synthesize()> and get it to work. 
I guess more succinctly the question is how do I get Antlr to recognize a new named "sub" template 
and invoke it. Do I need to do something like this:

#pragma mark Rule attributes scope methods
<rules:{rule |
<rule.ruleDescriptor.ruleScope:ruleAttributeScopeImplementation.synthesize(scope=it)>}><\n>

in genericParser or do I need to do something more in <ruleAttributeScopeImplementation(scope)>???
If so, what???

/******* START OF EXAMPLES ********/

ruleAttributeScopeImplementation(scope) ::= <<
/* start of ruleAttributeScopeImplementation */
<if(scope.attributes)>
@implementation <scope.name>_Scope<\n>
/******* MOVE THE FOLLOWING LINE TO A NEW TEMPLATE *******/
<scope.attributes:{a|@synthesize <a.name>;}; separator="\n"><\n>

+ (<scope.name>_Scope *)new<scope.name>_Scope
{
   return [[[<scope.name>_Scope alloc] init] retain];
}

/********* a bunch more lines of template ************/
/*********    end of these more lines     ************/
@end /* end of <scope.name>_Scope implemtation */<\n>
<endif>
>> 

/******_________CONVERT ABOVE TO BELOW_________*******/

ruleAttributeScopeImplementation.synthesize(scope) ::=<<
<scope.attributes:{a|@synthesize <a.name>;}; separator="\n"><\n>
>> 

ruleAttributeScopeImplementation(scope) ::= <<
/* start of ruleAttributeScopeImplementation */
<if(scope.attributes)>
@implementation <scope.name>_Scope<\n>
/********** INVOKE THE NEW TEMPLATE HERE **********/
<ruleAttributeScopeImplementation.synthesize(scope)>

+ (<scope.name>_Scope *)new<scope.name>_Scope
{
   return [[[<scope.name>_Scope alloc] init] retain];
}

/********* a bunch more lines of template ************/
/*********    end of these more lines     ************/
@end /* end of <scope.name>_Scope implemtation */<\n>
<endif>
>> 

Thanks in Advance for any help given,
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