1324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* 2324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver [The "BSD license"] 3324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver Copyright (c) 2005-2006 Terence Parr 4324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver All rights reserved. 5324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 6324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver Redistribution and use in source and binary forms, with or without 7324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver modification, are permitted provided that the following conditions 8324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver are met: 9324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 1. Redistributions of source code must retain the above copyright 10324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver notice, this list of conditions and the following disclaimer. 11324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 2. Redistributions in binary form must reproduce the above copyright 12324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver notice, this list of conditions and the following disclaimer in the 13324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver documentation and/or other materials provided with the distribution. 14324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 3. The name of the author may not be used to endorse or promote products 15324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver derived from this software without specific prior written permission. 16324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 17324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver*/ 28324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Template subgroup to add template rewrite output 29324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * If debugging, then you'll also get STDbg.stg loaded. 30324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */ 31324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 32324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeInterface.memVars() ::= << 33324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.memVars()> 34324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST returnInterface.memVars */ 35324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverST *st; 36324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 37324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 38324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeInterface.properties() ::= << 39324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.properties()> 40324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST returnScope.properties */ 41324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@property (retain, getter=getST, setter=setST:) ST *st; 42324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 43324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 44324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeInterface.methodsDecl() ::= << 45324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.methodsDecl()> 46324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST AST returnScopeInterface.methodsDecl */ 47324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (id) getTemplate; 48324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (NSString *) toString; 49324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (NSString *) description; 50324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 51324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 52324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeInterface() ::= << 53324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST returnScopeInterface */ 54324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@interface <returnScopeInterface.name> : ANTLRReturnScope { 55324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<returnScopeInterface.memVars()> 56324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 57324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<returnScopeInterface.properties()> 58324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 59324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<returnScopeInterface.methods()> 60324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@end 61324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 62324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 63324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeImplementation.synthesize() ::= << 64324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.synthesize()> 65324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST returnScope.synthesize */ 66324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@synthesize st; 67324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 68324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 69324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeImplementation.methods() ::= << 70324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.methods()> 71324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST returnScope.methods */ 72324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (id) getTemplate { return st; } 73324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (NSString *) toString { return st==nil?nil:[st toString]; } 74324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (NSString *) description { [self toString]; } 75324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 76324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 77324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScopeImplementation() ::= << 78324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@implementation <returnScopeImplementation.name> 79324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<returnScopeImplementation.synthesize()> 80324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 81324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<returnScopeImplementation.methods()> 82324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@end 83324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 84324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 85324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Add this to each rule's return value struct */ 86324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@returnScope.ruleReturnMembers() ::= << 87324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.ruleReturnMembers()> 88324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST returnScope.ruleReturnMembers -- empty */ 89324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 90324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 91324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@genericParserHeaderFile.memVars() ::= << 92324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.memVars()> 93324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST genericParserHeaderFile.memVars -- empty now */ 94324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverSTGroup *templateLib; /* ST -- really a part of STAttrMap */ 95324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 96324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 97324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@genericParserHeaderFile.properties() ::= << 98324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.properties()> 99324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST genericParser.properties */ 100324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@property (retain, getter=getTemplateLib, setter=setTemplateLib:) STGroup *templateLib; 101324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 102324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 103324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@genericParserHeaderFile.methodsDecl() ::= << 104324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.methodsDecl()> 105324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST genericParser.methodsDecl */ 106324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- init; 107324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STGroup *) getTemplateLib; 108324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (void) setTemplateLib:(STGroup *)aTemplateLib; 109324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@end 110324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 111324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 112324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@genericParser.synthesize() ::= << 113324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.synthesize()> 114324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST genericParserImplementation.synthesize */ 115324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@synthesize templateLib; 116324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 117324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 118324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@genericParser.methods() ::= << 119324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.methods()> 120324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST genericParser.methods */ 121324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 122324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STGroup *)getTemplateLib 123324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 124324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return templateLib; 125324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 126324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 127324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (void) setTemplateLib:(STGroup *)aTemplateLib 128324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 129324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver templateLib = aTemplateLib; 130324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 131324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 132324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 133324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 134324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@genericParser.members() ::= << 135324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@super.members()> 136324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverSTGroup *templateLib = [STGroup newSTGroup:@"<name>Templates"]; 137324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 138324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STGroup *) getTemplateLib 139324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 140324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return templateLib; 141324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 142324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 143324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (void) setTemplateLib:(STGroup *) templateLib 144324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 145324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver this.templateLib = templateLib; 146324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 147324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 148324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** allows convenient multi-value initialization: 149324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * "new STAttrMap().put(...).put(...)" 150324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */ 151324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* REPLACE THIS STATIC CLASS 152324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverstatic class STAttrMap extends HashMap { 153324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObject:(id)aValue forKey:(NS*)String attrName 154324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 155324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver [super setObject:value forKey:attrName]; 156324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return self; 157324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 158324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObjectWithInt:(NSInteger)value forKey:(NSString *)attrName 159324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 160324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver [super setObject:[NSNumber numberWithInteger:value] forKey:attrName]; 161324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return self; 162324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver } 163324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 164324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver*/ 165324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 166324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 167324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap() ::= << 168324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap ------------ */ 169324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@STAttrMap.interface()> 170324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@STAttrMap.implementation()> 171324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap ------------ */ 172324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 173324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 174324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap.interface() ::= << 175324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap.interface ------------ */ 176324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@interface STAttrMap : ANTLRHashMap { 177324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* <@STAttrMap.memVars()> */ 178324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver STGroup *templateLib; 179324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 180324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 181324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* <@STAttrMap.properties()> */ 182324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@property (retain, getter=getTemplateLib, setter=setTemplateLib:) STGroup *templateLib; 183324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* <@STAttrMap.methodsDecl()> */ 184324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (id) init; 185324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObject:(id)value forKey:(NSString *)attrName; 186324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObjectWithInt:(NSInteger)value forKey:(NSString *)attrName; 187324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (void) setTemplateLib:(STGroup *)aTemplateLib; 188324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STGroup *) getTemplateLib; 189324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@end 190324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap.interface ------------ */ 191324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 192324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 193324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap.implementation() ::= << 194324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap.implementation ------------ */ 195324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** allows convenient multi-value initialization: 196324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * "new STAttrMap().put(...).put(...)" 197324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */ 198324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@implementation STAttrMap 199324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@synthesize templateLib; 200324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 201324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<@STAttrMap.methods()> 202324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@end 203324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap.implementation ------------ */ 204324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 205324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 206324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap.memVars() ::= << 207324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap.memVars ------------ */ 208324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver STGroup *templateLib; 209324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap.memVars ------------ */ 210324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 211324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 212324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap.properties() ::= << 213324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap.properties ------------ */ 214324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@property (retain, getter=getTemplateLib, setter=setTemplateLib:) STGroup *templateLib; 215324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap.properties ------------ */ 216324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 217324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 218324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap.methodsDecl() ::= << 219324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap.methodsDecl ------------ */ 220324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (id) init; 221324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObject:(id)value forKey:(NSString *)attrName; 222324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObjectWithInt:(NSInteger)value forKey:(NSString *)attrName; 223324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (void) setTemplateLib:(STGroup *)aTemplateLib; 224324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STGroup *) getTemplateLib; 225324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap.methodsDecl ------------ */ 226324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 227324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 228324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver@STAttrMap.methods() ::= << 229324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start STAttrMap.methods ------------ */ 230324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (id) init 231324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 232324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver self = [super initWithLen:16]; 233324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver if ( self != nil ) { 234324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver templateLib = [STGroup newSTGroup:"<name>Templates"]; 235324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver } 236324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return self; 237324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 238324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 239324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObject:(id)aValue forKey:(NSString *)aAttrName 240324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 241324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver [super setObject:aValue forKey:aAttrName]; 242324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return self; 243324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 244324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 245324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STAttrMap *) setObjectWithInt:(NSInteger)aValue forKey:(NSString *)aAttrName 246324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 247324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver [super setObject:[NSNumber numberWithInteger:aValue] forKey:aAttrName]; 248324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return self; 249324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 250324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (void) setTemplateLib:(STGroup *)aTemplateLib 251324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 252324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver templateLib = aTemplateLib; 253324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 254324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 255324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver- (STGroup *)getTemplateLib 256324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 257324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver return templateLib; 258324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 259324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end STAttrMap.methods ------------ */ 260324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 261324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 262324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** x+=rule when output=template */ 263324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverruleRefAndListLabel(rule,label,elementIndex,args,scope) ::= << 264324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST ruleRefAndListLable */ 265324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<ruleRef(...)> 266324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<listLabel(elem=[label getTemplate,...]> 267324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 268324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 269324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteTemplate(alts) ::= << 270324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start rewriteTemplate ------------ */ 271324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver// TEMPLATE REWRITE 272324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(backtracking)> 273324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverif ( <actions.(actionScope).synpredgate> ) { 274324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver <alts:rewriteTemplateAlt(); separator="else "> 275324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver <if(rewriteMode)><replaceTextInLine()><endif> 276324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver} 277324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<else> 278324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<alts:rewriteTemplateAlt(); separator="else "> 279324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(rewriteMode)><replaceTextInLine()><endif> 280324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<endif> 281324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end rewriteTemplate ------------ */ 282324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 283324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 284324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverreplaceTextInLine() ::= << 285324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start replaceTextInLine ------------ */ 286324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(TREE_PARSER)> 287324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[[(ANTLRTokenRewriteStream *)input getTokenStream] 288324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver replaceFromIndex:[[input getTreeAdaptor] getTokenStartIndex:retval.start] 289324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver ToIndex:[[input getTreeAdaptor] getTokenStopIndex:retval.start] 290324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver Text:retval.st]; 291324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<else> 292324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[(ANTLRTokenRewriteStream *)input) 293324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver replaceFromIndex:[((ANTLRCommonToken *)retval.start) getTokenIndex] 294324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver ToIndex:[[input LT:-1] getTokenIndex] 295324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver Text:retval.st]; 296324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<endif> 297324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end replaceTextInLine ------------ */ 298324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 299324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 300324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteTemplateAlt() ::= << 301324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start rewriteTemplateAlt ------------ */ 302324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* ST <it.description> */ 303324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(it.pred)> 304324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruverif (<it.pred>) { 305324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver retval.st = <it.alt>; 306324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}<\n> 307324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<else> 308324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver{ 309324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver retval.st = <it.alt>; 310324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver}<\n> 311324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<endif> 312324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end rewriteTemplateAlt ------------ */ 313324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 314324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 315324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteEmptyTemplate(alts) ::= << 316324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruvernil; 317324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 318324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 319324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Invoke a template with a set of attribute name/value pairs. 320324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * Set the value of the rule's template *after* having set 321324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * the attributes because the rule's template might be used as 322324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * an attribute to build a bigger template; you get a self-embedded 323324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver * template. 324324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver */ 325324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteExternalTemplate(name,args) ::= << 326324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start rewriteExternalTemplate ------------ */ 327324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[templateLib getInstanceOf:@"<name>" 328324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(args)>[[STAttrMap newSTAttrMap] <args:{a | setObject:<a.value> forKey:@"<a.name>"]}><endif>] 329324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end rewriteExternalTemplate ------------ */ 330324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 331324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 332324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** expr is a string expression that says what template to load */ 333324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteIndirectTemplate(expr,args) ::= << 334324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start rewriteIndirectTemplate ------------ */ 335324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[templateLib getInstanceOf:<expr> 336324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(args)> [[STAttrMap newSTAttrMap]<args:{a | setObject:<a.value> forKey:@"<a.name>"]}>] 337324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<else>]<endif> 338324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end rewriteIndirectTemplate ------------ */ 339324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 340324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 341324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Invoke an inline template with a set of attribute name/value pairs */ 342324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteInlineTemplate(args, template) ::= << 343324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start rewriteInlineTemplate ------------ */ 344324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverSTGroup *templateLib; 345324c4644fee44b9898524c09511bd33c3f12e2dfBen GruvertemplateLib.templates = [STAttrMap newSTAttrMap]; 346324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<if(args)> [templateLib.templates <args:{a | setObject:<a.value> forKey:@"<a.name>"];}><endif> 347324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[ST newST:templateLib template:@"<template>"]; 348324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end rewriteInlineTemplate ------------ */ 349324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 350324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 351324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** plain -> {foo} action */ 352324c4644fee44b9898524c09511bd33c3f12e2dfBen GruverrewriteAction(action) ::= << 353324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start rewriteAction ------------ */ 354324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<action> 355324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end rewriteAction ------------ */ 356324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 357324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 358324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** An action has %st.attrName=expr; or %{st}.attrName=expr; */ 359324c4644fee44b9898524c09511bd33c3f12e2dfBen GruveractionSetAttribute(st,attrName,expr) ::= << 360324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start actionSetAttribute ------------ */ 361324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[[ST attributes] setObject:<expr> forKey:@"<attrName>"]; 362324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver<![<st> setAttribute:<expr> name:@"<attrName>"];!> 363324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end actionSetAttribute ------------ */ 364324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 365324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver 366324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/** Translate %{stringExpr} */ 367324c4644fee44b9898524c09511bd33c3f12e2dfBen GruveractionStringConstructor(stringExpr) ::= << 368324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST start actionStringConstructor ------------ */ 369324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver[ST newSTWithTemplate:<stringExpr>] 370324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver/* -------- ST end actionStringConstructor ------------ */ 371324c4644fee44b9898524c09511bd33c3f12e2dfBen Gruver>> 372