Пример #1
0
    public void lstmt()     //throws RecognitionException, TokenStreamException
    {
        returnAST = null;
        ASTPair currentAST = new ASTPair();
        AST     lstmt_AST  = null;

        try {              // for error handling
            if ((tokenSet_3_.member(LA(1))) && (tokenSet_5_.member(LA(2))))
            {
                stmt();
                astFactory.addASTChild(ref currentAST, returnAST);
                lstmt_AST       = (AST)currentAST.root;
                lstmt_AST       = (AST)astFactory.make(astFactory.create(STMT, "STMT"), lstmt_AST);
                currentAST.root = lstmt_AST;
                if ((null != lstmt_AST) && (null != lstmt_AST.getFirstChild()))
                {
                    currentAST.child = lstmt_AST.getFirstChild();
                }
                else
                {
                    currentAST.child = lstmt_AST;
                }
                currentAST.advanceChildToEnd();
                lstmt_AST = currentAST.root;
            }
            else if ((LA(1) == ID) && (LA(2) == COLON))
            {
                AST tmp14_AST = null;
                tmp14_AST = astFactory.create(LT(1));
                astFactory.addASTChild(ref currentAST, tmp14_AST);
                match(ID);
                match(COLON);
                stmt();
                astFactory.addASTChild(ref currentAST, returnAST);
                lstmt_AST       = (AST)currentAST.root;
                lstmt_AST       = (AST)astFactory.make(astFactory.create(LSTMT, "LSTMT"), lstmt_AST);
                currentAST.root = lstmt_AST;
                if ((null != lstmt_AST) && (null != lstmt_AST.getFirstChild()))
                {
                    currentAST.child = lstmt_AST.getFirstChild();
                }
                else
                {
                    currentAST.child = lstmt_AST;
                }
                currentAST.advanceChildToEnd();
                lstmt_AST = currentAST.root;
            }
            else
            {
                throw new NoViableAltException(LT(1), getFilename());
            }
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            recover(ex, tokenSet_6_);
        }
        returnAST = lstmt_AST;
    }
Пример #2
0
    public void decider()     //throws RecognitionException, TokenStreamException
    {
        returnAST = null;
        ASTPair currentAST  = new ASTPair();
        AST     decider_AST = null;

        try {              // for error handling
            {
                switch (LA(1))
                {
                case QMARK:
                {
                    AST tmp60_AST = null;
                    tmp60_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp60_AST);
                    match(QMARK);
                    break;
                }

                case ID:
                case LPAREN:
                case EMARK:
                case CONST:
                {
                    expr();
                    astFactory.addASTChild(ref currentAST, returnAST);
                    break;
                }

                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                }
            }
            decider_AST     = (AST)currentAST.root;
            decider_AST     = (AST)astFactory.make(astFactory.create(DECIDER, "DECIDER"), decider_AST);
            currentAST.root = decider_AST;
            if ((null != decider_AST) && (null != decider_AST.getFirstChild()))
            {
                currentAST.child = decider_AST.getFirstChild();
            }
            else
            {
                currentAST.child = decider_AST;
            }
            currentAST.advanceChildToEnd();
            decider_AST = currentAST.root;
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            recover(ex, tokenSet_10_);
        }
        returnAST = decider_AST;
    }
Пример #3
0
        public void visit(AST node)
        {
            // Flatten this level of the tree if it has no children
            bool flatten = /*true*/ false;
            AST  node2;

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (node2.getFirstChild() != null)
                {
                    flatten = false;
                    break;
                }
            }

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (!flatten || node2 == node)
                {
                    tabs();
                }
                if (node2.getText() == null)
                {
                    Console.Out.Write("nil");
                }
                else
                {
                    Console.Out.Write(node2.getText());
                }

                Console.Out.Write(" [" + node2.Type + "] ");

                if (flatten)
                {
                    Console.Out.Write(" ");
                }
                else
                {
                    Console.Out.WriteLine("");
                }

                if (node2.getFirstChild() != null)
                {
                    level++;
                    visit(node2.getFirstChild());
                    level--;
                }
            }

            if (flatten)
            {
                Console.Out.WriteLine("");
            }
        }
Пример #4
0
    public void sseq()     //throws RecognitionException, TokenStreamException
    {
        returnAST = null;
        ASTPair currentAST = new ASTPair();
        AST     sseq_AST   = null;

        try {             // for error handling
            {             // ( ... )+
                int _cnt18 = 0;
                for (;;)
                {
                    if ((tokenSet_3_.member(LA(1))))
                    {
                        lstmt();
                        astFactory.addASTChild(ref currentAST, returnAST);
                    }
                    else
                    {
                        if (_cnt18 >= 1)
                        {
                            goto _loop18_breakloop;
                        }
                        else
                        {
                            throw new NoViableAltException(LT(1), getFilename());;
                        }
                    }

                    _cnt18++;
                }
                _loop18_breakloop :;
            }                // ( ... )+
            sseq_AST        = (AST)currentAST.root;
            sseq_AST        = (AST)astFactory.make(astFactory.create(SSEQ, "SSEQ"), sseq_AST);
            currentAST.root = sseq_AST;
            if ((null != sseq_AST) && (null != sseq_AST.getFirstChild()))
            {
                currentAST.child = sseq_AST.getFirstChild();
            }
            else
            {
                currentAST.child = sseq_AST;
            }
            currentAST.advanceChildToEnd();
            sseq_AST = currentAST.root;
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            recover(ex, tokenSet_4_);
        }
        returnAST = sseq_AST;
    }
Пример #5
0
        public void visit(AST node)
        {
            // Flatten this level of the tree if it has no children
            bool flatten = /*true*/ false;
            AST node2;
            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (node2.getFirstChild() != null)
                {
                    flatten = false;
                    break;
                }
            }

            for (node2 = node; node2 != null; node2 = node2.getNextSibling())
            {
                if (!flatten || node2 == node)
                {
                    tabs();
                }
                if (node2.getText() == null)
                {
                    Console.Out.Write("nil");
                }
                else
                {
                    Console.Out.Write(node2.getText());
                }

                Console.Out.Write(" [" + node2.Type + "] ");

                if (flatten)
                {
                    Console.Out.Write(" ");
                }
                else
                {
                    Console.Out.WriteLine("");
                }

                if (node2.getFirstChild() != null)
                {
                    level++;
                    visit(node2.getFirstChild());
                    level--;
                }
            }

            if (flatten)
            {
                Console.Out.WriteLine("");
            }
        }
Пример #6
0
        /*Is 'sub' a subtree of this list?
         *  The siblings of the root are NOT ignored.
         */
        public virtual bool EqualsListPartial(AST sub)
        {
            AST sibling;

            // the empty tree is always a subset of any tree.
            if (sub == null)
            {
                return(true);
            }

            // Otherwise, start walking sibling lists.  First mismatch, return false.
            for (sibling = this; sibling != null && sub != null; sibling = sibling.getNextSibling(), sub = sub.getNextSibling())
            {
                // as a quick optimization, check roots first.
                if (!sibling.Equals(sub))
                {
                    return(false);
                }
                // if roots match, do partial list match test on children.
                if (sibling.getFirstChild() != null)
                {
                    if (!sibling.getFirstChild().EqualsListPartial(sub.getFirstChild()))
                    {
                        return(false);
                    }
                }
            }
            if (sibling == null && sub != null)
            {
                // nothing left to match in this tree, but subtree has more
                return(false);
            }
            // either both are null or sibling has more, but subtree doesn't
            return(true);
        }
Пример #7
0
    /** Is t an exact structural match of this tree with the same node
     *  types?  'self' is considered the start of a sibling list.
     */
    protected bool equalsNodeTypesList(AST self, AST t)
    {
        // Console.Out.WriteLine("self="+self+", t="+t);
        // Console.Out.WriteLine("self.class="+self.getClass()+", t.class="+t.getClass());
        AST sibling;

        // the empty tree is not a match of any non-null tree.
        if (t == null)
        {
            return(false);
        }

        // Otherwise, start walking sibling lists.  First mismatch, return false.
        for (sibling = self;
             sibling != null && t != null;
             sibling = sibling.getNextSibling(), t = t.getNextSibling())
        {
            // Console.Out.WriteLine("sibling="+sibling+", t="+t);
            // as a quick optimization, check root types first.
            if (sibling.GetType() != t.GetType())
            {
                return(false);
            }
            // if roots match, do full list match test on children.
            if (sibling.getFirstChild() != null)
            {
                if (!equalsNodeTypesList(sibling.getFirstChild(),
                                         t.getFirstChild()))
                {
                    return(false);
                }
            }
            // sibling has no kids, make sure t doesn't either
            else if (t.getFirstChild() != null)
            {
                return(false);
            }
        }
        if (sibling == null && t == null)
        {
            return(true);
        }
        // one sibling list has more than the other
        return(false);
    }
