/// <summary>To write out the value of a condition expr, invoke the evaluator in eval.g
 /// to walk the condition tree computing the boolean value.  If result
 /// is true, then write subtemplate.
 /// </summary>
 public override int write(StringTemplate self, StringTemplateWriter outWriter)
 {
     if (exprTree == null || self == null || outWriter == null)
     {
         return 0;
     }
     // System.out.println("evaluating conditional tree: "+exprTree.toStringList());
     ActionEvaluator eval = new ActionEvaluator(self, this, outWriter);
     int n = 0;
     try
     {
         // get conditional from tree and compute result
         AST cond = exprTree.getFirstChild();
         bool includeSubtemplate = eval.ifCondition(cond); // eval and write out tree
         // System.out.println("subtemplate "+subtemplate);
         if (includeSubtemplate)
         {
             /* To evaluate the IF chunk, make a new instance whose enclosingInstance
             * points at 'self' so get attribute works.  Otherwise, enclosingInstance
             * points at the template used to make the precompiled code.  We need a
             * new template instance every time we exec this chunk to get the new
             * "enclosing instance" pointer.
             */
             StringTemplate s = subtemplate.getInstanceOf();
             s.setEnclosingInstance(self);
             n = s.write(outWriter);
         }
         else if (elseSubtemplate != null)
         {
             // evaluate ELSE clause if present and IF condition failed
             StringTemplate s = elseSubtemplate.getInstanceOf();
             s.setEnclosingInstance(self);
             n = s.write(outWriter);
         }
     }
     catch (RecognitionException re)
     {
         self.error("can't evaluate tree: " + exprTree.ToStringList(), re);
     }
     return n;
 }
Esempio n. 2
0
 /// <summary>How to write this node to output; return how many char written </summary>
 public abstract int write(StringTemplate self, StringTemplateWriter outWriter);