Пример #1
0
        public void EvaluateArrayVariableExpression()
        {
            Context context = new Context();

            context.SetValue("array", new string[] { "one", "two", "three" });

            IExpression expression = new IndexedExpression(new VariableExpression("array"), new IExpression[] { new ConstantExpression(1) });

            object result = expression.Evaluate(context);

            Assert.IsNotNull(result);
            Assert.AreEqual("two", result);
        }
Пример #2
0
        public void EvaluateArrayDotExpression()
        {
            Context context = new Context();

            DynamicObject data = new DynamicObject();
            data.SetValue("Numbers", new string[] { "one", "two", "three" });

            context.SetValue("data", data);

            IExpression expression = new IndexedExpression(new DotExpression(new VariableExpression("data"), "Numbers"), new IExpression[] { new ConstantExpression(1) });

            object result = expression.Evaluate(context);

            Assert.IsNotNull(result);
            Assert.AreEqual("two", result);
        }
Пример #3
0
        private IExpression ParseTermExpression()
        {
            if (this.TryParse(TokenType.Name, "new"))
                return this.ParseNewExpression();

            IExpression expression = this.ParseSimpleTermExpression();

            while (this.TryParse(TokenType.Delimiter, ".", "[", "("))
            {
                if (this.TryParse(TokenType.Delimiter, "."))
                {
                    this.lexer.NextToken();
                    string name = this.ParseName();
                    IList<IExpression> arguments = null;

                    if (this.TryParse(TokenType.Delimiter, "("))
                        arguments = this.ParseArgumentList();

                    expression = new DotExpression(expression, name, arguments);
                    continue;
                }

                if (this.TryParse(TokenType.Delimiter, "("))
                {
                    IList<IExpression> arguments = this.ParseArgumentList();
                    expression = new InvokeExpression(expression, arguments);
                    continue;
                }

                expression = new IndexedExpression(expression, this.ParseArrayArgumentList());
            }

            return expression;
        }