#region COPYRIGHT
//
//     THIS IS GENERATED BY TEMPLATE
//     
//     AUTHOR  :     ROYE
//     DATE       :     2010
//
//     COPYRIGHT (C) 2010, TIANXIAHOTEL TECHNOLOGIES CO., LTD. ALL RIGHTS RESERVED.
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace System.Text.Template
{
    internal class WhileNode : ExpressionNode
    {
        public WhileNode(TokenMatch tokenMatch)
            : base(tokenMatch)
        {
        }

        private void EvaluateIterator(ITemplateContext context, int index)
        {
            context.AddLocal("index", index);
        }

        public override void Evaluate(IExpressionParser parser, ITemplateContext context, StringBuilder output)
        {
            int index = 1;
            ITemplateContext local = context.CreateLocal();

            while (context.ToBoolean(parser.Parse(this.Expression).Evaluate(context).Value))
            {
                local.AddLocal("index", index);

                foreach (TokenNode node in this.ChildNodes)
                {
                    node.Evaluate(parser, local, output);
                }

                index++;
            }
        }

        public static explicit operator WhileNode(TokenMatch tokenMatch)
        {
            return new WhileNode(tokenMatch);
        }
    }
}
