All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.antlr.codegen.templates.ObjC.ObjC.stg Maven / Gradle / Ivy

There is a newer version: 8.1.2
Show newest version
/*
 [The "BSD licence"]
 Copyright (c) 2006, 2007 Kay Roepke 2010 Alan Condit
 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.
*/

/*
 *  Template group file for the Objective C code generator.
 *  Heavily based on Java.stg
 *
 *  Written by Kay Roepke 
 *  Modified by Alan Condit 
 *
 *  This file is part of ANTLR and subject to the same license as ANTLR itself.
 */

group ObjC implements ANTLRCore;

objcTypeInitMap ::= [
    "int"           : "0",              // Integers     start out being 0
    "long"          : "0",              // Longs        start out being 0
    "float"         : "0.0",            // Floats       start out being 0
    "double"        : "0.0",            // Doubles      start out being 0
    "BOOL"          : "NO",             // Booleans     start out being Antlr ObjC for false
    "byte"          : "0",              // Bytes        start out being 0
    "short"         : "0",              // Shorts       start out being 0
    "char"          : "0",              // Chars        start out being 0
    "id"            : "nil",            // ids          start out being nil
    default         : "nil"             // anything other than an atomic type
]

className() ::= "LexerTreeParser!>"
leadIn(type) ::=
<<
/** \file
 *  This  file was generated by $ANTLR version 
 *
 *     -  From the grammar source file : 
 *     -                            On : 

 *     -                 for the lexer : Lexer


 *     -                for the parser : Parser


 *     -           for the tree parser : TreeParser

 *
 * Editing it, at least manually, is not wise. 
 *
 * ObjC language generator and runtime by Alan Condit, acondit|hereisanat|ipns|dotgoeshere|com.
 *
 *
>>

/** The overall file structure of a recognizer; stores methods for rules
 *  and cyclic DFAs plus support code.
 */
outputFile( LEXER,
            PARSER,
            TREE_PARSER,
            actionScope,
            actions,
            docComment,
            recognizer,
            name,
            tokens,
            tokenNames,
            rules,
            cyclicDFAs,
            bitsets,
            buildTemplate,
            buildAST,
            rewriteMode,
            profile,
            backtracking,
            synpreds,
            memoize,
            numRules,
            fileName,
            ANTLRVersion,
            generatedTimestamp,
            trace,
            scopes,
            superClass,
            literals
            ) ::=
<<

*/
// [The "BSD licence"]
// Copyright (c) 2010 Alan Condit
//
// 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.

// $ANTLR   



/* =============================================================================
 * This is what the grammar programmer asked us to put at the top of every file.
 */

/* End of Header action.
 * =============================================================================
 */


/* -----------------------------------------
 * Include the ANTLR3 generated header file.
 */
#import "LexerTreeParser!>.h"

/* ----------------------------------------- */




/** String literals used by  that we must do things like MATCHS() with.
 *  C will normally just lay down 8 bit characters, and you can use L"xxx" to
 *  get wchar_t, but wchar_t is 16 bits on Windows, which is not UTF32 and so
 *  we perform this little trick of defining the literals as arrays of UINT32
 *  and passing in the address of these.
 */
[]  = ;}; separator="\n">



/* ============================================================================= */

/* =============================================================================
 * Start of recognizer
 */



/* End of code
 * =============================================================================
 */

>>
headerFileExtension() ::= ".h"

headerFile( LEXER,
            PARSER,
            TREE_PARSER,
            actionScope,
            actions,
            docComment,
            recognizer,
            name,
            tokens,
            tokenNames,
            rules,
            cyclicDFAs,
            bitsets,
            buildTemplate,
            buildAST,
            rewriteMode,
            profile,
            backtracking,
            synpreds,
            memoize,
            numRules,
            fileName,
            ANTLRVersion,
            generatedTimestamp,
            trace,
            scopes,
            superClass,
            literals
          ) ::=
<<
// $ANTLR   

<@imports>

/* =============================================================================
 * Standard antlr3 OBJC runtime definitions
 */
#import \
#import "antlr3.h"
/* End of standard antlr3 runtime definitions
 * =============================================================================
 */

