Ejemplo n.º 1
0
 public override bool Walk(ExpressionStatement node) {
     if (node.Expression is TupleExpression) {
         node.Expression.Walk(this);
         CommitByDefault = false;
         return false;
     }
     return base.Walk(node);
 }
Ejemplo n.º 2
0
        // expr_stmt: expression_list
        // expression_list: expression ( "," expression )* [","] 
        // assignment_stmt: (target_list "=")+ (expression_list | yield_expression) 
        // augmented_assignment_stmt ::= target augop (expression_list | yield_expression) 
        // augop: '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '>>=' | '<<=' | '&=' | '^=' | '|=' | '//='
        private Statement ParseExprStmt() {
            Expression ret = ParseTestListAsExpr();

            if (PeekToken(TokenKind.Assign)) {
                if (_langVersion >= PythonLanguageVersion.V30) {
                    SequenceExpression seq = ret as SequenceExpression;
                    bool hasStar = false;
                    if (seq != null) {
                        for (int i = 0; i < seq.Items.Count; i++) {
                            if (seq.Items[i] is StarredExpression) {
                                if (hasStar) {
                                    ReportSyntaxError(seq.Items[i].StartIndex, seq.Items[i].EndIndex, "two starred expressions in assignment");
                                }
                                hasStar = true;
                            }
                        }
                    }
                }

                return FinishAssignments(ret);
            } else {
                PythonOperator op = GetAssignOperator(PeekToken());
                if (op != PythonOperator.None) {
                    NextToken();
                    string whiteSpace = _tokenWhiteSpace;
                    Expression rhs;

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

                    string assignError = ret.CheckAugmentedAssign();
                    if (assignError != null) {
                        ReportSyntaxError(ret.StartIndex, ret.EndIndex, assignError);
                    }

                    AugmentedAssignStatement aug = new AugmentedAssignStatement(op, ret, rhs);
                    if (_verbatim) {
                        AddPreceedingWhiteSpace(aug, whiteSpace);
                    }
                    aug.SetLoc(ret.StartIndex, GetEnd());
                    return aug;
                } else {
                    Statement stmt = new ExpressionStatement(ret);
                    stmt.SetLoc(ret.IndexSpan);
                    return stmt;
                }
            }
        }
Ejemplo n.º 3
0
            public override bool Walk(ExpressionStatement node) {
                if (node.Expression is TupleExpression) {
                    node.Expression.Walk(this);
                    CommitByDefault = false;
                    return false;
                } else if (node.Expression is ConstantExpression) {
                    node.Expression.Walk(this);
                    return false;
                } else if (node.Expression is ErrorExpression) {
                    // Might be an unfinished string literal, which we care about
                    node.Expression.Walk(this);
                    return false;
                }

                CanComplete = true;
                CommitByDefault = false;
                return base.Walk(node);
            }
Ejemplo n.º 4
0
        private Expression ParseLambdaHelperEnd(FunctionDefinition func, Expression expr, string whitespace, string colonWhiteSpace, List<string> commaWhiteSpace, bool ateTerminator) {
            // Pep 342 in Python 2.5 allows Yield Expressions, which can occur inside a Lambda body. 
            // In this case, the lambda is a generator and will yield it's final result instead of just return it.
            Statement body;
            if (func.IsGenerator) {
                YieldExpression y = new YieldExpression(expr);
                y.SetLoc(expr.IndexSpan);
                body = new ExpressionStatement(y);
            } else {
                body = new ReturnStatement(expr);
            }
            body.SetLoc(expr.StartIndex, expr.EndIndex);

            FunctionDefinition func2 = PopFunction();
            System.Diagnostics.Debug.Assert(func == func2);

            func.SetBody(body);
            func.EndIndex = GetEnd();

            LambdaExpression ret = new LambdaExpression(func);
            func.SetLoc(func.IndexSpan);
            ret.SetLoc(func.IndexSpan);
            if (_verbatim) {
                AddPreceedingWhiteSpace(ret, whitespace);
                AddSecondPreceedingWhiteSpace(ret, colonWhiteSpace);
                AddListWhiteSpace(ret, commaWhiteSpace.ToArray());
                if (!ateTerminator) {
                    AddErrorIsIncompleteNode(ret);
                }
            }
            return ret;
        }
Ejemplo n.º 5
0
        private Statement ParseYieldStmt() {
            // For yield statements, continue to enforce that it's currently in a function. 
            // This gives us better syntax error reporting for yield-statements than for yield-expressions.
            if (!AllowYieldSyntax) {
                if (AllowAsyncAwaitSyntax) {
                    ReportSyntaxError("'yield' inside async function");
                } else {
                    ReportSyntaxError("misplaced yield");
                }
            }

            _isGenerator = true;
            if (_returnsWithValue != null && _langVersion < PythonLanguageVersion.V33) {
                foreach (var span in _returnsWithValue) {
                    ReportSyntaxError(span.Start, span.End, "'return' with argument inside generator");
                }
            }

            Eat(TokenKind.KeywordYield);

            // See Pep 342: a yield statement is now just an expression statement around a yield expression.
            Expression e = ParseYieldExpression();
            Debug.Assert(e != null); // caller already verified we have a yield.

            Statement s = new ExpressionStatement(e);
            s.SetLoc(e.IndexSpan);
            return s;
        }
Ejemplo n.º 6
0
 private static bool IsDocString(ExpressionStatement exprStmt) {
     ConstantExpression constExpr;
     return exprStmt != null &&
             (constExpr = exprStmt.Expression as ConstantExpression) != null &&
             (constExpr.Value is string || constExpr.Value is AsciiString);
 }
Ejemplo n.º 7
0
        public override bool Walk(ExpressionStatement node) {
            UpdateLineInfo(node);

            return base.Walk(node);
        }
Ejemplo n.º 8
0
 public override bool Walk(ExpressionStatement node) {
     UpdateChildRanges(node);
     return base.Walk(node);
 }
Ejemplo n.º 9
0
 public override void PostWalk(ExpressionStatement node) { PostWalkWorker(node); }
Ejemplo n.º 10
0
 // ExpressionStatement
 public override bool Walk(ExpressionStatement node) { return ShouldWalkWorker(node); }