/* [The "BSD licence"] Copyright (c) 2006, 2007 Kay Roepke All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ group AST; @outputFile.imports() ::= << <@super.imports()> #import \<\n> >> @parserHeaderFile.ivars() ::= << <@super.ivars()> >> @parserHeaderFile.methodsdecl() ::= << <@super.methodsdecl()> >> @genericParser.methods() ::= << <@super.methods()> >> /** additional init code for tree support */ @genericParser.init() ::= << <@super.init()> [self setTreeAdaptor:[[[ANTLRCommonTreeAdaptor alloc] init] autorelease]]; >> @genericParser.dealloc() ::= << [self setTreeAdaptor:nil]; <@super.dealloc()> >> /** Add an adaptor property that knows how to build trees */ parserIVars() ::= << id\ treeAdaptor; >> /** Declaration of additional tree support methods - go in interface of parserHeaderFile() */ parserMethodsDecl() ::= << - (id\) treeAdaptor; - (void) setTreeAdaptor:(id\)theTreeAdaptor; >> /** Definition of addition tree support methods - go in implementation of genericParser() */ parserMethods() ::= << - (id\) treeAdaptor { return treeAdaptor; } - (void) setTreeAdaptor:(id\)aTreeAdaptor { if (aTreeAdaptor != treeAdaptor) { [aTreeAdaptor retain]; [treeAdaptor release]; treeAdaptor = aTreeAdaptor; } } >> /** addition ivars for returnscopes */ @returnScopeInterface.ivars() ::= << tree; >> /** the interface of returnScope methods */ @returnScopeInterface.methods() ::= << - () tree; - (void) setTree:()aTree; >> /** the implementation of returnScope methods */ @returnScope.methods() ::= << - () tree { return tree; } - (void) setTree:()aTree { if (tree != aTree) { [aTree retain]; [tree release]; tree = aTree; } } - (void) dealloc { [self setTree:nil]; [super dealloc]; } >> /** Add a variable to track rule's return AST */ ruleDeclarations() ::= << root_0 = nil;<\n> >> ruleLabelDefs() ::= << __tree = nil;}; separator="\n"> __tree = nil;}; separator="\n"> =[[ANTLRRewriteRuleTokenStream alloc] initWithTreeAdaptor:treeAdaptor description:@"token "];}; separator="\n"> =[[ANTLRRewriteRuleSubtreeStream alloc] initWithTreeAdaptor:treeAdaptor description:@"rule "];}; separator="\n"> >> ruleCleanUp() ::= << <[ruleDescriptor.allTokenRefsInAltsWithRewrites,ruleDescriptor.allRuleRefsInAltsWithRewrites] :{[_stream_ release];}; separator="\n"> if ( ![_state isBacktracking] ) {<\n> [_ setTree:()[treeAdaptor postProcessTree:root_0]]; [treeAdaptor setBoundariesForTree:[_ tree] fromToken:[_ start] toToken:[_ stop]]; } [root_0 release]; >> rewriteCodeLabelsCleanUp() ::= << release];}; separator="\n" > release];}; separator="\n" > release];}; separator="\n" > release];}; separator="\n" > >> /** When doing auto AST construction, we must define some variables; * These should be turned off if doing rewrites. This must be a "mode" * as a rule could have both rewrite and AST within the same alternative * block. */ @alt.declarations() ::= << root_0 = ()[treeAdaptor newEmptyTree];<\n> >> // T r a c k i n g R u l e E l e m e n t s /** ID and track it for use in a rewrite rule */ tokenRefTrack(token,label,elementIndex) ::= << if ( ![_state isBacktracking] ) [_stream_ addElement:_