Exemple #1
0
        public IExpression CompileList()
        {
            ListExpression listExpression = new ListExpression();

            Token token = this.lexer.NextToken();

            while (token != null && token.Value != "]")
            {
                if (listExpression.Expressions.Count != 0)
                {
                    if (token.Value != ",")
                    {
                        throw new InvalidDataException(string.Format("Unexpected '{0}'", token.Value));
                    }
                }
                else
                {
                    this.lexer.PushToken(token);
                }

                IExpression expression = this.CompileExpression();
                listExpression.Add(expression);

                token = this.lexer.NextToken();
            }

            if (token != null)
            {
                this.lexer.PushToken(token);
            }

            return(listExpression);
        }
        public void EvaluateListExpression()
        {
            ListExpression expression = new ListExpression();

            expression.Add(new ConstantExpression(1));
            expression.Add(new ConstantExpression("foo"));

            Assert.IsNotNull(expression.Expressions);
            Assert.AreEqual(2, expression.Expressions.Count);

            object result = expression.Evaluate(new BindingEnvironment());

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IList));

            IList list = (IList)result;

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(1, list[0]);
            Assert.AreEqual("foo", list[1]);
        }