<@end>











>>

lexerHeaderFile( LEXER,
            PARSER,
            TREE_PARSER,
            actionScope,
            actions,
            docComment,
            recognizer,
            name,
            tokens,
            tokenNames,
            rules,
            cyclicDFAs,
            bitsets,
            buildTemplate,
            profile,
            backtracking,
            synpreds,
            memoize,
            numRules,
            fileName,
            ANTLRVersion,
            generatedTimestamp,
            trace,
            scopes,
            superClass="ANTLRLexer"
            ) ::=
<<

/* Start cyclicDFAInterface */


#pragma mark Rule return scopes start
}>
}>
#pragma mark Rule return scopes end
#pragma mark Tokens
 }; separator="\n">
 <@superClassName>: <@end> { !>
@interface  <@superClassName>: <@end> { // line 283
 *dfa;}; separator="\n">
Selector;}; separator="\n">
// start of actions.lexer.memVars

// start of action-actionScope-memVars

}
+ ( *)newWithCharStream:(id\)anInput;


}>)m_fragment; }; separator="\n"><\n>
_fragment;}; separator="\n"><\n> !>
@end /* end of  interface */<\n>
>>

headerReturnScope(ruleDescriptor) ::= ""
headerReturnType(ruleDescriptor) ::= <<


 void

 


 

>>
// Produce the lexer output
lexer(  grammar,
        name,
        tokens,
        scopes,
        rules,
        numRules,
        labelType="id",
        filterMode,
        superClass="ANTLRLexer"
        ) ::= <<


/** As per Terence: No returns for lexer rules! */
}>
}>
#pragma mark Rule return scopes end
!>
@implementation  // line 330

+ (void) initialize
{
    [ANTLRBaseRecognizer setGrammarFileName:@""];
}

+ (NSString *) tokenNameForType:(NSInteger)aTokenType
{
    return [[self getTokenNames] objectAtIndex:aTokenType];
}

+ ( *)newWithCharStream:(id\)anInput
{
    return [[ alloc] initWithCharStream:anInput];
}

- (id) initWithCharStream:(id\)anInput
{
    if ((self = [super initWithCharStream:anInput State:[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:+1]]) != nil) {

        if ( state.ruleMemo == nil ) {
            state.ruleMemo = [[ANTLRRuleStack newANTLRRuleStackWithSize:+1] retain];
        }
        if ( [state.ruleMemo count] == 0 ) {
            // initialize the memoization cache - the indices are 1-based in the runtime code!
            
            for (NSInteger i = 0; i \< ; i++) {
                [state.ruleMemo addObject:[ANTLRHashRule newANTLRHashRuleWithLen:17]];
            }
        }

        };separator="\n">
         = [DFA newDFAWithRecognizer:self];}; separator="\n">
        
    }
    return self;
}

- (void) dealloc
{
     release];}; separator="\n">

    [super dealloc];
}

/* Start of actions.lexer.methods */

/* start methods() */
<@methods()>


- (void) reset
{
    
    [super reset];
}





/* Start of Rules */


@end /* end of  implementation line 397 */
>>

/** A override of Lexer.nextToken() that backtracks over mTokens() looking
 *  for matches.  No error can be generated upon error; just rewind, consume
 *  a token and then try again.  backtracking needs to be set as well.
 *  Make rule memoization happen only at levels above 1 as we start mTokens
 *  at backtracking==1.
 */
filteringNextToken() ::= <<
- (id\) nextToken
{
    while (YES) {
        if ( [input LA:1] == ANTLRCharStreamEOF ) {
            return [ANTLRCommonToken eofToken];
        }
        state.token = nil;
        state.channel = ANTLRTokenChannelDefault;
        state.tokenStartCharIndex = [input getIndex];
        state.tokenStartCharPositionInLine = [input getCharPositionInLine];
        state.tokenStartLine = [input getLine];
        state.text = nil;
        @try {
            NSInteger m = [input mark];
            state.backtracking = 1; /* means we won't throw slow exception */
            state.failed = NO;
            [self mTokens];
            state.backtracking = 0;
            /* mTokens backtracks with synpred at backtracking==2
               and we set the synpredgate to allow actions at level 1. */
            if ( state.failed == YES ) {
                [input rewind:m];
                [input consume]; /* advance one char and try again */
            } else {
                [self emit];
                return state.token;
            }
        }
        @catch (ANTLRRecognitionException *re) {
            // shouldn't happen in backtracking mode, but...
            [self reportError:re];
            [self recover:re];
        }
    }
}

