Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(538)

Unified Diff: Python/ast.c

Issue 20101: Python Yield-From Prototype Implementation
Patch Set: Created 15 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Parser/Python.asdl ('k') | Python/ceval.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Python/ast.c
===================================================================
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1834,13 +1834,28 @@ ast_for_expr(struct compiling *c, const
}
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 yield_from: {
+ expr_ty exp = ast_for_expr(c, CHILD(n, 2));
+ return Yield(1, exp, LINENO(n), n->n_col_offset, c->c_arena);
}
case factor:
if (NCH(n) == 1) {
@@ -1864,7 +1879,7 @@ ast_for_call(struct compiling *c, const
/*
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test]
| '**' test)
- argument: [test '='] test [gen_for] # Really [keyword '='] test
+ argument: [test '='] (test | yield_from) [gen_for] # Really [keyword '='] test
*/
int i, nargs, nkeywords, ngens;
@@ -2243,7 +2258,7 @@ ast_for_flow_stmt(struct compiling *c, c
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;
« no previous file with comments | « Parser/Python.asdl ('k') | Python/ceval.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b