public void VisitEnter(EachBlock astNode)
 {
     state.SetCursor(astNode);
     //Check if we are already in a compiletime loop.
     if (astNode.Type != EachBlock.LoopType.CompileTime)
     {//Not in compiletime loop. procede as usual
         Context loopedVariable;
         if (astNode.Member.TryEvaluate(state, out loopedVariable))
         {
             state.PromiseTruthyCheck(loopedVariable);
             state.PushNewBlock();
             Context loopContext = astNode.Member.EvaluateLoop(state);
             if (loopContext != null)
             {//The loopVariable implements IEnumerable -> runtimeloop over its contents
                 astNode.Type = EachBlock.LoopType.RunTime;
                 state.ContextStack.Push(astNode.Member.EvaluateLoop(state));
                 state.LoopLevel++;
                 if (astNode.Flags.HasFlag(EachBlock.ForLoopFlags.Last))
                 {
                     state.SetLastVariable(loopedVariable.FullPath);
                 }
             }
             else
             {//The loopVariable is an object. Compiletimeloop over its Members
                 astNode.Type = EachBlock.LoopType.CompileTime;
                 //Push the CompileTimeLoopContext
                 var ctLoopContext = new CompileTimeLoopContext(loopedVariable.FullPath, loopedVariable.Symbol);
                 ctLoopContext.MoveNext();
                 state.ContextStack.Push(ctLoopContext);
             }
         }
     }
 }
Example #2
0
        public HtmlEngine(ViewCollection views)
        {
            this.views = views;

            RemoveComments           = true;
            VariableNotFoundBehavior = VariableNotFoundBehavior.Source;

            conditionalBlock = new ConditionalBlock(this);
            eachBlock        = new EachBlock(this);
        }
 public void VisitLeave(EachBlock astNode)
 {
     state.SetCursor(astNode);
     if (astNode.Type == EachBlock.LoopType.RunTime)
     {
         if (astNode.Flags.HasFlag(EachBlock.ForLoopFlags.Index) || astNode.Flags.HasFlag(EachBlock.ForLoopFlags.Last))
         {
             state.IncrementIndexVariable();
         }
         if (astNode.Flags.HasFlag(EachBlock.ForLoopFlags.First))
         {
             state.SetFirstVariable();
         }
         //Leave loop context
         state.ContextStack.Pop();
         state.LoopLevel--;
         var     prepareLoopStatements = SyntaxHelper.PrepareForLoop(astNode.Flags, state.LoopLevel + 1);
         Context context;
         if (astNode.Member.TryEvaluate(state, out context))
         {
             prepareLoopStatements.Add(SyntaxHelper.ForLoop(astNode.Member.EvaluateLoop(state).FullPath, context.FullPath, state.PopBlock()));
         }
         state.DoTruthyCheck(
             prepareLoopStatements
             );
     }
     else if (astNode.Type == EachBlock.LoopType.CompileTime)
     {
         //Check if loop is completed
         var ctLoopContext = state.ContextStack.Peek() as CompileTimeLoopContext;
         if (ctLoopContext.MoveNext())
         {//Next Iteration
             astNode.Accept(this);
         }
         else
         {//Pop ctLoopContext
             state.ContextStack.Pop();
             state.DoTruthyCheck(state.PopBlock());
         }
     }
 }
 public void VisitLeave(EachBlock astNode)
 {
     state.SetCursor(astNode);
       if (astNode.Type==EachBlock.LoopType.RunTime)
       {
     if (astNode.Flags.HasFlag(EachBlock.ForLoopFlags.Index) || astNode.Flags.HasFlag(EachBlock.ForLoopFlags.Last))
       state.IncrementIndexVariable();
     if (astNode.Flags.HasFlag(EachBlock.ForLoopFlags.First))
       state.SetFirstVariable();
     //Leave loop context
     state.ContextStack.Pop();
     state.LoopLevel--;
     var prepareLoopStatements = SyntaxHelper.PrepareForLoop(astNode.Flags, state.LoopLevel + 1);
     Context context;
     if (astNode.Member.TryEvaluate(state, out context))
     {
       prepareLoopStatements.Add(SyntaxHelper.ForLoop(astNode.Member.EvaluateLoop(state).FullPath, context.FullPath, state.PopBlock()));
     }
     state.DoTruthyCheck(
     prepareLoopStatements
     );
       } else if (astNode.Type==EachBlock.LoopType.CompileTime)
       {
     //Check if loop is completed
     var ctLoopContext = state.ContextStack.Peek() as CompileTimeLoopContext;
     if (ctLoopContext.MoveNext())
     {//Next Iteration
       astNode.Accept(this);
     }
     else
     {//Pop ctLoopContext
       state.ContextStack.Pop();
       state.DoTruthyCheck(state.PopBlock());
     }
       }
 }
 public void VisitEnter(EachBlock astNode)
 {
     state.SetCursor(astNode);
       //Check if we are already in a compiletime loop.
       if (astNode.Type!=EachBlock.LoopType.CompileTime)
       {//Not in compiletime loop. procede as usual
     Context loopedVariable;
     if (astNode.Member.TryEvaluate(state, out loopedVariable))
     {
       state.PromiseTruthyCheck(loopedVariable);
       state.PushNewBlock();
       Context loopContext = astNode.Member.EvaluateLoop(state);
       if (loopContext!=null)
       {//The loopVariable implements IEnumerable -> runtimeloop over its contents
     astNode.Type = EachBlock.LoopType.RunTime;
     state.ContextStack.Push(astNode.Member.EvaluateLoop(state));
     state.LoopLevel++;
     if (astNode.Flags.HasFlag(EachBlock.ForLoopFlags.Last))
       state.SetLastVariable(loopedVariable.FullPath);
       }
       else
       {//The loopVariable is an object. Compiletimeloop over its Members
     astNode.Type = EachBlock.LoopType.CompileTime;
     //Push the CompileTimeLoopContext
     var ctLoopContext = new CompileTimeLoopContext(loopedVariable.FullPath, loopedVariable.Symbol);
     ctLoopContext.MoveNext();
     state.ContextStack.Push(ctLoopContext);
       }
     }
       }
 }