- (void)memoize:(id\)anInput
      RuleIndex:(NSInteger)ruleIndex
     StartIndex:(NSInteger)ruleStartIndex
{
    if ( state.backtracking > 1 ) [super memoize:anInput RuleIndex:ruleIndex StartIndex:ruleStartIndex];
}

- (BOOL)alreadyParsedRule:(id\)anInput RuleIndex:(NSInteger)ruleIndex
{
    if ( state.backtracking > 1 ) return [super alreadyParsedRule:anInput RuleIndex:ruleIndex];
    return NO;
}
>>

actionGate() ::= "state.backtracking == 0"

filteringActionGate() ::= "state.backtracking == 1"

parserHeaderFile( LEXER,
            PARSER,
            TREE_PARSER,
            actionScope,
            actions,
            docComment,
            recognizer,
            name,
            tokens,
            tokenNames,
            rules,
            cyclicDFAs,
            bitsets,
            buildTemplate,
            profile,
            backtracking,
            synpreds,
            memoize,
            numRules,
            fileName,
            ANTLRVersion,
            generatedTimestamp,
            trace,
            scopes,
            superClass="ANTLRParser"
            ) ::=
<<
/* parserHeaderFile */

>>

treeParserHeaderFile( LEXER,
            PARSER,
            TREE_PARSER,
            actionScope,
            actions,
            docComment,
            recognizer,
            name,
            tokens,
            tokenNames,
            rules,
            cyclicDFAs,
            bitsets,
            buildTemplate,
            profile,
            backtracking,
            synpreds,
            memoize,
            numRules,
            fileName,
            ANTLRVersion,
            generatedTimestamp,
            trace,
            scopes,
            superClass="ANTLRTreeParser"
            ) ::= 
<<
/* treeParserHeaderFile */

>>

genericParserHeaderFile( LEXER,
            PARSER,
            TREE_PARSER,
            actionScope,
            actions,
            docComment,
            recognizer,
            name,
            tokens,
            tokenNames,
            rules,
            cyclicDFAs,
            bitsets,
            buildTemplate,
            profile,
            backtracking,
            synpreds,
            memoize,
            numRules,
            fileName,
            ANTLRVersion,
            generatedTimestamp,
            trace,
            scopes,
            superClass
            ) ::=
<<

typedef enum {
    ANTLR_EOF = -1,
    INVALID,
    EOR,
    DOWN,
    UP,
    MIN
} ANTLR3TokenType;


#pragma mark Tokens
 }; separator="\n">
#pragma mark Dynamic Global Scopes
}>
#pragma mark Dynamic Rule Scopes
}>
}>
#pragma mark Rule Return Scopes start
}>}>
#pragma mark Rule return scopes end
}>}>}>
#pragma mark Rule return scopes end
!>
 <@superClassName>: <@end> { !>
@interface  <@superClassName>: <@end> { /* line 572 */
// start of globalAttributeScopeMemVar
}><\n>
// start of action-actionScope-memVars

// start of ruleAttributeScopeMemVar
}><\n>
// Start of memVars
<@memVars()>

 *dfa;}; separator="\n">
Selector;}; separator="\n">
 }

// start of action-actionScope-methodsDecl


<@methodsdecl()>

}>)_fragment; }; separator="\n"><\n>
_fragment;}; separator="\n"><\n> !>

@end /* end of  interface */<\n>
>>

/** How to generate a parser */
genericParser(  grammar,
                name,
                scopes,
                tokens,
                tokenNames,
                rules,
                numRules,
                cyclicDFAs,          // parser init -- initializes the DFAs
                bitsets,
                inputStreamType,
                superClass="ANTLRParser",
                ASTLabelType="ANTLRCommonTree",
                labelType="id",
                members,
                rewriteElementType,
                filterMode
              ) ::= <<



