Exemplo n.º 1
0
        private static IEnumerable <IMember> ValuesFromSequenceExpression(IEnumerable <Expression> items, ExpressionEval eval)
        {
            var members = new List <IMember>();

            foreach (var item in items)
            {
                var value = eval.GetValueFromExpression(item);
                switch (value)
                {
                case IPythonCollection coll:
                    members.AddRange(coll.Contents);
                    break;

                default:
                    members.Add(value);
                    break;
                }
            }
            return(members);
        }
        internal static void AssignTuple(TupleExpression lhs, TupleExpression rhs, ExpressionEval eval)
        {
            var returnedExpressions = rhs.Items.ToArray();
            var names = lhs.Items.OfType <NameExpression>().Select(x => x.Name).ToArray();

            for (var i = 0; i < names.Length; i++)
            {
                Expression e = null;
                if (returnedExpressions.Length > 0)
                {
                    e = i < returnedExpressions.Length ? returnedExpressions[i] : returnedExpressions[returnedExpressions.Length - 1];
                }

                if (e != null && !string.IsNullOrEmpty(names[i]))
                {
                    var v = eval.GetValueFromExpression(e);
                    eval.DeclareVariable(names[i], v ?? eval.UnknownType, VariableSource.Declaration, e);
                }
            }
        }