Esempio n. 1
0
        //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_);
            }
        }
Esempio n. 2
0
        //throws RecognitionException, TokenStreamException
        public void mapdef(
		StringTemplateGroup g
	)
        {
            IToken  name = null;

            IDictionary m=null;

            try {      // for error handling
            name = LT(1);
            match(ID);
            match(DEFINED_TO_BE);
            m=map();

                    if ( g.getMap(name.getText())!=null ) {
                        g.error("redefinition of map: "+name.getText());
                    }
                    else if ( g.isDefinedInThisGroup(name.getText()) ) {
                        g.error("redefinition of template as map: "+name.getText());
                    }
                    else {
                        g.defineMap(name.getText(), m);
                    }

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