Пример #8
0
        public virtual string ToStringTree()
        {
            AST    t  = this;
            string ts = "";

            if (t.getFirstChild() != null)
            {
                ts += " (";
            }
            ts += " " + this.ToString();
            if (t.getFirstChild() != null)
            {
                ts += ((BaseAST)t.getFirstChild()).ToStringList();
            }
            if (t.getFirstChild() != null)
            {
                ts += " )";
            }
            return(ts);
        }
Пример #9
0
        /// <summary>
        /// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
        /// </summary>
        /// <param name="t">Root of AST Node tree.</param>
        /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
        public virtual AST dupTree(AST t)
        {
            AST result = dup(t);             // make copy of root

            // copy all children of root.
            if (t != null)
            {
                result.setFirstChild(dupList(t.getFirstChild()));
            }
            return(result);
        }
Пример #10
0
 /*Is tree rooted at 'this' equal to 't'?  The siblings
  *  of 'this' are ignored.
  */
 public virtual bool EqualsTree(AST t)
 {
     // check roots first.
     if (!this.Equals(t))
     {
         return(false);
     }
     // if roots match, do full list match test on children.
     if (this.getFirstChild() != null)
     {
         if (!this.getFirstChild().EqualsList(t.getFirstChild()))
         {
             return(false);
         }
     }
     else if (t.getFirstChild() != null)
     {
         return(false);
     }
     return(true);
 }
Пример #11
0
        /// <summary>
        /// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
        /// </summary>
        /// <param name="t">Root of AST Node tree.</param>
        /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
        public override AST dupTree(AST t)
        {
            AST result = dup(t);             // make copy of root

            // copy all children of root.
            if (t != null)
            {
                AST d = dupList(t.getFirstChild());
                result.setFirstChild(d);
                ((ASTNode)d).setParent((ASTNode)result);
            }
            return(result);
        }
Пример #12
0
        public virtual void xmlSerialize(TextWriter outWriter)
        {
            // print out this node and all siblings
            for (AST node = this; node != null; node = node.getNextSibling())
            {
                if (node.getFirstChild() == null)
                {
                    // print guts (class name, attributes)
                    ((BaseAST)node).xmlSerializeNode(outWriter);
                }
                else
                {
                    ((BaseAST)node).xmlSerializeRootOpen(outWriter);

                    // print children
                    ((BaseAST)node.getFirstChild()).xmlSerialize(outWriter);

                    // print end tag
                    ((BaseAST)node).xmlSerializeRootClose(outWriter);
                }
            }
        }
Пример #13
0
        /*Is t an exact structural and equals() match of this tree.  The
         *  'this' reference is considered the start of a sibling list.
         */
        public virtual bool EqualsList(AST t)
        {
            AST sibling;

            // the empty tree is not a match of any non-null tree.
            if (t == null)
            {
                return(false);
            }

            // Otherwise, start walking sibling lists.  First mismatch, return false.
            for (sibling = this; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling())
            {
                // as a quick optimization, check roots first.
                if (!sibling.Equals(t))
                {
                    return(false);
                }
                // if roots match, do full list match test on children.
                if (sibling.getFirstChild() != null)
                {
                    if (!sibling.getFirstChild().EqualsList(t.getFirstChild()))
                    {
                        return(false);
                    }
                }
                else if (t.getFirstChild() != null)
                {
                    return(false);
                }
            }
            if (sibling == null && t == null)
            {
                return(true);
            }
            // one sibling list has more than the other
            return(false);
        }
Пример #14
0
        /// <summary>
        /// Make a tree from a list of nodes.  The first element in the
        /// array is the root.  If the root is null, then the tree is
        /// a simple list not a tree.  Handles null children nodes correctly.
        /// For example, build(a, b, null, c) yields tree (a b c).  build(null,a,b)
        /// yields tree (nil a b).
        /// </summary>
        /// <param name="nodes">List of Nodes.</param>
        /// <returns>AST Node tree.</returns>
        public override AST make(params AST[] nodes)
        {
            if (nodes == null || nodes.Length == 0)
            {
                return(null);
            }
            AST root = nodes[0];
            AST tail = null;

            if (root != null)
            {
                root.setFirstChild(null);                 // don't leave any old pointers set
            }
            // link in children;
            for (int i = 1; i < nodes.Length; i++)
            {
                if (nodes[i] == null)
                {
                    continue;
                }
                // ignore null nodes
                if (root == null)
                {
                    // Set the root and set it up for a flat list
                    root = (tail = nodes[i]);
                }
                else if (tail == null)
                {
                    root.setFirstChild(nodes[i]);
                    ((ASTNode)nodes[i]).setParent((ASTNode)root);
                    tail = root.getFirstChild();
                }
                else
                {
                    ((ASTNode)nodes[i]).setParent((ASTNode)root);
                    tail.setNextSibling(nodes[i]);
                    ((ASTNode)nodes[i]).setPreviousSibling((ASTNode)tail);
                    tail = tail.getNextSibling();
                }
                // Chase tail to last sibling
                while (tail.getNextSibling() != null)
                {
                    tail = tail.getNextSibling();
                }
            }
            return(root);
        }
Пример #15
0
        internal static void tree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            ASTTreeNode thisNode  = (ASTTreeNode)e.Node;
            AST         parentAST = thisNode.ASTNode;
            AST         childAST;

            if (!thisNode.IsAlreadyExpanded)
            {
                thisNode.Nodes.Clear();
                childAST = parentAST.getFirstChild();
                while (null != childAST)
                {
                    thisNode.Nodes.Add(new ASTTreeNode(childAST));
                    childAST = childAST.getNextSibling();
                }
                thisNode.IsAlreadyExpanded = true;
            }
        }
