//throws RecognitionException, TokenStreamException
        public void template(
		StringTemplateGroup g
	)
        {
            IToken  name = null;
            IToken  t = null;
            IToken  alias = null;
            IToken  target = null;

            IDictionary formalArgs = null;
            StringTemplate st = null;
            bool ignore = false;

            try {      // for error handling
            if ((LA(1)==ID) && (LA(2)==LPAREN))
            {
                name = LT(1);
                match(ID);

                        if ( g.isDefinedInThisGroup(name.getText()) ) {
                            g.error("redefinition of template: "+name.getText());
                            st = new StringTemplate(); // create bogus template to fill in
                        }
                        else {
                            st = g.defineTemplate(name.getText(), null);
                        }

                match(LPAREN);
                {
                    switch ( LA(1) )
                    {
                    case ID:
                    {
                        args(st);
                        break;
                    }
                    case RPAREN:
                    {
                        st.defineEmptyFormalArgumentList();
                        break;
                    }
                    default:
                    {
                        throw new NoViableAltException(LT(1), getFilename());
                    }
                     }
                }
                match(RPAREN);
                match(DEFINED_TO_BE);
                t = LT(1);
                match(TEMPLATE);
                st.setTemplate(t.getText());
            }
            else if ((LA(1)==ID) && (LA(2)==DEFINED_TO_BE)) {
                alias = LT(1);
                match(ID);
                match(DEFINED_TO_BE);
                target = LT(1);
                match(ID);
                g.defineTemplateAlias(alias.getText(), target.getText());
            }
            else
            {
                throw new NoViableAltException(LT(1), getFilename());
            }

            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            recover(ex,tokenSet_1_);
            }
        }