internal override string CheckAssign()
 {
     for (int i = 0; i < Items.Count; i++)
     {
         Expression e = Items[i];
         if (e.CheckAssign() != null)
         {
             // we don't return the same message here as CPython doesn't seem to either,
             // for example ((yield a), 2,3) = (2,3,4) gives a different error than
             // a = yield 3 = yield 4.
             return("can't assign to " + e.NodeName);
         }
     }
     return(null);
 }
 internal override string CheckAssign()
 {
     return(_expression.CheckAssign());
 }
Exemple #3
0
        private Statement FinishAssignments(Expression right) {
            List<Expression> left = null;
            List<string> assignWhiteSpace = MakeWhiteSpaceList();
            Expression singleLeft = null;

            while (MaybeEat(TokenKind.Assign)) {
                if (assignWhiteSpace != null) {
                    assignWhiteSpace.Add(_tokenWhiteSpace);
                }
                string assignError = right.CheckAssign();
                if (assignError != null) {
                    ReportSyntaxError(right.StartIndex, right.EndIndex, assignError, ErrorCodes.SyntaxError | ErrorCodes.NoCaret);
                }

                if (singleLeft == null) {
                    singleLeft = right;
                } else {
                    if (left == null) {
                        left = new List<Expression>();
                        left.Add(singleLeft);
                    }
                    left.Add(right);
                }

                if (_langVersion >= PythonLanguageVersion.V25 && PeekToken(TokenKind.KeywordYield)) {
                    if (!AllowYieldSyntax && AllowAsyncAwaitSyntax) {
                        ReportSyntaxError("'yield' inside async function");
                    }
                    Eat(TokenKind.KeywordYield);
                    right = ParseYieldExpression();
                } else {
                    right = ParseTestListAsExpr();
                }
            }

            AssignmentStatement assign;
            if (left != null) {
                Debug.Assert(left.Count > 0);

                assign = new AssignmentStatement(left.ToArray(), right);
                assign.SetLoc(left[0].StartIndex, right.EndIndex);
            } else {
                Debug.Assert(singleLeft != null);

                assign = new AssignmentStatement(new[] { singleLeft }, right);
                assign.SetLoc(singleLeft.StartIndex, right.EndIndex);
            }
            if (assignWhiteSpace != null) {
                AddListWhiteSpace(assign, assignWhiteSpace.ToArray());
            }
            return assign;
        }