Пример #16
0
        /*Is 't' a subtree of the tree rooted at 'this'?  The siblings
         *  of 'this' are ignored.
         */
        public virtual bool EqualsTreePartial(AST sub)
        {
            // the empty tree is always a subset of any tree.
            if (sub == null)
            {
                return(true);
            }

            // check roots first.
            if (!this.Equals(sub))
            {
                return(false);
            }
            // if roots match, do full list partial match test on children.
            if (this.getFirstChild() != null)
            {
                if (!this.getFirstChild().EqualsListPartial(sub.getFirstChild()))
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #17
0
 /// <summary>
 /// Duplicate AST Node tree rooted at specified AST node. Ignore it's siblings.
 /// </summary>
 /// <param name="t">Root of AST Node tree.</param>
 /// <returns>Root node of new AST Node tree (or null if <c>t</c> is null).</returns>
 public virtual AST dupTree(AST t)
 {
     AST result = dup(t); // make copy of root
     // copy all children of root.
     if (t != null)
     {
         result.setFirstChild(dupList(t.getFirstChild()));
     }
     return result;
 }
Пример #18
0
        //throws RecognitionException
        public void singleTemplateArg(AST _t,
		StringTemplate embedded, IDictionary argumentContext
	)
        {
            antlr.stringtemplate.language.StringTemplateAST singleTemplateArg_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            Object e = null;

            try {      // for error handling
            AST __t41 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp22_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,SINGLEVALUEARG);
            _t = _t.getFirstChild();
            e=expr(_t);
            _t = retTree_;
            _t = __t41;
            _t = _t.getNextSibling();

                    if ( e!=null ) {
                        String soleArgName = null;
                        // find the sole defined formal argument for embedded
                        bool error = false;
                        IDictionary formalArgs = embedded.getFormalArguments();
                        if ( formalArgs!=null )
                        {
                            ICollection argNames = formalArgs.Keys;
                            if ( argNames.Count==1 )
                            {
                                string[] argNamesArray = new string[argNames.Count];
                                argNames.CopyTo(argNamesArray,0);
                                soleArgName = argNamesArray[0];
                                //System.out.println("sole formal arg of "+embedded.getName()+" is "+soleArgName);
                            }
                            else
                            {
                                error=true;
                            }
                        }
                        else
                        {
                            error=true;
                        }
                        if ( error )
                        {
                            self.error("template "+embedded.getName()+
                                       " must have exactly one formal arg in template context "+
                                       self.getEnclosingInstanceStackString());
                       	}
                       	else
                       	{
                       		self.rawSetArgumentAttribute(embedded,argumentContext,soleArgName,e);
                       	}
                    }

            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
        }
Пример #19
0
        //throws RecognitionException
        /** create a new list of expressions as a new multi-value attribute */
        public Object list(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST list_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            Object e = null;
            IList elements = new ArrayList();
            value = new CatIterator(elements);

            try {      // for error handling
            AST __t6 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp14_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,LIST);
            _t = _t.getFirstChild();
            { // ( ... )+
                int _cnt8=0;
                for (;;)
                {
                    if (_t == null)
                        _t = ASTNULL;
                    if ((tokenSet_0_.member(_t.Type)))
                    {
                        e=expr(_t);
                        _t = retTree_;

                                      	if ( e!=null ) {
                                            e = ASTExpr.convertAnythingToIterator(e);
                                      		elements.Add(e);
                                      	}

                    }
                    else
                    {
                        if (_cnt8 >= 1) { goto _loop8_breakloop; } else { throw new NoViableAltException(_t);; }
                    }

                    _cnt8++;
                }
            _loop8_breakloop:				;
            }    // ( ... )+
            _t = __t6;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #20
0
        //throws RecognitionException
        public Object function(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST function_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            Object a;

            try {      // for error handling
            AST __t21 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp10_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,FUNCTION);
            _t = _t.getFirstChild();
            {
                if (null == _t)
                    _t = ASTNULL;
                switch ( _t.Type )
                {
                case LITERAL_first:
                {
                    antlr.stringtemplate.language.StringTemplateAST tmp11_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_first);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.first(a);
                    break;
                }
                case LITERAL_rest:
                {
                    antlr.stringtemplate.language.StringTemplateAST tmp12_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_rest);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.rest(a);
                    break;
                }
                case LITERAL_last:
                {
                    antlr.stringtemplate.language.StringTemplateAST tmp13_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_last);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.last(a);
                    break;
                }
                default:
                {
                    throw new NoViableAltException(_t);
                }
                 }
            }
            _t = __t21;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #21
0
        //throws RecognitionException
        public Object attribute(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST attribute_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST prop = null;
            antlr.stringtemplate.language.StringTemplateAST i3 = null;
            antlr.stringtemplate.language.StringTemplateAST i = null;
            antlr.stringtemplate.language.StringTemplateAST s = null;
            antlr.stringtemplate.language.StringTemplateAST at = null;

            Object obj = null;
            String propName = null;
            Object e = null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case DOT:
            {
                AST __t33 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp6_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,DOT);
                _t = _t.getFirstChild();
                obj=expr(_t);
                _t = retTree_;
                {
                    if (null == _t)
                        _t = ASTNULL;
                    switch ( _t.Type )
                    {
                    case ID:
                    {
                        prop = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                        match((AST)_t,ID);
                        _t = _t.getNextSibling();
                        propName = prop.getText();
                        break;
                    }
                    case VALUE:
                    {
                        AST __t35 = _t;
                        antlr.stringtemplate.language.StringTemplateAST tmp7_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                        match((AST)_t,VALUE);
                        _t = _t.getFirstChild();
                        e=expr(_t);
                        _t = retTree_;
                        _t = __t35;
                        _t = _t.getNextSibling();
                        if (e!=null) {propName=e.ToString();}
                        break;
                    }
                    default:
                    {
                        throw new NoViableAltException(_t);
                    }
                     }
                }
                _t = __t33;
                _t = _t.getNextSibling();
                value = chunk.getObjectProperty(self,obj,propName);
                break;
            }
            case ID:
            {
                i3 = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ID);
                _t = _t.getNextSibling();

                value=self.getAttribute(i3.getText());

                break;
            }
            case INT:
            {
                i = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,INT);
                _t = _t.getNextSibling();
                value=Int32.Parse(i.getText());
                break;
            }
            case STRING:
            {
                s = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,STRING);
                _t = _t.getNextSibling();

                    value=s.getText();

                break;
            }
            case ANONYMOUS_TEMPLATE:
            {
                at = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ANONYMOUS_TEMPLATE);
                _t = _t.getNextSibling();

                    value=at.getText();
                        if ( at.getText()!=null ) {
                            StringTemplate valueST =new StringTemplate(self.getGroup(), at.getText());
                            valueST.setEnclosingInstance(self);
                            valueST.setName("<anonymous template argument>");
                            value = valueST;
                    }

                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #22
0
        //throws RecognitionException
        /** self is assumed to be the enclosing context as foo(x=y) must find y in
         *  the template that encloses the ref to foo(x=y).  We must pass in
         *  the embedded template (the one invoked) so we can check formal args
         *  in rawSetArgumentAttribute.
         */
        public IDictionary argList(AST _t,
		StringTemplate embedded, IDictionary initialContext
	)
        {
            IDictionary argumentContext=null;

            antlr.stringtemplate.language.StringTemplateAST argList_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            argumentContext = initialContext;
            if ( argumentContext==null ) {
            argumentContext=new Hashtable();
            }

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case ARGS:
            {
                AST __t37 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp19_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ARGS);
                _t = _t.getFirstChild();
                {    // ( ... )*
                    for (;;)
                    {
                        if (_t == null)
                            _t = ASTNULL;
                        if ((_t.Type==ASSIGN||_t.Type==DOTDOTDOT))
                        {
                            argumentAssignment(_t,embedded,argumentContext);
                            _t = retTree_;
                        }
                        else
                        {
                            goto _loop39_breakloop;
                        }

                    }
            _loop39_breakloop:					;
                }    // ( ... )*
                _t = __t37;
                _t = _t.getNextSibling();
                break;
            }
            case SINGLEVALUEARG:
            {
                singleTemplateArg(_t,embedded,argumentContext);
                _t = retTree_;
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return argumentContext;
        }
Пример #23
0
        //throws RecognitionException
        /** Apply template(s) to an attribute; can be applied to another apply
         *  result.
         */
        public Object templateApplication(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST templateApplication_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST anon = null;

            Object a=null;
            ArrayList templatesToApply=new ArrayList();
            ArrayList attributes=new ArrayList();

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case APPLY:
            {
                AST __t14 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp3_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,APPLY);
                _t = _t.getFirstChild();
                a=expr(_t);
                _t = retTree_;
                { // ( ... )+
                    int _cnt16=0;
                    for (;;)
                    {
                        if (_t == null)
                            _t = ASTNULL;
                        if ((_t.Type==TEMPLATE))
                        {
                            template(_t,templatesToApply);
                            _t = retTree_;
                        }
                        else
                        {
                            if (_cnt16 >= 1) { goto _loop16_breakloop; } else { throw new NoViableAltException(_t);; }
                        }

                        _cnt16++;
                    }
            _loop16_breakloop:					;
                }    // ( ... )+
                value = chunk.applyListOfAlternatingTemplates(self,a,templatesToApply);
                _t = __t14;
                _t = _t.getNextSibling();
                break;
            }
            case MULTI_APPLY:
            {
                AST __t17 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp4_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,MULTI_APPLY);
                _t = _t.getFirstChild();
                { // ( ... )+
                    int _cnt19=0;
                    for (;;)
                    {
                        if (_t == null)
                            _t = ASTNULL;
                        if ((tokenSet_0_.member(_t.Type)))
                        {
                            a=expr(_t);
                            _t = retTree_;
                            attributes.Add(a);
                        }
                        else
                        {
                            if (_cnt19 >= 1) { goto _loop19_breakloop; } else { throw new NoViableAltException(_t);; }
                        }

                        _cnt19++;
                    }
            _loop19_breakloop:					;
                }    // ( ... )+
                antlr.stringtemplate.language.StringTemplateAST tmp5_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,COLON);
                _t = _t.getNextSibling();
                anon = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ANONYMOUS_TEMPLATE);
                _t = _t.getNextSibling();

                            StringTemplate anonymous = anon.getStringTemplate();
                            templatesToApply.Add(anonymous);
                            value = chunk.applyTemplateToListOfAttributes(self,
                                                                          attributes,
                                                                          anon.getStringTemplate());

                _t = __t17;
                _t = _t.getNextSibling();
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #24
0
    public void expr()     //throws RecognitionException, TokenStreamException
    {
        returnAST = null;
        ASTPair currentAST = new ASTPair();
        AST     expr_AST   = null;

        try {              // for error handling
            {
                switch (LA(1))
                {
                case EMARK:
                {
                    AST tmp54_AST = null;
                    tmp54_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp54_AST);
                    match(EMARK);
                    expr();
                    astFactory.addASTChild(ref currentAST, returnAST);
                    break;
                }

                case LPAREN:
                {
                    match(LPAREN);
                    expr();
                    astFactory.addASTChild(ref currentAST, returnAST);
                    match(RPAREN);
                    break;
                }

                case ID:
                {
                    AST tmp57_AST = null;
                    tmp57_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp57_AST);
                    match(ID);
                    break;
                }

                case CONST:
                {
                    AST tmp58_AST = null;
                    tmp58_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp58_AST);
                    match(CONST);
                    break;
                }

                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                }
            }
            {
                if ((LA(1) == BINOP) && (tokenSet_7_.member(LA(2))))
                {
                    AST tmp59_AST = null;
                    tmp59_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp59_AST);
                    match(BINOP);
                    expr();
                    astFactory.addASTChild(ref currentAST, returnAST);
                }
                else if ((tokenSet_8_.member(LA(1))) && (tokenSet_9_.member(LA(2))))
                {
                }
                else
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
            }
            expr_AST        = (AST)currentAST.root;
            expr_AST        = (AST)astFactory.make(astFactory.create(EXPR, "EXPR"), expr_AST);
            currentAST.root = expr_AST;
            if ((null != expr_AST) && (null != expr_AST.getFirstChild()))
            {
                currentAST.child = expr_AST.getFirstChild();
            }
            else
            {
                currentAST.child = expr_AST;
            }
            currentAST.advanceChildToEnd();
            expr_AST = currentAST.root;
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            recover(ex, tokenSet_8_);
        }
        returnAST = expr_AST;
    }