#pragma mark Bitsets
_in_}, words64=it.bits)>

#pragma mark Dynamic Global Scopes
}>

#pragma mark Dynamic Rule Scopes

}>

#pragma mark Rule return scopes start
}>
}>

@implementation   // line 637

+ (void) initialize
{
    #pragma mark Bitsets
    _in_}, words64=it.bits)>
    [ANTLRBaseRecognizer setTokenNames:[[[NSArray alloc] initWithObjects:@"\", @"\", @"\", @"\", }; separator=", ", wrap="\n ">, nil] retain]];
    }>
}

+ ( *)new:()aStream
{

    return [[ alloc] initWithTokenStream:aStream];

    return [[ alloc] initWithStream:aStream];
<\n>
}


- (id) initWithTokenStream:()aStream
{
    if ((self = [super initWithTokenStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:+1] retain]]) != nil) {

- (id) initWithStream:()aStream
{
    if ((self = [super initWithStream:aStream State:[[ANTLRRecognizerSharedState newANTLRRecognizerSharedStateWithRuleLen:+1] retain]]) != nil) {
<\n>
         !>
         = [DFA newDFAWithRecognizer:self];}; separator="\n">
        }> !>
        }>
        /* start of actions-actionScope-init */
        
        /* start of init */
        <@init()>
    }
    return self;
}

- (void) dealloc
{
     release];}; separator="\n">
    }>
    
    <@dealloc()>
    [super dealloc];
}
// start actions.actionScope.methods

// start methods()
<@methods()>
// start rules


@end /* end of  implementation line 692 */<\n>
>>

parserCtorBody() ::= <<


state.ruleMemo = [[ANTLRRuleStack newANTLRRuleStack:+1] retain];<\n> 


 = ;}; separator="\n">
>>

parser( grammar,
        name,
        scopes,
        tokens,
        tokenNames,
        rules,
        numRules,
        bitsets,
        ASTLabelType="ANTLRCommonTree",
        superClass="ANTLRParser",
        labelType="ANTLRCommonToken",
        members={}
        ) ::= <<
", rewriteElementType="ANTLRCommonToken", ...)>
>>

treeParser( grammar,
        name,
        scopes,
        tokens,
        tokenNames,
        globalAction,
        rules,
        numRules,
        bitsets,
        ASTLabelType="ANTLRCommonTree",
        superClass={ANTLRTreeRewriterANTLRTreeFilterANTLRTreeParser},
        labelType="ANTLRCommonTree",
        members={},
        filterMode
        ) ::= <<
", rewriteElementType="Node", ...)>
>>

/** A simpler version of a rule template that is specific to the imaginary
 *  rules created for syntactic predicates.  As they never have return values
 *  nor parameters etc..., just give simplest possible method.  Don't do
 *  any of the normal memoization stuff in here either; it's a waste.
 *  As predicates cannot be inlined into the invoking rule, they need to
 *  be in a rule by themselves.
 */
synpredRule(ruleName, ruleDescriptor, block, description, nakedBlock) ::=
<<
// $ANTLR start _fragment
- (void) _fragment
{
    
    
        [self traceIn:\@"_fragment" Index:];
    @try {
        
    }
    @finally {
        [self traceOut:\@"_fragment" Index:];
    }

    

} // $ANTLR end _fragment
>>

synpred(name) ::= <<
SEL Selector = @selector(_fragment);

- (BOOL) 
{
    state.backtracking++;
    <@start()>
    NSInteger start = [input mark];
    @try {
        [self _fragment]; // can never throw exception
    }
    @catch (ANTLRRecognitionException *re) {
        NSLog(@"impossible: %@\n", re);
    }
    BOOL success = (state.failed == NO);
    [input rewind:start];
    <@stop()>
    state.backtracking--;
    state.failed=NO;
    return success;
} // $ANTLR end  <\n> !>
>>

lexerSynpred(name) ::= <<

>>

