Пример #1
0
        /** <summary>
         *  Evaluate an argument list within the context of the enclosing
         *  template but store the values in the context of self, the
         *  new embedded template.  For example, bold(item=item) means
         *  that bold.item should get the value of enclosing.item.
         *  </summary>
         */
        protected virtual void EvaluateArguments( StringTemplate self )
        {
            StringTemplateAST argumentsAST = self.ArgumentsAST;
            if ( argumentsAST == null || argumentsAST.GetChild( 0 ) == null )
            {
                // return immediately if missing tree or no actual args
                return;
            }

            // Evaluate args in the context of the enclosing template, but we
            // need the predefined args like 'it', 'attr', and 'i' to be
            // available as well so we put a dummy ST between the enclosing
            // context and the embedded context.  The dummy has the predefined
            // context as does the embedded.
            StringTemplate enclosing = self.EnclosingInstance;
            StringTemplate argContextST = new StringTemplate( self.Group, "" );
            argContextST.Name = "<invoke " + self.Name + " arg context>";
            argContextST.EnclosingInstance = enclosing;
            argContextST.ArgumentContext = self.ArgumentContext;

            ActionEvaluator eval =
                    new ActionEvaluator( argContextST, this, null, argumentsAST );
            /*
            System.out.println("eval args: "+argumentsAST.toStringList());
            System.out.println("ctx is "+self.getArgumentContext());
            */
            try
            {
                // using any initial argument context (such as when obj is set),
                // evaluate the arg list like bold(item=obj).  Since we pass
                // in any existing arg context, that context gets filled with
                // new values.  With bold(item=obj), context becomes:
                // {[obj=...],[item=...]}.
                Dictionary<string, object> ac = eval.argList( self, self.ArgumentContext );
                self.ArgumentContext = ac;
            }
            catch ( RecognitionException re )
            {
                self.Error( "can't evaluate tree: " + argumentsAST.ToStringTree(), re );
            }
        }