Пример #25
0
    public void stmt()     //throws RecognitionException, TokenStreamException
    {
        returnAST = null;
        ASTPair currentAST = new ASTPair();
        AST     stmt_AST   = null;

        try {              // for error handling
            switch (LA(1))
            {
            case LITERAL_skip:
            {
                AST tmp16_AST = null;
                tmp16_AST = astFactory.create(LT(1));
                astFactory.addASTChild(ref currentAST, tmp16_AST);
                match(LITERAL_skip);
                match(SEMI);
                stmt_AST = currentAST.root;
                break;
            }

            case LITERAL_print:
            {
                AST tmp18_AST = null;
                tmp18_AST = astFactory.create(LT(1));
                astFactory.makeASTRoot(ref currentAST, tmp18_AST);
                match(LITERAL_print);
                match(LPAREN);
                {
                    expr();
                    astFactory.addASTChild(ref currentAST, returnAST);
                    {                        // ( ... )*
                        for (;;)
                        {
                            if ((LA(1) == COMMA))
                            {
                                match(COMMA);
                                expr();
                                astFactory.addASTChild(ref currentAST, returnAST);
                            }
                            else
                            {
                                goto _loop23_breakloop;
                            }
                        }
                        _loop23_breakloop :;
                    }                        // ( ... )*
                }
                match(RPAREN);
                match(SEMI);
                stmt_AST = currentAST.root;
                break;
            }

            case LITERAL_goto:
            {
                AST tmp23_AST = null;
                tmp23_AST = astFactory.create(LT(1));
                astFactory.makeASTRoot(ref currentAST, tmp23_AST);
                match(LITERAL_goto);
                AST tmp24_AST = null;
                tmp24_AST = astFactory.create(LT(1));
                astFactory.addASTChild(ref currentAST, tmp24_AST);
                match(ID);
                match(SEMI);
                stmt_AST = currentAST.root;
                break;
            }

            case LITERAL_return:
            {
                AST tmp26_AST = null;
                tmp26_AST = astFactory.create(LT(1));
                astFactory.makeASTRoot(ref currentAST, tmp26_AST);
                match(LITERAL_return);
                match(SEMI);
                stmt_AST = currentAST.root;
                break;
            }

            case LITERAL_if:
            {
                AST tmp28_AST = null;
                tmp28_AST = astFactory.create(LT(1));
                astFactory.makeASTRoot(ref currentAST, tmp28_AST);
                match(LITERAL_if);
                match(LPAREN);
                decider();
                astFactory.addASTChild(ref currentAST, returnAST);
                match(RPAREN);
                match(LITERAL_then);
                sseq();
                astFactory.addASTChild(ref currentAST, returnAST);
                match(LITERAL_else);
                sseq();
                astFactory.addASTChild(ref currentAST, returnAST);
                match(LITERAL_fi);
                stmt_AST = currentAST.root;
                break;
            }

            case LITERAL_while:
            {
                AST tmp34_AST = null;
                tmp34_AST = astFactory.create(LT(1));
                astFactory.makeASTRoot(ref currentAST, tmp34_AST);
                match(LITERAL_while);
                match(LPAREN);
                decider();
                astFactory.addASTChild(ref currentAST, returnAST);
                match(RPAREN);
                match(LITERAL_do);
                sseq();
                astFactory.addASTChild(ref currentAST, returnAST);
                match(LITERAL_od);
                stmt_AST = currentAST.root;
                break;
            }

            case LITERAL_assert:
            {
                AST tmp39_AST = null;
                tmp39_AST = astFactory.create(LT(1));
                astFactory.makeASTRoot(ref currentAST, tmp39_AST);
                match(LITERAL_assert);
                match(LPAREN);
                decider();
                astFactory.addASTChild(ref currentAST, returnAST);
                match(RPAREN);
                match(SEMI);
                stmt_AST = currentAST.root;
                break;
            }

            default:
                if ((LA(1) == ID) && (LA(2) == COMMA || LA(2) == ASSIGN))
                {
                    {
                        AST tmp43_AST = null;
                        tmp43_AST = astFactory.create(LT(1));
                        astFactory.addASTChild(ref currentAST, tmp43_AST);
                        match(ID);
                        {                            // ( ... )*
                            for (;;)
                            {
                                if ((LA(1) == COMMA))
                                {
                                    match(COMMA);
                                    AST tmp45_AST = null;
                                    tmp45_AST = astFactory.create(LT(1));
                                    astFactory.addASTChild(ref currentAST, tmp45_AST);
                                    match(ID);
                                }
                                else
                                {
                                    goto _loop26_breakloop;
                                }
                            }
                            _loop26_breakloop :;
                        }                            // ( ... )*
                    }
                    AST tmp46_AST = null;
                    tmp46_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp46_AST);
                    match(ASSIGN);
                    {
                        expr();
                        astFactory.addASTChild(ref currentAST, returnAST);
                        {                            // ( ... )*
                            for (;;)
                            {
                                if ((LA(1) == COMMA))
                                {
                                    match(COMMA);
                                    expr();
                                    astFactory.addASTChild(ref currentAST, returnAST);
                                }
                                else
                                {
                                    goto _loop29_breakloop;
                                }
                            }
                            _loop29_breakloop :;
                        }                            // ( ... )*
                    }
                    match(SEMI);
                    stmt_AST        = (AST)currentAST.root;
                    stmt_AST        = (AST)astFactory.make(astFactory.create(ASSIGNMENT, "ASSIGNMENT"), stmt_AST);
                    currentAST.root = stmt_AST;
                    if ((null != stmt_AST) && (null != stmt_AST.getFirstChild()))
                    {
                        currentAST.child = stmt_AST.getFirstChild();
                    }
                    else
                    {
                        currentAST.child = stmt_AST;
                    }
                    currentAST.advanceChildToEnd();
                    stmt_AST = currentAST.root;
                }
                else if ((LA(1) == ID) && (LA(2) == LPAREN))
                {
                    AST tmp49_AST = null;
                    tmp49_AST = astFactory.create(LT(1));
                    astFactory.makeASTRoot(ref currentAST, tmp49_AST);
                    match(ID);
                    match(LPAREN);
                    {
                        switch (LA(1))
                        {
                        case ID:
                        case LPAREN:
                        case EMARK:
                        case CONST:
                        {
                            expr();
                            astFactory.addASTChild(ref currentAST, returnAST);
                            {                                // ( ... )*
                                for (;;)
                                {
                                    if ((LA(1) == COMMA))
                                    {
                                        match(COMMA);
                                        expr();
                                        astFactory.addASTChild(ref currentAST, returnAST);
                                    }
                                    else
                                    {
                                        goto _loop32_breakloop;
                                    }
                                }
                                _loop32_breakloop :;
                            }                                // ( ... )*
                            break;
                        }

                        case RPAREN:
                        {
                            break;
                        }

                        default:
                        {
                            throw new NoViableAltException(LT(1), getFilename());
                        }
                        }
                    }
                    match(RPAREN);
                    match(SEMI);
                    stmt_AST        = (AST)currentAST.root;
                    stmt_AST        = (AST)astFactory.make(astFactory.create(PROCCALL, "PROCCALL"), stmt_AST);
                    currentAST.root = stmt_AST;
                    if ((null != stmt_AST) && (null != stmt_AST.getFirstChild()))
                    {
                        currentAST.child = stmt_AST.getFirstChild();
                    }
                    else
                    {
                        currentAST.child = stmt_AST;
                    }
                    currentAST.advanceChildToEnd();
                    stmt_AST = currentAST.root;
                }
                else
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                break;
            }
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            recover(ex, tokenSet_6_);
        }
        returnAST = stmt_AST;
    }
Пример #26
0
        //throws RecognitionException
        public object expr(AST _t)
        {
            object value=null;

            Antlr.StringTemplate.Language.StringTemplateAST expr_AST_in = (Antlr.StringTemplate.Language.StringTemplateAST)_t;

            object a=null, b=null, e=null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case PLUS:
            {
                AST __t3 = _t;
                Antlr.StringTemplate.Language.StringTemplateAST tmp1_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                match((AST)_t,PLUS);
                _t = _t.getFirstChild();
                a=expr(_t);
                _t = retTree_;
                b=expr(_t);
                _t = retTree_;
                value = chunk.Add(a,b);
                _t = __t3;
                _t = _t.getNextSibling();
                break;
            }
            case APPLY:
            case MULTI_APPLY:
            {
                value=templateApplication(_t);
                _t = retTree_;
                break;
            }
            case ID:
            case DOT:
            case ANONYMOUS_TEMPLATE:
            case STRING:
            case INT:
            {
                value=attribute(_t);
                _t = retTree_;
                break;
            }
            case INCLUDE:
            {
                value=templateInclude(_t);
                _t = retTree_;
                break;
            }
            case FUNCTION:
            {
                value=function(_t);
                _t = retTree_;
                break;
            }
            case LIST:
            {
                value=list(_t);
                _t = retTree_;
                break;
            }
            case VALUE:
            {
                AST __t4 = _t;
                Antlr.StringTemplate.Language.StringTemplateAST tmp2_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                match((AST)_t,VALUE);
                _t = _t.getFirstChild();
                e=expr(_t);
                _t = retTree_;
                _t = __t4;
                _t = _t.getNextSibling();

                            StringWriter buf = new StringWriter();
                            IStringTemplateWriter sw = self.Group.CreateInstanceOfTemplateWriter(buf);
                            int n = chunk.WriteAttribute(self,e,sw);
                            if (n > 0)
                            {
                                value = buf.ToString();

                            }

                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #27
0
    public void proc()     //throws RecognitionException, TokenStreamException
    {
        returnAST = null;
        ASTPair currentAST = new ASTPair();
        AST     proc_AST   = null;

        try {              // for error handling
            AST tmp6_AST = null;
            tmp6_AST = astFactory.create(LT(1));
            astFactory.makeASTRoot(ref currentAST, tmp6_AST);
            match(ID);
            match(LPAREN);
            {
                switch (LA(1))
                {
                case ID:
                {
                    AST tmp8_AST = null;
                    tmp8_AST = astFactory.create(LT(1));
                    astFactory.addASTChild(ref currentAST, tmp8_AST);
                    match(ID);
                    {                        // ( ... )*
                        for (;;)
                        {
                            if ((LA(1) == COMMA))
                            {
                                match(COMMA);
                                AST tmp10_AST = null;
                                tmp10_AST = astFactory.create(LT(1));
                                astFactory.addASTChild(ref currentAST, tmp10_AST);
                                match(ID);
                            }
                            else
                            {
                                goto _loop13_breakloop;
                            }
                        }
                        _loop13_breakloop :;
                    }                        // ( ... )*
                    break;
                }

                case RPAREN:
                {
                    break;
                }

                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                }
            }
            match(RPAREN);
            match(LITERAL_begin);
            {                // ( ... )*
                for (;;)
                {
                    if ((LA(1) == LITERAL_decl))
                    {
                        decl();
                        astFactory.addASTChild(ref currentAST, returnAST);
                    }
                    else
                    {
                        goto _loop15_breakloop;
                    }
                }
                _loop15_breakloop :;
            }                // ( ... )*
            sseq();
            astFactory.addASTChild(ref currentAST, returnAST);
            match(LITERAL_end);
            proc_AST        = (AST)currentAST.root;
            proc_AST        = (AST)astFactory.make(astFactory.create(PROC, "PROC"), proc_AST);
            currentAST.root = proc_AST;
            if ((null != proc_AST) && (null != proc_AST.getFirstChild()))
            {
                currentAST.child = proc_AST.getFirstChild();
            }
            else
            {
                currentAST.child = proc_AST;
            }
            currentAST.advanceChildToEnd();
            proc_AST = currentAST.root;
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            recover(ex, tokenSet_2_);
        }
        returnAST = proc_AST;
    }
Пример #28
0
        //throws RecognitionException
        public object function(AST _t)
        {
            object value=null;

            Antlr.StringTemplate.Language.StringTemplateAST function_AST_in = (Antlr.StringTemplate.Language.StringTemplateAST)_t;

            object a;

            try {      // for error handling
            AST __t21 = _t;
            Antlr.StringTemplate.Language.StringTemplateAST tmp10_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
            match((AST)_t,FUNCTION);
            _t = _t.getFirstChild();
            {
                if (null == _t)
                    _t = ASTNULL;
                switch ( _t.Type )
                {
                case LITERAL_first:
                {
                    Antlr.StringTemplate.Language.StringTemplateAST tmp11_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_first);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.First(a);
                    break;
                }
                case LITERAL_rest:
                {
                    Antlr.StringTemplate.Language.StringTemplateAST tmp12_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_rest);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.Rest(a);
                    break;
                }
                case LITERAL_last:
                {
                    Antlr.StringTemplate.Language.StringTemplateAST tmp13_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_last);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.Last(a);
                    break;
                }
                case LITERAL_length:
                {
                    Antlr.StringTemplate.Language.StringTemplateAST tmp14_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_length);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.Length(a);
                    break;
                }
                case LITERAL_strip:
                {
                    Antlr.StringTemplate.Language.StringTemplateAST tmp15_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_strip);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.Strip(a);
                    break;
                }
                case LITERAL_trunc:
                {
                    Antlr.StringTemplate.Language.StringTemplateAST tmp16_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,LITERAL_trunc);
                    _t = _t.getNextSibling();
                    a=singleFunctionArg(_t);
                    _t = retTree_;
                    value=chunk.Trunc(a);
                    break;
                }
                default:
                {
                    throw new NoViableAltException(_t);
                }
                 }
            }
            _t = __t21;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #29
0
        //throws RecognitionException
        public Object attribute(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST attribute_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST prop = null;
            antlr.stringtemplate.language.StringTemplateAST i3 = null;
            antlr.stringtemplate.language.StringTemplateAST i = null;
            antlr.stringtemplate.language.StringTemplateAST s = null;

            Object obj = null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case DOT:
            {
                AST __t21 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp4_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,DOT);
                _t = _t.getFirstChild();
                obj=attribute(_t);
                _t = retTree_;
                prop = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ID);
                _t = _t.getNextSibling();
                _t = __t21;
                _t = _t.getNextSibling();
                value = chunk.getObjectProperty(self,obj,prop.getText());
                break;
            }
            case ID:
            {
                i3 = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ID);
                _t = _t.getNextSibling();

                try {
                value=self.getAttribute(i3.getText());
                }
                catch (ArgumentOutOfRangeException nse) {
                // rethrow with more precise error message
                throw new ArgumentOutOfRangeException(nse.ParamName, String.Format(
                    "no such attribute: {0} in template {1}", i3.getText(), self.getName()));
                }

                break;
            }
            case INT:
            {
                i = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,INT);
                _t = _t.getNextSibling();
                value=Int32.Parse(i.getText());
                break;
            }
            case STRING:
            {
                s = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,STRING);
                _t = _t.getNextSibling();
                value=s.getText();
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #30
0
        //throws RecognitionException
        public void singleTemplateArg(AST _t,
            StringTemplate embedded, IDictionary argumentContext
            )
        {
            Antlr.StringTemplate.Language.StringTemplateAST singleTemplateArg_AST_in = (Antlr.StringTemplate.Language.StringTemplateAST)_t;

            object e = null;

            try {      // for error handling
            AST __t40 = _t;
            Antlr.StringTemplate.Language.StringTemplateAST tmp25_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
            match((AST)_t,SINGLEVALUEARG);
            _t = _t.getFirstChild();
            e=expr(_t);
            _t = retTree_;
            _t = __t40;
            _t = _t.getNextSibling();

                    if ( e!=null ) {
                        string soleArgName = null;
                        // find the sole defined formal argument for embedded
                        bool error = false;
                        HashList formalArgs = (HashList) embedded.FormalArguments;
                        if ( formalArgs!=null ) {
                            ICollection argNames = formalArgs.Keys;
                            if ( argNames.Count==1 ) {
                                IEnumerator iter = argNames.GetEnumerator();
                                iter.MoveNext();
                                soleArgName = (string) iter.Current;
                                //Console.WriteLine("sole formal arg of "+embedded.Name+" is "+soleArgName);
                            }
                            else {
                                error=true;
                            }
                        }
                        else {
                            error=true;
                        }
                        if ( error ) {
                            self.Error("template "+embedded.Name+
                                       " must have exactly one formal arg in template context "+
                                       self.GetEnclosingInstanceStackString());
                       	}
                       	else {
                       		self.RawSetArgumentAttribute(embedded,argumentContext,soleArgName,e);
                       	}
                    }

            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
        }
Пример #31
0
		/*Is 't' a subtree of the tree rooted at 'this'?  The siblings
		*  of 'this' are ignored.
		*/
		public virtual bool EqualsTreePartial(AST sub)
		{
			// the empty tree is always a subset of any tree.
			if (sub == null)
			{
				return true;
			}
			
			// check roots first.
			if (!this.Equals(sub))
				return false;
			// if roots match, do full list partial match test on children.
			if (this.getFirstChild() != null)
			{
				if (!this.getFirstChild().EqualsListPartial(sub.getFirstChild()))
					return false;
			}
			return true;
		}
Пример #32
0
        //throws RecognitionException
        public Object templateInclude(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST templateInclude_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST id = null;
            antlr.stringtemplate.language.StringTemplateAST a1 = null;
            antlr.stringtemplate.language.StringTemplateAST a2 = null;

            StringTemplateAST args = null;
            String name = null;
            Object n = null;

            try {      // for error handling
            AST __t10 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp8_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,INCLUDE);
            _t = _t.getFirstChild();
            {
                if (null == _t)
                    _t = ASTNULL;
                switch ( _t.Type )
                {
                case ID:
                {
                    id = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,ID);
                    _t = _t.getNextSibling();
                    a1 = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    if (null == _t) throw new MismatchedTokenException();
                    _t = _t.getNextSibling();
                    name=id.getText(); args=a1;
                    break;
                }
                case VALUE:
                {
                    AST __t12 = _t;
                    antlr.stringtemplate.language.StringTemplateAST tmp9_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,VALUE);
                    _t = _t.getFirstChild();
                    n=expr(_t);
                    _t = retTree_;
                    a2 = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    if (null == _t) throw new MismatchedTokenException();
                    _t = _t.getNextSibling();
                    _t = __t12;
                    _t = _t.getNextSibling();
                    if (n!=null) {name=n.ToString();} args=a2;
                    break;
                }
                default:
                {
                    throw new NoViableAltException(_t);
                }
                 }
            }
            _t = __t10;
            _t = _t.getNextSibling();

            if ( name!=null ) {
                value = chunk.getTemplateInclude(self, name, args);
            }

            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #33
0
        //throws RecognitionException
        public void argumentAssignment(AST _t,
		IDictionary argumentContext
	)
        {
            antlr.stringtemplate.language.StringTemplateAST argumentAssignment_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST arg = null;

            Object e = null;

            try {      // for error handling
            AST __t27 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp11_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,ASSIGN);
            _t = _t.getFirstChild();
            arg = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,ID);
            _t = _t.getNextSibling();
            e=expr(_t);
            _t = retTree_;

                       if ( e!=null )
                           self.rawSetAttribute(argumentContext,arg.getText(),e);

            _t = __t27;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
        }
Пример #34
0
        //throws RecognitionException
        public void argumentAssignment(AST _t,
		StringTemplate embedded, IDictionary argumentContext
	)
        {
            antlr.stringtemplate.language.StringTemplateAST argumentAssignment_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST arg = null;

            Object e = null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case ASSIGN:
            {
                AST __t43 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp20_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ASSIGN);
                _t = _t.getFirstChild();
                arg = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,ID);
                _t = _t.getNextSibling();
                e=expr(_t);
                _t = retTree_;
                _t = __t43;
                _t = _t.getNextSibling();

                        if ( e!=null ) {
                            self.rawSetArgumentAttribute(embedded,argumentContext,arg.getText(),e);
                        }

                break;
            }
            case DOTDOTDOT:
            {
                antlr.stringtemplate.language.StringTemplateAST tmp21_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,DOTDOTDOT);
                _t = _t.getNextSibling();
                embedded.setPassThroughAttributes(true);
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
        }
Пример #35
0
		/*Is tree rooted at 'this' equal to 't'?  The siblings
		*  of 'this' are ignored.
		*/
		public virtual bool EqualsTree(AST t)
		{
			// check roots first.
			if (!this.Equals(t))
				return false;
			// if roots match, do full list match test on children.
			if (this.getFirstChild() != null)
			{
				if (!this.getFirstChild().EqualsList(t.getFirstChild()))
					return false;
			}
			else if (t.getFirstChild() != null)
			{
				return false;
			}
			return true;
		}
Пример #36
0
        //throws RecognitionException
        public Object expr(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST expr_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            Object a=null, b=null, e=null;
            IDictionary argumentContext=null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case PLUS:
            {
                AST __t3 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp1_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,PLUS);
                _t = _t.getFirstChild();
                a=expr(_t);
                _t = retTree_;
                b=expr(_t);
                _t = retTree_;
                value = chunk.add(a,b);
                _t = __t3;
                _t = _t.getNextSibling();
                break;
            }
            case APPLY:
            case MULTI_APPLY:
            {
                value=templateApplication(_t);
                _t = retTree_;
                break;
            }
            case DOT:
            case ID:
            case ANONYMOUS_TEMPLATE:
            case STRING:
            case INT:
            {
                value=attribute(_t);
                _t = retTree_;
                break;
            }
            case INCLUDE:
            {
                value=templateInclude(_t);
                _t = retTree_;
                break;
            }
            case FUNCTION:
            {
                value=function(_t);
                _t = retTree_;
                break;
            }
            case LIST:
            {
                value=list(_t);
                _t = retTree_;
                break;
            }
            case VALUE:
            {
                AST __t4 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp2_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,VALUE);
                _t = _t.getFirstChild();
                e=expr(_t);
                _t = retTree_;
                _t = __t4;
                _t = _t.getNextSibling();

                StringWriter buf = new StringWriter();
                Type writerClass = @out.GetType();
                StringTemplateWriter sw = null;
                try {
                ConstructorInfo ctor =
                    writerClass.GetConstructor(new Type[] {typeof(TextWriter)});
                sw = (StringTemplateWriter)ctor.Invoke(new Object[] {buf});
                }
                catch (Exception exc) {
                    // default new AutoIndentWriter(buf)
                    self.error("cannot make implementation of StringTemplateWriter",exc);
                    sw = new AutoIndentWriter(buf);
                    }
                chunk.writeAttribute(self,e,sw);
                value = buf.ToString();

                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #37