ruleMemoization(name) ::= <<

if ( state.backtracking && [self alreadyParsedRule:input RuleIndex:] ) return ;

>>

/** How to test for failure and return from rule */
checkRuleBacktrackFailure() ::= <<
if ( state.failed == YES ) return ;
>>

/** This rule has failed, exit indicating failure during backtrack */
ruleBacktrackFailure() ::= <<
if ( state.backtracking > 0 ) { state.failed = YES; return ; }
>>

/** How to generate code for a rule.
 *  The return type aggregates are declared in the header file (headerFile template)
 */
rule(ruleName,ruleDescriptor,block,emptyRule,description,exceptions,finally,memoize) ::= <<
/*
 * $ANTLR start 
 * :
 */
- () 
{
    traceIn("", );
    NSLog(@"enter  %@ failed=%@ backtracking=%d", [input LT:1], (state.failed==YES)?@"YES":@"NO", state.backtracking);
    
    
    
    <@preamble()>
    @try {
        
        
        
        
        <(ruleDescriptor.actions.after):execAction()>
    }

    <\n>}>



    

    @catch (ANTLRRecognitionException *re) {
        [self reportError:re];
        [self recover:input Exception:re];
        <@setErrorReturnValue()>
    }



    @finally {
    traceOut("", );
    NSLog(@"exit  %@ failed=%@ backtracking=%d", [input LT:1], state.failed ? @"YES" : @"NO", state.backtracking);
        
        
        
    }
    <@postamble()>
    return ;
}
/* $ANTLR end  */
>>

finalCode(finalBlock) ::= <<
{
    
}
>>

catch(decl,action) ::= <<
@catch () {
    
}
>>

ruleDeclarations() ::= <<

 retval = [ new];
[retval setStart:[input LT:1]];<\n>

  = ;
}>
 // This is not in the Java.stg
  = ;
 !>


NSInteger _StartIndex = [input getIndex];

>>

ruleScopeSetUp() ::= <<
/* ruleScopeSetUp */
_scope = [[_Scope new_Scope] retain];
[gStack push:_scope];}>
 = [ANTLRSymbolStack newANTLRSymbolStackWithLen:30];
[ruleStack push:[[_Scope new_Scope] retain]];}>
>>

ruleScopeCleanUp() ::= <<

 pop];}; separator="\n">
>>

ruleLabelDefs() ::= <<
<[ruleDescriptor.tokenLabels, ruleDescriptor.tokenListLabels,
  ruleDescriptor.wildcardTreeLabels,ruleDescriptor.wildcardTreeListLabels]
    :{ * = nil;}; separator="\n">
<[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels,ruleDescriptor.wildcardTreeListLabels]
    :{NSMutableArray *list_ = nil;}; separator="\n"
>

 = nil;}; separator="\n">
>>

lexerRuleLabelDefs() ::= <<
<[ruleDescriptor.tokenLabels,
  ruleDescriptor.tokenListLabels,
  ruleDescriptor.ruleLabels]
    :{ *=nil;}; separator="\n"
>
;}; separator="\n">
<[ruleDescriptor.tokenListLabels,
  ruleDescriptor.ruleListLabels]:{NSMutableArray *list_=nil; }; separator="\n">
>>

ruleReturnValue() ::= <<





retval



>>

ruleCleanUp() ::= <<
// token+rule list labels
<[ruleDescriptor.tokenListLabels,ruleDescriptor.ruleListLabels]:{[list_ release];}; separator="\n">


[retval setStop:[input LT:-1]];<\n>


>>

memoize() ::= <<


if (state.backtracking > 0) [self memoize:input RuleIndex: StartIndex:_StartIndex];


>>

/** How to generate a rule in the lexer; naked blocks are used for
 *  fragment rules.
 */
