summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2012-01-13 11:43:40 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2012-01-13 11:43:40 (GMT)
commit1f7ce62bd61488d5d721896a36a1b43befab88b5 (patch)
treee7c92d4429ce431c78d0b7816c93862629590223 /Python/ast.c
parente51757f6de9db71b7ee0a6cbf7dde62e9f146804 (diff)
downloadcpython-1f7ce62bd61488d5d721896a36a1b43befab88b5.zip
cpython-1f7ce62bd61488d5d721896a36a1b43befab88b5.tar.gz
cpython-1f7ce62bd61488d5d721896a36a1b43befab88b5.tar.bz2
Implement PEP 380 - 'yield from' (closes #11682)
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 110754b..7080c65 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2369,13 +2369,24 @@ ast_for_expr(struct compiling *c, const node *n)
}
return ast_for_binop(c, n);
case yield_expr: {
+ node *an = NULL;
+ node *en = NULL;
+ int is_from = 0;
expr_ty exp = NULL;
- if (NCH(n) == 2) {
- exp = ast_for_testlist(c, CHILD(n, 1));
+ if (NCH(n) > 1)
+ an = CHILD(n, 1); /* yield_arg */
+ if (an) {
+ en = CHILD(an, NCH(an) - 1);
+ if (NCH(an) == 2) {
+ is_from = 1;
+ exp = ast_for_expr(c, en);
+ }
+ else
+ exp = ast_for_testlist(c, en);
if (!exp)
return NULL;
}
- return Yield(exp, LINENO(n), n->n_col_offset, c->c_arena);
+ return Yield(is_from, exp, LINENO(n), n->n_col_offset, c->c_arena);
}
case factor:
if (NCH(n) == 1) {
@@ -2399,7 +2410,7 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
/*
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
| '**' test)
- argument: [test '='] test [comp_for] # Really [keyword '='] test
+ argument: [test '='] (test) [comp_for] # Really [keyword '='] test
*/
int i, nargs, nkeywords, ngens;
@@ -2693,7 +2704,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
continue_stmt: 'continue'
return_stmt: 'return' [testlist]
yield_stmt: yield_expr
- yield_expr: 'yield' testlist
+ yield_expr: 'yield' testlist | 'yield' 'from' test
raise_stmt: 'raise' [test [',' test [',' test]]]
*/
node *ch;