0
		/*Is 'sub' a subtree of this list?
		*  The siblings of the root are NOT ignored.
		*/
		public virtual bool EqualsListPartial(AST sub)
		{
			AST sibling;
			
			// the empty tree is always a subset of any tree.
			if (sub == null)
			{
				return true;
			}
			
			// Otherwise, start walking sibling lists.  First mismatch, return false.
			 for (sibling = this; sibling != null && sub != null; sibling = sibling.getNextSibling(), sub = sub.getNextSibling())
			{
				// as a quick optimization, check roots first.
				if (!sibling.Equals(sub))
					return false;
				// if roots match, do partial list match test on children.
				if (sibling.getFirstChild() != null)
				{
					if (!sibling.getFirstChild().EqualsListPartial(sub.getFirstChild()))
						return false;
				}
			}
			if (sibling == null && sub != null)
			{
				// nothing left to match in this tree, but subtree has more
				return false;
			}
			// either both are null or sibling has more, but subtree doesn't
			return true;
		}
Пример #38
0
        //throws RecognitionException
        public bool ifCondition(AST _t)
        {
            bool value=false;

            antlr.stringtemplate.language.StringTemplateAST ifCondition_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            Object a=null, b=null;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case APPLY:
            case MULTI_APPLY:
            case INCLUDE:
            case VALUE:
            case FUNCTION:
            case LIST:
            case PLUS:
            case DOT:
            case ID:
            case ANONYMOUS_TEMPLATE:
            case STRING:
            case INT:
            {
                a=ifAtom(_t);
                _t = retTree_;
                value = chunk.testAttributeTrue(a);
                break;
            }
            case NOT:
            {
                AST __t30 = _t;
                antlr.stringtemplate.language.StringTemplateAST tmp18_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                match((AST)_t,NOT);
                _t = _t.getFirstChild();
                a=ifAtom(_t);
                _t = retTree_;
                _t = __t30;
                _t = _t.getNextSibling();
                value = !chunk.testAttributeTrue(a);
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #39
0
		/*Is t an exact structural and equals() match of this tree.  The
		*  'this' reference is considered the start of a sibling list.
		*/
		public virtual bool EqualsList(AST t)
		{
			AST sibling;
			
			// the empty tree is not a match of any non-null tree.
			if (t == null)
			{
				return false;
			}
			
			// Otherwise, start walking sibling lists.  First mismatch, return false.
			 for (sibling = this; sibling != null && t != null; sibling = sibling.getNextSibling(), t = t.getNextSibling())
			{
				// as a quick optimization, check roots first.
				if (!sibling.Equals(t))
				{
					return false;
				}
				// if roots match, do full list match test on children.
				if (sibling.getFirstChild() != null)
				{
					if (!sibling.getFirstChild().EqualsList(t.getFirstChild()))
					{
						return false;
					}
				}
				else if (t.getFirstChild() != null)
				{
					return false;
				}
			}
			if (sibling == null && t == null)
			{
				return true;
			}
			// one sibling list has more than the other
			return false;
		}
Пример #40
0
        //throws RecognitionException
        public Object singleFunctionArg(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST singleFunctionArg_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            try {      // for error handling
            AST __t24 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp17_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,SINGLEVALUEARG);
            _t = _t.getFirstChild();
            value=expr(_t);
            _t = retTree_;
            _t = __t24;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #41
0
        //throws RecognitionException
        public bool expression(AST _t)
        {
            bool e ;

            AST expression_AST_in = (AST)_t;

            bool a, b;
            object l, r;

            e = false;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case AND:
            {
                AST __t44 = _t;
                AST tmp21_AST_in = _t;
                match(_t,AND);
                _t = _t.getFirstChild();
                a=expression(_t);
                _t = retTree_;
                b=expression(_t);
                _t = retTree_;
                e = a && b;
                _t = __t44;
                _t = _t.getNextSibling();
                break;
            }
            case OR:
            {
                AST __t45 = _t;
                AST tmp22_AST_in = _t;
                match(_t,OR);
                _t = _t.getFirstChild();
                a=expression(_t);
                _t = retTree_;
                b=expression(_t);
                _t = retTree_;
                e = a || b;
                _t = __t45;
                _t = _t.getNextSibling();
                break;
            }
            case EQUAL:
            {
                AST __t46 = _t;
                AST tmp23_AST_in = _t;
                match(_t,EQUAL);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = ((l as IComparable).CompareTo(r) == 0);

                _t = __t46;
                _t = _t.getNextSibling();
                break;
            }
            case NOT_EQUAL:
            {
                AST __t47 = _t;
                AST tmp24_AST_in = _t;
                match(_t,NOT_EQUAL);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = ((l as IComparable).CompareTo(r) != 0);

                _t = __t47;
                _t = _t.getNextSibling();
                break;
            }
            case LESSTHAN:
            {
                AST __t48 = _t;
                AST tmp25_AST_in = _t;
                match(_t,LESSTHAN);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = ((l as IComparable).CompareTo(r) < 0);

                _t = __t48;
                _t = _t.getNextSibling();
                break;
            }
            case LESSEQUAL:
            {
                AST __t49 = _t;
                AST tmp26_AST_in = _t;
                match(_t,LESSEQUAL);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = ((l as IComparable).CompareTo(r) <= 0);

                _t = __t49;
                _t = _t.getNextSibling();
                break;
            }
            case GE:
            {
                AST __t50 = _t;
                AST tmp27_AST_in = _t;
                match(_t,GE);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = ((l as IComparable).CompareTo(r) >= 0);

                _t = __t50;
                _t = _t.getNextSibling();
                break;
            }
            case GT:
            {
                AST __t51 = _t;
                AST tmp28_AST_in = _t;
                match(_t,GT);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = ((l as IComparable).CompareTo(r) > 0);

                _t = __t51;
                _t = _t.getNextSibling();
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return e ;
        }
Пример #42
0
        //throws RecognitionException
        public void template(AST _t,
		ArrayList templatesToApply
	)
        {
            antlr.stringtemplate.language.StringTemplateAST template_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;
            antlr.stringtemplate.language.StringTemplateAST t = null;
            antlr.stringtemplate.language.StringTemplateAST args = null;
            antlr.stringtemplate.language.StringTemplateAST anon = null;
            antlr.stringtemplate.language.StringTemplateAST args2 = null;

            IDictionary argumentContext = null;
            Object n = null;

            try {      // for error handling
            AST __t26 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp15_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,TEMPLATE);
            _t = _t.getFirstChild();
            {
                if (null == _t)
                    _t = ASTNULL;
                switch ( _t.Type )
                {
                case ID:
                {
                    t = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,ID);
                    _t = _t.getNextSibling();
                    args = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    if (null == _t) throw new MismatchedTokenException();
                    _t = _t.getNextSibling();

                    String templateName = t.getText();
                    StringTemplateGroup group = self.getGroup();
                    StringTemplate embedded = group.getEmbeddedInstanceOf(self, templateName);
                    if ( embedded!=null ) {
                    embedded.setArgumentsAST(args);
                    templatesToApply.Add(embedded);
                    }

                    break;
                }
                case ANONYMOUS_TEMPLATE:
                {
                    anon = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,ANONYMOUS_TEMPLATE);
                    _t = _t.getNextSibling();

                    StringTemplate anonymous = anon.getStringTemplate();
                    templatesToApply.Add(anonymous);

                    break;
                }
                case VALUE:
                {
                    AST __t28 = _t;
                    antlr.stringtemplate.language.StringTemplateAST tmp16_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    match((AST)_t,VALUE);
                    _t = _t.getFirstChild();
                    n=expr(_t);
                    _t = retTree_;
                    args2 = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
                    if (null == _t) throw new MismatchedTokenException();
                    _t = _t.getNextSibling();

                                            StringTemplate embedded = null;
                                            if ( n!=null )
                                            {
                                String templateName = n.ToString();
                                                StringTemplateGroup group = self.getGroup();
                                                embedded = group.getEmbeddedInstanceOf(self, templateName);
                                                if ( embedded!=null )
                                                {
                                                    embedded.setArgumentsAST(args2);
                                                    templatesToApply.Add(embedded);
                                                }
                                            }

                    _t = __t28;
                    _t = _t.getNextSibling();
                    break;
                }
                default:
                {
                    throw new NoViableAltException(_t);
                }
                 }
            }
            _t = __t26;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
        }
Пример #43
0
        //throws RecognitionException
        /** Apply template(s) to an attribute; can be applied to another apply
         *  result.
         */
        public Object templateApplication(AST _t)
        {
            Object value=null;

            antlr.stringtemplate.language.StringTemplateAST templateApplication_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            Object a=null;
            ArrayList templatesToApply=new ArrayList();

            try {      // for error handling
            AST __t10 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp3_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,APPLY);
            _t = _t.getFirstChild();
            a=expr(_t);
            _t = retTree_;
            { // ( ... )+
                int _cnt12=0;
                for (;;)
                {
                    if (_t == null)
                        _t = ASTNULL;
                    if ((_t.Type==TEMPLATE))
                    {
                        template(_t,templatesToApply);
                        _t = retTree_;
                    }
                    else
                    {
                        if (_cnt12 >= 1) { goto _loop12_breakloop; } else { throw new NoViableAltException(_t);; }
                    }

                    _cnt12++;
                }
            _loop12_breakloop:				;
            }    // ( ... )+
            value = chunk.applyListOfAlternatingTemplates(self,a,templatesToApply);
            _t = __t10;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return value;
        }
Пример #44
0
        //throws RecognitionException
        public boolean expression(AST _t)
        {
            boolean e ;

            AST expression_AST_in = (AST)_t;

            boolean a, b;
            String l, r;

            e = false;

            try {      // for error handling
            if (null == _t)
                _t = ASTNULL;
            switch ( _t.Type )
            {
            case AND:
            {
                AST __t43 = _t;
                AST tmp21_AST_in = _t;
                match(_t,AND);
                _t = _t.getFirstChild();
                a=expression(_t);
                _t = retTree_;
                b=expression(_t);
                _t = retTree_;
                e = a && b;
                _t = __t43;
                _t = _t.getNextSibling();
                break;
            }
            case OR:
            {
                AST __t44 = _t;
                AST tmp22_AST_in = _t;
                match(_t,OR);
                _t = _t.getFirstChild();
                a=expression(_t);
                _t = retTree_;
                b=expression(_t);
                _t = retTree_;
                e = a || b;
                _t = __t44;
                _t = _t.getNextSibling();
                break;
            }
            case EQUAL:
            {
                AST __t45 = _t;
                AST tmp23_AST_in = _t;
                match(_t,EQUAL);
                _t = _t.getFirstChild();
                l=value(_t);
                _t = retTree_;
                r=value(_t);
                _t = retTree_;

                e = l.equals(r);

                _t = __t45;
                _t = _t.getNextSibling();
                break;
            }
            default:
            {
                throw new NoViableAltException(_t);
            }
             }
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return e ;
        }
Пример #45
0
    /** Is t an exact structural match of this tree with the same node
     *  types?  'self' is considered the start of a sibling list.
     */
    protected bool equalsNodeTypesList(AST self, AST t)
    {
        // Console.Out.WriteLine("self="+self+", t="+t);
        // Console.Out.WriteLine("self.class="+self.getClass()+", t.class="+t.getClass());
        AST sibling;

        // the empty tree is not a match of any non-null tree.
        if (t == null) {
            return false;
        }

        // Otherwise, start walking sibling lists.  First mismatch, return false.
        for (sibling = self;
             sibling != null && t != null;
             sibling = sibling.getNextSibling(), t = t.getNextSibling())
        {
            // Console.Out.WriteLine("sibling="+sibling+", t="+t);
            // as a quick optimization, check root types first.
            if ( sibling.GetType()!=t.GetType() ) {
                return false;
            }
            // if roots match, do full list match test on children.
            if (sibling.getFirstChild() != null) {
                if (!equalsNodeTypesList(sibling.getFirstChild(),
                                         t.getFirstChild()))
                {
                    return false;
                }
            }
            // sibling has no kids, make sure t doesn't either
            else if (t.getFirstChild() != null) {
                return false;
            }
        }
        if (sibling == null && t == null) {
            return true;
        }
        // one sibling list has more than the other
        return false;
    }
Пример #46
0
        //throws RecognitionException
        public IDictionary argList(AST _t,
		IDictionary initialContext
	)
        {
            IDictionary argumentContext=null;

            antlr.stringtemplate.language.StringTemplateAST argList_AST_in = (antlr.stringtemplate.language.StringTemplateAST)_t;

            argumentContext = initialContext;
            if ( argumentContext==null ) {
            argumentContext=new Hashtable();
            }

            try {      // for error handling
            AST __t23 = _t;
            antlr.stringtemplate.language.StringTemplateAST tmp9_AST_in = (_t==ASTNULL) ? null : (antlr.stringtemplate.language.StringTemplateAST)_t;
            match((AST)_t,ARGS);
            _t = _t.getFirstChild();
            {    // ( ... )*
                for (;;)
                {
                    if (_t == null)
                        _t = ASTNULL;
                    if ((_t.Type==ASSIGN))
                    {
                        argumentAssignment(_t,argumentContext);
                        _t = retTree_;
                    }
                    else
                    {
                        goto _loop25_breakloop;
                    }

                }
            _loop25_breakloop:				;
            }    // ( ... )*
            _t = __t23;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
            return argumentContext;
        }
Пример #47
0
        //throws RecognitionException
        public void template(AST _t,
            ArrayList templatesToApply
            )
        {
            Antlr.StringTemplate.Language.StringTemplateAST template_AST_in = (Antlr.StringTemplate.Language.StringTemplateAST)_t;
            Antlr.StringTemplate.Language.StringTemplateAST t = null;
            Antlr.StringTemplate.Language.StringTemplateAST args = null;
            Antlr.StringTemplate.Language.StringTemplateAST anon = null;
            Antlr.StringTemplate.Language.StringTemplateAST args2 = null;

            object n = null;

            try {      // for error handling
            AST __t26 = _t;
            Antlr.StringTemplate.Language.StringTemplateAST tmp18_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
            match((AST)_t,TEMPLATE);
            _t = _t.getFirstChild();
            {
                if (null == _t)
                    _t = ASTNULL;
                switch ( _t.Type )
                {
                case ID:
                {
                    t = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,ID);
                    _t = _t.getNextSibling();
                    args = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    if (null == _t) throw new MismatchedTokenException();
                    _t = _t.getNextSibling();

                    string templateName = t.getText();
                    StringTemplateGroup group = self.Group;
                    StringTemplate embedded = group.GetEmbeddedInstanceOf(self, templateName);
                    if ( embedded!=null ) {
                    embedded.ArgumentsAST = args;
                    templatesToApply.Add(embedded);
                    }

                    break;
                }
                case ANONYMOUS_TEMPLATE:
                {
                    anon = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,ANONYMOUS_TEMPLATE);
                    _t = _t.getNextSibling();

                    StringTemplate anonymous = anon.StringTemplate;
                    // to properly see overridden templates, always set
                    // anonymous' group to be self's group
                                    anonymous.Group = self.Group;
                    templatesToApply.Add(anonymous);

                    break;
                }
                case VALUE:
                {
                    AST __t28 = _t;
                    Antlr.StringTemplate.Language.StringTemplateAST tmp19_AST_in = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    match((AST)_t,VALUE);
                    _t = _t.getFirstChild();
                    n=expr(_t);
                    _t = retTree_;
                    args2 = (_t==ASTNULL) ? null : (Antlr.StringTemplate.Language.StringTemplateAST)_t;
                    if (null == _t) throw new MismatchedTokenException();
                    _t = _t.getNextSibling();

                                            StringTemplate embedded = null;
                                            if ( n!=null ) {
                                String templateName = n.ToString();
                                                StringTemplateGroup group = self.Group;
                                                embedded = group.GetEmbeddedInstanceOf(self, templateName);
                                                if ( embedded!=null ) {
                                                    embedded.ArgumentsAST = args2;
                                                    templatesToApply.Add(embedded);
                                                }
                                            }

                    _t = __t28;
                    _t = _t.getNextSibling();
                    break;
                }
                default:
                {
                    throw new NoViableAltException(_t);
                }
                 }
            }
            _t = __t26;
            _t = _t.getNextSibling();
            }
            catch (RecognitionException ex)
            {
            reportError(ex);
            if (null != _t)
            {
                _t = _t.getNextSibling();
            }
            }
            retTree_ = _t;
        }