lexerRule(ruleName, nakedBlock, ruleDescriptor, block, memoize) ::= <<
// $ANTLR start ""
- (void) m
{
    //[self traceIn:[NSString stringWithFormat:@" %d\n", ]];
    NSLog(@"enter  %C line=%d:%d failed=%@ backtracking=%d",
        [input LA:1],
        [self getLine],
        [self getCharPositionInLine],
        (state.failed==YES) ? @"YES" : @"NO",
        state.backtracking);
    
    
    
    @try {

        
        
        
        <\n>

        NSInteger _type = ;
        NSInteger _channel = ANTLRTokenChannelDefault;
        
        
        
        
        
        [state setType:_type];<\n>
        state.channel = _channel;
        <(ruleDescriptor.actions.after):execAction()>

    }
    @finally {
        //[self traceOut:[NSString stringWithFormat:@" %d\n", ]];
        NSLog(@"exit  %C line=%d:%d failed=%@ backtracking=%d",
                    [input LA:1], [self getLine], [self getCharPositionInLine],
                    (state.failed==YES) ? @"YES" : @"NO", state.backtracking);
        
        
    }
    return;
}
// $ANTLR end ""
>>

/** How to generate code for the implicitly-defined lexer grammar rule
 *  that chooses between lexer rules.
 */
tokensRule(ruleName,nakedBlock,args,block,ruleDescriptor) ::= <<
- (void) mTokens
{
    <\n>
}
>>

// S U B R U L E S

/** A (...) subrule with multiple alternatives */
block(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<
// : // block
NSInteger alt=;

<@predecision()>

<@postdecision()>
<@prebranch()>
switch (alt) {
    
}
<@postbranch()>
>>

/** A rule block with multiple alternatives */
ruleBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<
// : //ruleblock
NSInteger alt=;

<@predecision()>

<@postdecision()>
switch (alt) {
    
}
>>

ruleBlockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<
// : // ruleBlockSingleAlt

<@prealt()>

<@postalt()>
>>

/** A special case of a (...) subrule with a single alternative */
blockSingleAlt(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,description) ::= <<
// : // blockSingleAlt

<@prealt()>

<@postalt()>
>>

/** A (..)+ block with 1 or more alternatives */
positiveClosureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<
// : // positiveClosureBlock
NSInteger cnt=0;

<@preloop()>
do {
    NSInteger alt=;
    <@predecision()>
    
    <@postdecision()>
    switch (alt) {
        
        default :
            if ( cnt >= 1 )
                goto loop;

            

            ANTLREarlyExitException *eee = [ANTLREarlyExitException exceptionWithStream:input decisionNumber:];
            <@earlyExitException()>
            @throw eee;
    }
    cnt++;
} while (YES);
loop: ;
<@postloop()>
>>

positiveClosureBlockSingleAlt ::= positiveClosureBlock

/** A (..)* block with 0 or more alternatives */
closureBlock(alts,decls,decision,enclosingBlockLevel,blockLevel,decisionNumber,maxK,maxAlt,description) ::= <<

<@preloop()>
do {
    NSInteger alt=;
    <@predecision()>
    
    <@postdecision()>
    switch (alt) {
        
        default :
            goto loop;
    }
} while (YES);
loop: ;
<@postloop()>
>>

closureBlockSingleAlt ::= closureBlock

/** Optional blocks (x)? are translated to (x|) by before code generation
 *  so we can just use the normal block template
 */
optionalBlock ::= block

optionalBlockSingleAlt ::= block

/** A case in a switch that jumps to an alternative given the alternative
 *  number.  A DFA predicts the alternative and then a simple switch
 *  does the jump to the code that actually matches that alternative.
 */
altSwitchCase() ::= <<
case  : ;
    <@prealt()>
    
    break;<\n>
>>

/** An alternative is just a list of elements; at outermost level */
alt(elements,altNum,description,autoAST,outerAlt,treeLevel,rew) ::= <<
// : // alt
{
<@declarations()>
 /* elements */

<@cleanup()>
}
>>

/** What to emit when there is no rewrite.  For auto build
 *  mode, does nothing.
 */
noRewrite(rewriteBlockLevel, treeLevel) ::= ""

// E L E M E N T S

/** Dump the elements one per line */
element() ::= <<
<@prematch()>
  /* element() */<\n>
>>

/** match a token optionally with a label in front */
tokenRef(token,label,elementIndex,hetero) ::= <<