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

org.stringtemplate.v4.compiler.GroupParser Maven / Gradle / Ivy

Go to download

StringTemplate is a java template engine for generating source code, web pages, emails, or any other formatted text output. StringTemplate is particularly good at multi-targeted code generators, multiple site skins, and internationalization/localization. It evolved over years of effort developing jGuru.com. StringTemplate also generates the stringtemplate website: http://www.stringtemplate.org and powers the ANTLR v3 code generator. Its distinguishing characteristic is that unlike other engines, it strictly enforces model-view separation. Strict separation makes websites and code generators more flexible and maintainable; it also provides an excellent defense against malicious template authors. There are currently about 600 StringTemplate source downloads a month.

The newest version!
// $ANTLR 3.3 Nov 30, 2010 12:46:29 org/stringtemplate/v4/compiler/Group.g 2011-05-19 10:13:25

/*
 * [The "BSD license"]
 *  Copyright (c) 2011 Terence Parr
 *  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.
 */
package org.stringtemplate.v4.compiler;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import org.stringtemplate.v4.misc.*;
import org.stringtemplate.v4.*;
import java.io.File;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;

public class GroupParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "", "", "", "", "TRUE", "FALSE", "STRING", "ID", "BIGSTRING", "BIGSTRING_NO_NL", "ANONYMOUS_TEMPLATE", "COMMENT", "LINE_COMMENT", "WS", "'import'", "'.'", "'group'", "':'", "'implements'", "','", "';'", "'@'", "'('", "')'", "'::='", "'='", "'['", "']'", "'default'"
    };
    public static final int EOF=-1;
    public static final int T__14=14;
    public static final int T__15=15;
    public static final int T__16=16;
    public static final int T__17=17;
    public static final int T__18=18;
    public static final int T__19=19;
    public static final int T__20=20;
    public static final int T__21=21;
    public static final int T__22=22;
    public static final int T__23=23;
    public static final int T__24=24;
    public static final int T__25=25;
    public static final int T__26=26;
    public static final int T__27=27;
    public static final int T__28=28;
    public static final int TRUE=4;
    public static final int FALSE=5;
    public static final int STRING=6;
    public static final int ID=7;
    public static final int BIGSTRING=8;
    public static final int BIGSTRING_NO_NL=9;
    public static final int ANONYMOUS_TEMPLATE=10;
    public static final int COMMENT=11;
    public static final int LINE_COMMENT=12;
    public static final int WS=13;

    // delegates
    // delegators


        public GroupParser(TokenStream input) {
            this(input, new RecognizerSharedState());
        }
        public GroupParser(TokenStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        

    public String[] getTokenNames() { return GroupParser.tokenNames; }
    public String getGrammarFileName() { return "org/stringtemplate/v4/compiler/Group.g"; }


    public STGroup group;

    public void displayRecognitionError(String[] tokenNames,
                                        RecognitionException e)
    {
        String msg = getErrorMessage(e, tokenNames);
        group.errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, getSourceName(), e, msg);
    }
    public String getSourceName() {
        String fullFileName = super.getSourceName();
        File f = new File(fullFileName); // strip to simple name
        return f.getName();
    }
    public void error(String msg) {
        NoViableAltException e = new NoViableAltException("", 0, 0, input);
        group.errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, getSourceName(), e, msg);
        recover(input, null);
    }



    // $ANTLR start "group"
    // org/stringtemplate/v4/compiler/Group.g:150:1: group[STGroup group, String prefix] : ( oldStyleHeader )? ( 'import' STRING | 'import' ID ( '.' ID )* )* ( def[prefix] )+ ;
    public final void group(STGroup group, String prefix) throws RecognitionException {
        Token STRING1=null;


        GroupLexer lexer = (GroupLexer)input.getTokenSource();
        this.group = lexer.group = group;

        try {
            // org/stringtemplate/v4/compiler/Group.g:155:2: ( ( oldStyleHeader )? ( 'import' STRING | 'import' ID ( '.' ID )* )* ( def[prefix] )+ )
            // org/stringtemplate/v4/compiler/Group.g:155:4: ( oldStyleHeader )? ( 'import' STRING | 'import' ID ( '.' ID )* )* ( def[prefix] )+
            {
            // org/stringtemplate/v4/compiler/Group.g:155:4: ( oldStyleHeader )?
            int alt1=2;
            switch ( input.LA(1) ) {
                case 16:
                    {
                    alt1=1;
                    }
                    break;
            }

            switch (alt1) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:155:4: oldStyleHeader
                    {
                    pushFollow(FOLLOW_oldStyleHeader_in_group65);
                    oldStyleHeader();

                    state._fsp--;


                    }
                    break;

            }

            // org/stringtemplate/v4/compiler/Group.g:156:6: ( 'import' STRING | 'import' ID ( '.' ID )* )*
            loop3:
            do {
                int alt3=3;
                switch ( input.LA(1) ) {
                case 14:
                    {
                    switch ( input.LA(2) ) {
                    case STRING:
                        {
                        alt3=1;
                        }
                        break;
                    case ID:
                        {
                        alt3=2;
                        }
                        break;

                    }

                    }
                    break;

                }

                switch (alt3) {
            	case 1 :
            	    // org/stringtemplate/v4/compiler/Group.g:156:8: 'import' STRING
            	    {
            	    match(input,14,FOLLOW_14_in_group75); 
            	    STRING1=(Token)match(input,STRING,FOLLOW_STRING_in_group77); 
            	    group.importTemplates(STRING1);

            	    }
            	    break;
            	case 2 :
            	    // org/stringtemplate/v4/compiler/Group.g:157:5: 'import' ID ( '.' ID )*
            	    {
            	    match(input,14,FOLLOW_14_in_group85); 

            	    			MismatchedTokenException e = new MismatchedTokenException(STRING, input);
            	    			reportError(e);
            	    			
            	    match(input,ID,FOLLOW_ID_in_group96); 
            	    // org/stringtemplate/v4/compiler/Group.g:162:7: ( '.' ID )*
            	    loop2:
            	    do {
            	        int alt2=2;
            	        switch ( input.LA(1) ) {
            	        case 15:
            	            {
            	            alt2=1;
            	            }
            	            break;

            	        }

            	        switch (alt2) {
            	    	case 1 :
            	    	    // org/stringtemplate/v4/compiler/Group.g:162:8: '.' ID
            	    	    {
            	    	    match(input,15,FOLLOW_15_in_group99); 
            	    	    match(input,ID,FOLLOW_ID_in_group101); 

            	    	    }
            	    	    break;

            	    	default :
            	    	    break loop2;
            	        }
            	    } while (true);


            	    }
            	    break;

            	default :
            	    break loop3;
                }
            } while (true);

            // org/stringtemplate/v4/compiler/Group.g:164:9: ( def[prefix] )+
            int cnt4=0;
            loop4:
            do {
                int alt4=2;
                switch ( input.LA(1) ) {
                case ID:
                case 21:
                    {
                    alt4=1;
                    }
                    break;

                }

                switch (alt4) {
            	case 1 :
            	    // org/stringtemplate/v4/compiler/Group.g:164:9: def[prefix]
            	    {
            	    pushFollow(FOLLOW_def_in_group119);
            	    def(prefix);

            	    state._fsp--;


            	    }
            	    break;

            	default :
            	    if ( cnt4 >= 1 ) break loop4;
                        EarlyExitException eee =
                            new EarlyExitException(4, input);
                        throw eee;
                }
                cnt4++;
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "group"


    // $ANTLR start "oldStyleHeader"
    // org/stringtemplate/v4/compiler/Group.g:167:1: oldStyleHeader : 'group' ID ( ':' ID )? ( 'implements' ID ( ',' ID )* )? ';' ;
    public final void oldStyleHeader() throws RecognitionException {
        try {
            // org/stringtemplate/v4/compiler/Group.g:168:5: ( 'group' ID ( ':' ID )? ( 'implements' ID ( ',' ID )* )? ';' )
            // org/stringtemplate/v4/compiler/Group.g:168:9: 'group' ID ( ':' ID )? ( 'implements' ID ( ',' ID )* )? ';'
            {
            match(input,16,FOLLOW_16_in_oldStyleHeader141); 
            match(input,ID,FOLLOW_ID_in_oldStyleHeader143); 
            // org/stringtemplate/v4/compiler/Group.g:168:20: ( ':' ID )?
            int alt5=2;
            switch ( input.LA(1) ) {
                case 17:
                    {
                    alt5=1;
                    }
                    break;
            }

            switch (alt5) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:168:22: ':' ID
                    {
                    match(input,17,FOLLOW_17_in_oldStyleHeader147); 
                    match(input,ID,FOLLOW_ID_in_oldStyleHeader149); 

                    }
                    break;

            }

            // org/stringtemplate/v4/compiler/Group.g:169:6: ( 'implements' ID ( ',' ID )* )?
            int alt7=2;
            switch ( input.LA(1) ) {
                case 18:
                    {
                    alt7=1;
                    }
                    break;
            }

            switch (alt7) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:169:8: 'implements' ID ( ',' ID )*
                    {
                    match(input,18,FOLLOW_18_in_oldStyleHeader161); 
                    match(input,ID,FOLLOW_ID_in_oldStyleHeader163); 
                    // org/stringtemplate/v4/compiler/Group.g:169:24: ( ',' ID )*
                    loop6:
                    do {
                        int alt6=2;
                        switch ( input.LA(1) ) {
                        case 19:
                            {
                            alt6=1;
                            }
                            break;

                        }

                        switch (alt6) {
                    	case 1 :
                    	    // org/stringtemplate/v4/compiler/Group.g:169:25: ',' ID
                    	    {
                    	    match(input,19,FOLLOW_19_in_oldStyleHeader166); 
                    	    match(input,ID,FOLLOW_ID_in_oldStyleHeader168); 

                    	    }
                    	    break;

                    	default :
                    	    break loop6;
                        }
                    } while (true);


                    }
                    break;

            }

            match(input,20,FOLLOW_20_in_oldStyleHeader180); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "oldStyleHeader"


    // $ANTLR start "groupName"
    // org/stringtemplate/v4/compiler/Group.g:173:1: groupName returns [String name] : a= ID ( '.' a= ID )* ;
    public final String groupName() throws RecognitionException {
        String name = null;

        Token a=null;

        StringBuilder buf = new StringBuilder();
        try {
            // org/stringtemplate/v4/compiler/Group.g:175:2: (a= ID ( '.' a= ID )* )
            // org/stringtemplate/v4/compiler/Group.g:175:4: a= ID ( '.' a= ID )*
            {
            a=(Token)match(input,ID,FOLLOW_ID_in_groupName202); 
            buf.append((a!=null?a.getText():null));
            // org/stringtemplate/v4/compiler/Group.g:175:32: ( '.' a= ID )*
            loop8:
            do {
                int alt8=2;
                switch ( input.LA(1) ) {
                case 15:
                    {
                    alt8=1;
                    }
                    break;

                }

                switch (alt8) {
            	case 1 :
            	    // org/stringtemplate/v4/compiler/Group.g:175:33: '.' a= ID
            	    {
            	    match(input,15,FOLLOW_15_in_groupName207); 
            	    a=(Token)match(input,ID,FOLLOW_ID_in_groupName211); 
            	    buf.append((a!=null?a.getText():null));

            	    }
            	    break;

            	default :
            	    break loop8;
                }
            } while (true);


            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return name;
    }
    // $ANTLR end "groupName"


    // $ANTLR start "def"
    // org/stringtemplate/v4/compiler/Group.g:178:1: def[String prefix] : ( templateDef[prefix] | dictDef );
    public final void def(String prefix) throws RecognitionException {
        try {
            // org/stringtemplate/v4/compiler/Group.g:182:20: ( templateDef[prefix] | dictDef )
            int alt9=2;
            switch ( input.LA(1) ) {
            case 21:
                {
                alt9=1;
                }
                break;
            case ID:
                {
                switch ( input.LA(2) ) {
                case 22:
                    {
                    alt9=1;
                    }
                    break;
                case 24:
                    {
                    switch ( input.LA(3) ) {
                    case ID:
                        {
                        alt9=1;
                        }
                        break;
                    case 26:
                        {
                        alt9=2;
                        }
                        break;
                    default:
                        NoViableAltException nvae =
                            new NoViableAltException("", 9, 3, input);

                        throw nvae;
                    }

                    }
                    break;
                default:
                    NoViableAltException nvae =
                        new NoViableAltException("", 9, 2, input);

                    throw nvae;
                }

                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 9, 0, input);

                throw nvae;
            }

            switch (alt9) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:182:22: templateDef[prefix]
                    {
                    pushFollow(FOLLOW_templateDef_in_def228);
                    templateDef(prefix);

                    state._fsp--;


                    }
                    break;
                case 2 :
                    // org/stringtemplate/v4/compiler/Group.g:182:44: dictDef
                    {
                    pushFollow(FOLLOW_dictDef_in_def233);
                    dictDef();

                    state._fsp--;


                    }
                    break;

            }
        }
        catch (RecognitionException re) {

            		// pretend we already saw an error here
            		state.lastErrorIndex = input.index();
            		error("garbled template definition starting at '"+input.LT(1).getText()+"'");
            	
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "def"


    // $ANTLR start "templateDef"
    // org/stringtemplate/v4/compiler/Group.g:189:1: templateDef[String prefix] : ( ( '@' enclosing= ID '.' name= ID '(' ')' | name= ID '(' formalArgs ')' ) '::=' ( STRING | BIGSTRING | BIGSTRING_NO_NL | ) | alias= ID '::=' target= ID );
    public final void templateDef(String prefix) throws RecognitionException {
        Token enclosing=null;
        Token name=null;
        Token alias=null;
        Token target=null;
        Token STRING2=null;
        Token BIGSTRING3=null;
        Token BIGSTRING_NO_NL4=null;
        List formalArgs5 = null;



            String template=null;
            int n=0; // num char to strip from left, right of template def

        try {
            // org/stringtemplate/v4/compiler/Group.g:194:2: ( ( '@' enclosing= ID '.' name= ID '(' ')' | name= ID '(' formalArgs ')' ) '::=' ( STRING | BIGSTRING | BIGSTRING_NO_NL | ) | alias= ID '::=' target= ID )
            int alt12=2;
            switch ( input.LA(1) ) {
            case 21:
                {
                alt12=1;
                }
                break;
            case ID:
                {
                switch ( input.LA(2) ) {
                case 22:
                    {
                    alt12=1;
                    }
                    break;
                case 24:
                    {
                    alt12=2;
                    }
                    break;
                default:
                    NoViableAltException nvae =
                        new NoViableAltException("", 12, 2, input);

                    throw nvae;
                }

                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 12, 0, input);

                throw nvae;
            }

            switch (alt12) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:194:4: ( '@' enclosing= ID '.' name= ID '(' ')' | name= ID '(' formalArgs ')' ) '::=' ( STRING | BIGSTRING | BIGSTRING_NO_NL | )
                    {
                    // org/stringtemplate/v4/compiler/Group.g:194:4: ( '@' enclosing= ID '.' name= ID '(' ')' | name= ID '(' formalArgs ')' )
                    int alt10=2;
                    switch ( input.LA(1) ) {
                    case 21:
                        {
                        alt10=1;
                        }
                        break;
                    case ID:
                        {
                        alt10=2;
                        }
                        break;
                    default:
                        NoViableAltException nvae =
                            new NoViableAltException("", 10, 0, input);

                        throw nvae;
                    }

                    switch (alt10) {
                        case 1 :
                            // org/stringtemplate/v4/compiler/Group.g:194:6: '@' enclosing= ID '.' name= ID '(' ')'
                            {
                            match(input,21,FOLLOW_21_in_templateDef257); 
                            enclosing=(Token)match(input,ID,FOLLOW_ID_in_templateDef261); 
                            match(input,15,FOLLOW_15_in_templateDef263); 
                            name=(Token)match(input,ID,FOLLOW_ID_in_templateDef267); 
                            match(input,22,FOLLOW_22_in_templateDef269); 
                            match(input,23,FOLLOW_23_in_templateDef271); 

                            }
                            break;
                        case 2 :
                            // org/stringtemplate/v4/compiler/Group.g:195:5: name= ID '(' formalArgs ')'
                            {
                            name=(Token)match(input,ID,FOLLOW_ID_in_templateDef279); 
                            match(input,22,FOLLOW_22_in_templateDef281); 
                            pushFollow(FOLLOW_formalArgs_in_templateDef283);
                            formalArgs5=formalArgs();

                            state._fsp--;

                            match(input,23,FOLLOW_23_in_templateDef285); 

                            }
                            break;

                    }

                    match(input,24,FOLLOW_24_in_templateDef296); 
                    Token templateToken = input.LT(1);
                    // org/stringtemplate/v4/compiler/Group.g:199:6: ( STRING | BIGSTRING | BIGSTRING_NO_NL | )
                    int alt11=4;
                    switch ( input.LA(1) ) {
                    case STRING:
                        {
                        alt11=1;
                        }
                        break;
                    case BIGSTRING:
                        {
                        alt11=2;
                        }
                        break;
                    case BIGSTRING_NO_NL:
                        {
                        alt11=3;
                        }
                        break;
                    case EOF:
                    case ID:
                    case 21:
                        {
                        alt11=4;
                        }
                        break;
                    default:
                        NoViableAltException nvae =
                            new NoViableAltException("", 11, 0, input);

                        throw nvae;
                    }

                    switch (alt11) {
                        case 1 :
                            // org/stringtemplate/v4/compiler/Group.g:199:8: STRING
                            {
                            STRING2=(Token)match(input,STRING,FOLLOW_STRING_in_templateDef312); 
                            template=(STRING2!=null?STRING2.getText():null); n=1;

                            }
                            break;
                        case 2 :
                            // org/stringtemplate/v4/compiler/Group.g:200:8: BIGSTRING
                            {
                            BIGSTRING3=(Token)match(input,BIGSTRING,FOLLOW_BIGSTRING_in_templateDef327); 
                            template=(BIGSTRING3!=null?BIGSTRING3.getText():null); n=2;

                            }
                            break;
                        case 3 :
                            // org/stringtemplate/v4/compiler/Group.g:201:8: BIGSTRING_NO_NL
                            {
                            BIGSTRING_NO_NL4=(Token)match(input,BIGSTRING_NO_NL,FOLLOW_BIGSTRING_NO_NL_in_templateDef339); 
                            template=(BIGSTRING_NO_NL4!=null?BIGSTRING_NO_NL4.getText():null); n=2;

                            }
                            break;
                        case 4 :
                            // org/stringtemplate/v4/compiler/Group.g:202:8: 
                            {

                            	    	template = "";
                            	    	String msg = "missing template at '"+input.LT(1).getText()+"'";
                                        NoViableAltException e = new NoViableAltException("", 0, 0, input);
                                	    group.errMgr.groupSyntaxError(ErrorType.SYNTAX_ERROR, getSourceName(), e, msg);
                                	    

                            }
                            break;

                    }


                    	    if ( (name!=null?name.getTokenIndex():0) >= 0 ) { // if ID missing
                    			template = Misc.strip(template, n);
                    			String templateName = (name!=null?name.getText():null);
                    			if ( prefix.length()>0 ) templateName = prefix+"/"+(name!=null?name.getText():null);
                    			group.defineTemplateOrRegion(templateName, (enclosing!=null?enclosing.getText():null), templateToken,
                    										 template, name, formalArgs5);
                    		}
                    	    

                    }
                    break;
                case 2 :
                    // org/stringtemplate/v4/compiler/Group.g:218:6: alias= ID '::=' target= ID
                    {
                    alias=(Token)match(input,ID,FOLLOW_ID_in_templateDef374); 
                    match(input,24,FOLLOW_24_in_templateDef376); 
                    target=(Token)match(input,ID,FOLLOW_ID_in_templateDef380); 
                    group.defineTemplateAlias(alias, target);

                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "templateDef"

    protected static class formalArgs_scope {
        boolean hasOptionalParameter;
    }
    protected Stack formalArgs_stack = new Stack();


    // $ANTLR start "formalArgs"
    // org/stringtemplate/v4/compiler/Group.g:221:1: formalArgs returns [List args = new ArrayList()] : ( formalArg[$args] ( ',' formalArg[$args] )* | );
    public final List formalArgs() throws RecognitionException {
        formalArgs_stack.push(new formalArgs_scope());
        List args =  new ArrayList();

         ((formalArgs_scope)formalArgs_stack.peek()).hasOptionalParameter = false; 
        try {
            // org/stringtemplate/v4/compiler/Group.g:226:2: ( formalArg[$args] ( ',' formalArg[$args] )* | )
            int alt14=2;
            switch ( input.LA(1) ) {
            case ID:
                {
                alt14=1;
                }
                break;
            case 23:
                {
                alt14=2;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 14, 0, input);

                throw nvae;
            }

            switch (alt14) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:226:4: formalArg[$args] ( ',' formalArg[$args] )*
                    {
                    pushFollow(FOLLOW_formalArg_in_formalArgs406);
                    formalArg(args);

                    state._fsp--;

                    // org/stringtemplate/v4/compiler/Group.g:226:21: ( ',' formalArg[$args] )*
                    loop13:
                    do {
                        int alt13=2;
                        switch ( input.LA(1) ) {
                        case 19:
                            {
                            alt13=1;
                            }
                            break;

                        }

                        switch (alt13) {
                    	case 1 :
                    	    // org/stringtemplate/v4/compiler/Group.g:226:22: ',' formalArg[$args]
                    	    {
                    	    match(input,19,FOLLOW_19_in_formalArgs410); 
                    	    pushFollow(FOLLOW_formalArg_in_formalArgs412);
                    	    formalArg(args);

                    	    state._fsp--;


                    	    }
                    	    break;

                    	default :
                    	    break loop13;
                        }
                    } while (true);


                    }
                    break;
                case 2 :
                    // org/stringtemplate/v4/compiler/Group.g:228:2: 
                    {
                    }
                    break;

            }
        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
            formalArgs_stack.pop();
        }
        return args;
    }
    // $ANTLR end "formalArgs"


    // $ANTLR start "formalArg"
    // org/stringtemplate/v4/compiler/Group.g:230:1: formalArg[List args] : ID ( '=' a= ( STRING | ANONYMOUS_TEMPLATE | 'true' | 'false' ) | ) ;
    public final void formalArg(List args) throws RecognitionException {
        Token a=null;
        Token ID6=null;

        try {
            // org/stringtemplate/v4/compiler/Group.g:231:2: ( ID ( '=' a= ( STRING | ANONYMOUS_TEMPLATE | 'true' | 'false' ) | ) )
            // org/stringtemplate/v4/compiler/Group.g:231:4: ID ( '=' a= ( STRING | ANONYMOUS_TEMPLATE | 'true' | 'false' ) | )
            {
            ID6=(Token)match(input,ID,FOLLOW_ID_in_formalArg430); 
            // org/stringtemplate/v4/compiler/Group.g:232:3: ( '=' a= ( STRING | ANONYMOUS_TEMPLATE | 'true' | 'false' ) | )
            int alt15=2;
            switch ( input.LA(1) ) {
            case 25:
                {
                alt15=1;
                }
                break;
            case 19:
            case 23:
                {
                alt15=2;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 15, 0, input);

                throw nvae;
            }

            switch (alt15) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:232:5: '=' a= ( STRING | ANONYMOUS_TEMPLATE | 'true' | 'false' )
                    {
                    match(input,25,FOLLOW_25_in_formalArg436); 
                    a=(Token)input.LT(1);
                    if ( (input.LA(1)>=TRUE && input.LA(1)<=STRING)||input.LA(1)==ANONYMOUS_TEMPLATE ) {
                        input.consume();
                        state.errorRecovery=false;
                    }
                    else {
                        MismatchedSetException mse = new MismatchedSetException(null,input);
                        throw mse;
                    }

                    ((formalArgs_scope)formalArgs_stack.peek()).hasOptionalParameter = true;

                    }
                    break;
                case 2 :
                    // org/stringtemplate/v4/compiler/Group.g:233:5: 
                    {

                    			if (((formalArgs_scope)formalArgs_stack.peek()).hasOptionalParameter) {
                    				group.errMgr.compileTimeError(ErrorType.REQUIRED_PARAMETER_AFTER_OPTIONAL,
                    				 							  null, ID6);
                    			}
                    			

                    }
                    break;

            }

            args.add(new FormalArgument((ID6!=null?ID6.getText():null), a));

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "formalArg"


    // $ANTLR start "dictDef"
    // org/stringtemplate/v4/compiler/Group.g:252:1: dictDef : ID '::=' dict ;
    public final void dictDef() throws RecognitionException {
        Token ID7=null;
        Map dict8 = null;


        try {
            // org/stringtemplate/v4/compiler/Group.g:253:2: ( ID '::=' dict )
            // org/stringtemplate/v4/compiler/Group.g:253:4: ID '::=' dict
            {
            ID7=(Token)match(input,ID,FOLLOW_ID_in_dictDef481); 
            match(input,24,FOLLOW_24_in_dictDef483); 
            pushFollow(FOLLOW_dict_in_dictDef485);
            dict8=dict();

            state._fsp--;


                    if ( group.rawGetDictionary((ID7!=null?ID7.getText():null))!=null ) {
            			group.errMgr.compileTimeError(ErrorType.MAP_REDEFINITION, null, ID7);
                    }
                    else if ( group.rawGetTemplate((ID7!=null?ID7.getText():null))!=null ) {
            			group.errMgr.compileTimeError(ErrorType.TEMPLATE_REDEFINITION_AS_MAP, null, ID7);
                    }
                    else {
                        group.defineDictionary((ID7!=null?ID7.getText():null), dict8);
                    }
                    

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "dictDef"


    // $ANTLR start "dict"
    // org/stringtemplate/v4/compiler/Group.g:267:1: dict returns [Map mapping] : '[' dictPairs[mapping] ']' ;
    public final Map dict() throws RecognitionException {
        Map mapping = null;

        mapping=new HashMap();
        try {
            // org/stringtemplate/v4/compiler/Group.g:269:2: ( '[' dictPairs[mapping] ']' )
            // org/stringtemplate/v4/compiler/Group.g:269:6: '[' dictPairs[mapping] ']'
            {
            match(input,26,FOLLOW_26_in_dict517); 
            pushFollow(FOLLOW_dictPairs_in_dict519);
            dictPairs(mapping);

            state._fsp--;

            match(input,27,FOLLOW_27_in_dict522); 

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return mapping;
    }
    // $ANTLR end "dict"


    // $ANTLR start "dictPairs"
    // org/stringtemplate/v4/compiler/Group.g:272:1: dictPairs[Map mapping] : ( keyValuePair[mapping] ( ',' keyValuePair[mapping] )* ( ',' defaultValuePair[mapping] )? | defaultValuePair[mapping] );
    public final void dictPairs(Map mapping) throws RecognitionException {
        try {
            // org/stringtemplate/v4/compiler/Group.g:273:5: ( keyValuePair[mapping] ( ',' keyValuePair[mapping] )* ( ',' defaultValuePair[mapping] )? | defaultValuePair[mapping] )
            int alt18=2;
            switch ( input.LA(1) ) {
            case STRING:
                {
                alt18=1;
                }
                break;
            case 28:
                {
                alt18=2;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("", 18, 0, input);

                throw nvae;
            }

            switch (alt18) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:273:7: keyValuePair[mapping] ( ',' keyValuePair[mapping] )* ( ',' defaultValuePair[mapping] )?
                    {
                    pushFollow(FOLLOW_keyValuePair_in_dictPairs537);
                    keyValuePair(mapping);

                    state._fsp--;

                    // org/stringtemplate/v4/compiler/Group.g:274:6: ( ',' keyValuePair[mapping] )*
                    loop16:
                    do {
                        int alt16=2;
                        switch ( input.LA(1) ) {
                        case 19:
                            {
                            switch ( input.LA(2) ) {
                            case STRING:
                                {
                                alt16=1;
                                }
                                break;

                            }

                            }
                            break;

                        }

                        switch (alt16) {
                    	case 1 :
                    	    // org/stringtemplate/v4/compiler/Group.g:274:7: ',' keyValuePair[mapping]
                    	    {
                    	    match(input,19,FOLLOW_19_in_dictPairs546); 
                    	    pushFollow(FOLLOW_keyValuePair_in_dictPairs548);
                    	    keyValuePair(mapping);

                    	    state._fsp--;


                    	    }
                    	    break;

                    	default :
                    	    break loop16;
                        }
                    } while (true);

                    // org/stringtemplate/v4/compiler/Group.g:274:35: ( ',' defaultValuePair[mapping] )?
                    int alt17=2;
                    switch ( input.LA(1) ) {
                        case 19:
                            {
                            alt17=1;
                            }
                            break;
                    }

                    switch (alt17) {
                        case 1 :
                            // org/stringtemplate/v4/compiler/Group.g:274:36: ',' defaultValuePair[mapping]
                            {
                            match(input,19,FOLLOW_19_in_dictPairs554); 
                            pushFollow(FOLLOW_defaultValuePair_in_dictPairs556);
                            defaultValuePair(mapping);

                            state._fsp--;


                            }
                            break;

                    }


                    }
                    break;
                case 2 :
                    // org/stringtemplate/v4/compiler/Group.g:275:7: defaultValuePair[mapping]
                    {
                    pushFollow(FOLLOW_defaultValuePair_in_dictPairs567);
                    defaultValuePair(mapping);

                    state._fsp--;


                    }
                    break;

            }
        }
        catch (RecognitionException re) {

            		error("missing dictionary entry at '"+input.LT(1).getText()+"'");
            	
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "dictPairs"


    // $ANTLR start "defaultValuePair"
    // org/stringtemplate/v4/compiler/Group.g:281:1: defaultValuePair[Map mapping] : 'default' ':' keyValue ;
    public final void defaultValuePair(Map mapping) throws RecognitionException {
        Object keyValue9 = null;


        try {
            // org/stringtemplate/v4/compiler/Group.g:282:2: ( 'default' ':' keyValue )
            // org/stringtemplate/v4/compiler/Group.g:282:4: 'default' ':' keyValue
            {
            match(input,28,FOLLOW_28_in_defaultValuePair590); 
            match(input,17,FOLLOW_17_in_defaultValuePair592); 
            pushFollow(FOLLOW_keyValue_in_defaultValuePair594);
            keyValue9=keyValue();

            state._fsp--;

            mapping.put(STGroup.DEFAULT_KEY, keyValue9);

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "defaultValuePair"


    // $ANTLR start "keyValuePair"
    // org/stringtemplate/v4/compiler/Group.g:285:1: keyValuePair[Map mapping] : STRING ':' keyValue ;
    public final void keyValuePair(Map mapping) throws RecognitionException {
        Token STRING10=null;
        Object keyValue11 = null;


        try {
            // org/stringtemplate/v4/compiler/Group.g:286:2: ( STRING ':' keyValue )
            // org/stringtemplate/v4/compiler/Group.g:286:4: STRING ':' keyValue
            {
            STRING10=(Token)match(input,STRING,FOLLOW_STRING_in_keyValuePair608); 
            match(input,17,FOLLOW_17_in_keyValuePair610); 
            pushFollow(FOLLOW_keyValue_in_keyValuePair612);
            keyValue11=keyValue();

            state._fsp--;

            mapping.put(Misc.replaceEscapes(Misc.strip((STRING10!=null?STRING10.getText():null), 1)), keyValue11);

            }

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return ;
    }
    // $ANTLR end "keyValuePair"


    // $ANTLR start "keyValue"
    // org/stringtemplate/v4/compiler/Group.g:289:1: keyValue returns [Object value] : ( BIGSTRING | BIGSTRING_NO_NL | ANONYMOUS_TEMPLATE | STRING | TRUE | FALSE | {...}? => ID );
    public final Object keyValue() throws RecognitionException {
        Object value = null;

        Token BIGSTRING12=null;
        Token BIGSTRING_NO_NL13=null;
        Token ANONYMOUS_TEMPLATE14=null;
        Token STRING15=null;

        try {
            // org/stringtemplate/v4/compiler/Group.g:290:2: ( BIGSTRING | BIGSTRING_NO_NL | ANONYMOUS_TEMPLATE | STRING | TRUE | FALSE | {...}? => ID )
            int alt19=7;
            int LA19_0 = input.LA(1);

            if ( (LA19_0==BIGSTRING) ) {
                alt19=1;
            }
            else if ( (LA19_0==BIGSTRING_NO_NL) ) {
                alt19=2;
            }
            else if ( (LA19_0==ANONYMOUS_TEMPLATE) ) {
                alt19=3;
            }
            else if ( (LA19_0==STRING) ) {
                alt19=4;
            }
            else if ( (LA19_0==TRUE) ) {
                alt19=5;
            }
            else if ( (LA19_0==FALSE) ) {
                alt19=6;
            }
            else if ( (LA19_0==ID) && ((input.LT(1).getText().equals("key")))) {
                alt19=7;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 19, 0, input);

                throw nvae;
            }
            switch (alt19) {
                case 1 :
                    // org/stringtemplate/v4/compiler/Group.g:290:4: BIGSTRING
                    {
                    BIGSTRING12=(Token)match(input,BIGSTRING,FOLLOW_BIGSTRING_in_keyValue629); 
                    value = group.createSingleton(BIGSTRING12);

                    }
                    break;
                case 2 :
                    // org/stringtemplate/v4/compiler/Group.g:291:4: BIGSTRING_NO_NL
                    {
                    BIGSTRING_NO_NL13=(Token)match(input,BIGSTRING_NO_NL,FOLLOW_BIGSTRING_NO_NL_in_keyValue638); 
                    value = group.createSingleton(BIGSTRING_NO_NL13);

                    }
                    break;
                case 3 :
                    // org/stringtemplate/v4/compiler/Group.g:292:4: ANONYMOUS_TEMPLATE
                    {
                    ANONYMOUS_TEMPLATE14=(Token)match(input,ANONYMOUS_TEMPLATE,FOLLOW_ANONYMOUS_TEMPLATE_in_keyValue646); 
                    value = group.createSingleton(ANONYMOUS_TEMPLATE14);

                    }
                    break;
                case 4 :
                    // org/stringtemplate/v4/compiler/Group.g:293:4: STRING
                    {
                    STRING15=(Token)match(input,STRING,FOLLOW_STRING_in_keyValue653); 
                    value = Misc.replaceEscapes(Misc.strip((STRING15!=null?STRING15.getText():null), 1));

                    }
                    break;
                case 5 :
                    // org/stringtemplate/v4/compiler/Group.g:294:4: TRUE
                    {
                    match(input,TRUE,FOLLOW_TRUE_in_keyValue663); 
                    value = true;

                    }
                    break;
                case 6 :
                    // org/stringtemplate/v4/compiler/Group.g:295:4: FALSE
                    {
                    match(input,FALSE,FOLLOW_FALSE_in_keyValue673); 
                    value = false;

                    }
                    break;
                case 7 :
                    // org/stringtemplate/v4/compiler/Group.g:296:4: {...}? => ID
                    {
                    if ( !((input.LT(1).getText().equals("key"))) ) {
                        throw new FailedPredicateException(input, "keyValue", "input.LT(1).getText().equals(\"key\")");
                    }
                    match(input,ID,FOLLOW_ID_in_keyValue686); 
                    value = STGroup.DICT_KEY;

                    }
                    break;

            }
        }
        catch (RecognitionException re) {

            		error("missing value for key at '"+input.LT(1).getText()+"'");
            	
        }
        finally {
        }
        return value;
    }
    // $ANTLR end "keyValue"

    // Delegated rules


 

    public static final BitSet FOLLOW_oldStyleHeader_in_group65 = new BitSet(new long[]{0x0000000000204080L});
    public static final BitSet FOLLOW_14_in_group75 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_STRING_in_group77 = new BitSet(new long[]{0x0000000000204080L});
    public static final BitSet FOLLOW_14_in_group85 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_group96 = new BitSet(new long[]{0x000000000020C080L});
    public static final BitSet FOLLOW_15_in_group99 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_group101 = new BitSet(new long[]{0x000000000020C080L});
    public static final BitSet FOLLOW_def_in_group119 = new BitSet(new long[]{0x0000000000204082L});
    public static final BitSet FOLLOW_16_in_oldStyleHeader141 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_oldStyleHeader143 = new BitSet(new long[]{0x0000000000160000L});
    public static final BitSet FOLLOW_17_in_oldStyleHeader147 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_oldStyleHeader149 = new BitSet(new long[]{0x0000000000140000L});
    public static final BitSet FOLLOW_18_in_oldStyleHeader161 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_oldStyleHeader163 = new BitSet(new long[]{0x0000000000180000L});
    public static final BitSet FOLLOW_19_in_oldStyleHeader166 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_oldStyleHeader168 = new BitSet(new long[]{0x0000000000180000L});
    public static final BitSet FOLLOW_20_in_oldStyleHeader180 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_groupName202 = new BitSet(new long[]{0x0000000000008002L});
    public static final BitSet FOLLOW_15_in_groupName207 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_groupName211 = new BitSet(new long[]{0x0000000000008002L});
    public static final BitSet FOLLOW_templateDef_in_def228 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_dictDef_in_def233 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_21_in_templateDef257 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_templateDef261 = new BitSet(new long[]{0x0000000000008000L});
    public static final BitSet FOLLOW_15_in_templateDef263 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_templateDef267 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_22_in_templateDef269 = new BitSet(new long[]{0x0000000000800000L});
    public static final BitSet FOLLOW_23_in_templateDef271 = new BitSet(new long[]{0x0000000001000000L});
    public static final BitSet FOLLOW_ID_in_templateDef279 = new BitSet(new long[]{0x0000000000400000L});
    public static final BitSet FOLLOW_22_in_templateDef281 = new BitSet(new long[]{0x0000000000800080L});
    public static final BitSet FOLLOW_formalArgs_in_templateDef283 = new BitSet(new long[]{0x0000000000800000L});
    public static final BitSet FOLLOW_23_in_templateDef285 = new BitSet(new long[]{0x0000000001000000L});
    public static final BitSet FOLLOW_24_in_templateDef296 = new BitSet(new long[]{0x0000000000000342L});
    public static final BitSet FOLLOW_STRING_in_templateDef312 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_BIGSTRING_in_templateDef327 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_BIGSTRING_NO_NL_in_templateDef339 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_templateDef374 = new BitSet(new long[]{0x0000000001000000L});
    public static final BitSet FOLLOW_24_in_templateDef376 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_ID_in_templateDef380 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_formalArg_in_formalArgs406 = new BitSet(new long[]{0x0000000000080002L});
    public static final BitSet FOLLOW_19_in_formalArgs410 = new BitSet(new long[]{0x0000000000000080L});
    public static final BitSet FOLLOW_formalArg_in_formalArgs412 = new BitSet(new long[]{0x0000000000080002L});
    public static final BitSet FOLLOW_ID_in_formalArg430 = new BitSet(new long[]{0x0000000002000002L});
    public static final BitSet FOLLOW_25_in_formalArg436 = new BitSet(new long[]{0x0000000000000470L});
    public static final BitSet FOLLOW_set_in_formalArg440 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_dictDef481 = new BitSet(new long[]{0x0000000001000000L});
    public static final BitSet FOLLOW_24_in_dictDef483 = new BitSet(new long[]{0x0000000004000000L});
    public static final BitSet FOLLOW_dict_in_dictDef485 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_26_in_dict517 = new BitSet(new long[]{0x0000000010000040L});
    public static final BitSet FOLLOW_dictPairs_in_dict519 = new BitSet(new long[]{0x0000000008000000L});
    public static final BitSet FOLLOW_27_in_dict522 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_keyValuePair_in_dictPairs537 = new BitSet(new long[]{0x0000000000080002L});
    public static final BitSet FOLLOW_19_in_dictPairs546 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_keyValuePair_in_dictPairs548 = new BitSet(new long[]{0x0000000000080002L});
    public static final BitSet FOLLOW_19_in_dictPairs554 = new BitSet(new long[]{0x0000000010000040L});
    public static final BitSet FOLLOW_defaultValuePair_in_dictPairs556 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_defaultValuePair_in_dictPairs567 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_28_in_defaultValuePair590 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_17_in_defaultValuePair592 = new BitSet(new long[]{0x00000000000007F0L});
    public static final BitSet FOLLOW_keyValue_in_defaultValuePair594 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_keyValuePair608 = new BitSet(new long[]{0x0000000000020000L});
    public static final BitSet FOLLOW_17_in_keyValuePair610 = new BitSet(new long[]{0x00000000000007F0L});
    public static final BitSet FOLLOW_keyValue_in_keyValuePair612 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_BIGSTRING_in_keyValue629 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_BIGSTRING_NO_NL_in_keyValue638 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ANONYMOUS_TEMPLATE_in_keyValue646 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_keyValue653 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_TRUE_in_keyValue663 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_FALSE_in_keyValue673 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_keyValue686 = new BitSet(new long[]{0x0000000000000002L});

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy