コード例 #1
0
        public override EnumeratorTemplateElement Deserialize(TemplateTokenizer tokenizer, AbstractTemplateElement root)
        {
            var result = new EnumeratorTemplateElement(root);

            tokenizer.AdvanceUntilChar(' ');
            tokenizer.AdvanceWhileChar(' ');

            switch (tokenizer.CurrentChar)
            {
            case '{':
                result.EnumerationCondition = new VariableConditionPart {
                    VariableName = tokenizer.AdvanceUntilChar('>').InfoBetween("{", "}")
                };
                tokenizer.Advance();
                break;

            case '[':
                result.EnumerationCondition = ConditionDeserializer.Deserialize(tokenizer.AdvanceUntilChar(']').InfoAfter("[", int.MaxValue), new Dictionary <string, AbstractConditionPart>());
                tokenizer.AdvanceUntilChar('>');
                tokenizer.Advance();
                break;
            }
            result.Elements = FindElements(result, tokenizer, "/FOREACH").ToArray();
            tokenizer.AdvanceUntilChar('>');
            return(result);
        }
コード例 #2
0
        public override ConditionalTemplateElement Deserialize(TemplateTokenizer tokenizer, AbstractTemplateElement root)
        {
            var result = new ConditionalTemplateElement(root)
            {
                Condition = ConditionDeserializer.Deserialize(tokenizer.AdvanceUntilChar(']').InfoAfter("[", int.MaxValue), new Dictionary <string, AbstractConditionPart>())
            };

            tokenizer.AdvanceUntilChar('>');
            tokenizer.Advance();
            result.ConditionTrueElements = FindElements(result, tokenizer, "/IF", ":ELSE:").ToArray();
            var command = tokenizer.AdvanceUntilChar('>').ToUpper();

            if (command != ":ELSE:")
            {
                return(result);
            }

            tokenizer.Advance();
            result.ConditionFalseElements = FindElements(result, tokenizer, "/IF", ":ELSE:").ToArray();
            tokenizer.AdvanceUntilChar('>');
            return(result);
        }
コード例 #3
0
        public override DefineTemplateElement Deserialize(TemplateTokenizer tokenizer, AbstractTemplateElement root)
        {
            var result = new DefineTemplateElement(root);

            tokenizer.AdvanceUntilChar(' ');
            var stuff = tokenizer.AdvanceUntilChar('>').Trim();

            result.Variable = (VariableConditionPart)ConditionDeserializer.Deserialize(stuff, new Dictionary <string, AbstractConditionPart>());
            result.IsArray  = Command == TemplateCommandEnum.DefineArray;
            tokenizer.Advance();
            result.Elements = FindElements(result, tokenizer, "/DEFINE").ToArray();
            tokenizer.AdvanceUntilChar('>');
            return(result);
        }
コード例 #4
0
        public override RangeTemplateElement Deserialize(TemplateTokenizer tokenizer, AbstractTemplateElement root)
        {
            var result = new RangeTemplateElement(root);

            tokenizer.AdvanceUntilChar(' ');
            tokenizer.AdvanceWhileChar(' ');

            if (tokenizer.CurrentChar == '[')
            {
                var condition = ConditionDeserializer.Deserialize(tokenizer.AdvanceUntilChar(']').InfoAfter("[", int.MaxValue), new Dictionary <string, AbstractConditionPart>());
                var opCond    = condition as OperationConditionPart;
                if (!(opCond?.LeftSide is VariableConditionPart) || opCond.Operator != ConditionPartOperatorEnum.Range || !(opCond.RightSide is OperationConditionPart))
                {
                    throw new ArgumentException("Invalid FOR condition");
                }

                result.Variable = (VariableConditionPart)opCond.LeftSide;
                var cond = (OperationConditionPart)opCond.RightSide;

                if (cond.Operator != ConditionPartOperatorEnum.To && cond.Operator != ConditionPartOperatorEnum.Until)
                {
                    throw new ArgumentException("Invalid FOR condition");
                }

                result.InludeMaximum = cond.Operator == ConditionPartOperatorEnum.To;
                result.Minimum       = cond.LeftSide;
                result.Maximum       = cond.RightSide;

                tokenizer.AdvanceUntilChar('>');
                tokenizer.Advance();
            }
            else
            {
                throw new ArgumentException("FOR must have a condition in []");
            }

            result.Elements = FindElements(result, tokenizer, "/FOR").ToArray();
            tokenizer.AdvanceUntilChar('>');
            return(result);
        }