summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 92b02f0..c8357b1 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -2557,6 +2557,27 @@ ast_for_global_stmt(struct compiling *c, const node *n)
}
static stmt_ty
+ast_for_nonlocal_stmt(struct compiling *c, const node *n)
+{
+ /* nonlocal_stmt: 'nonlocal' NAME (',' NAME)* */
+ identifier name;
+ asdl_seq *s;
+ int i;
+
+ REQ(n, nonlocal_stmt);
+ s = asdl_seq_new(NCH(n) / 2, c->c_arena);
+ if (!s)
+ return NULL;
+ for (i = 1; i < NCH(n); i += 2) {
+ name = NEW_IDENTIFIER(CHILD(n, i));
+ if (!name)
+ return NULL;
+ asdl_seq_SET(s, i / 2, name);
+ }
+ return Nonlocal(s, LINENO(n), n->n_col_offset, c->c_arena);
+}
+
+static stmt_ty
ast_for_assert_stmt(struct compiling *c, const node *n)
{
/* assert_stmt: 'assert' test [',' test] */
@@ -3063,8 +3084,8 @@ ast_for_stmt(struct compiling *c, const node *n)
if (TYPE(n) == small_stmt) {
REQ(n, small_stmt);
n = CHILD(n, 0);
- /* small_stmt: expr_stmt | del_stmt | pass_stmt
- | flow_stmt | import_stmt | global_stmt | assert_stmt
+ /* small_stmt: expr_stmt | del_stmt | pass_stmt | flow_stmt
+ | import_stmt | global_stmt | nonlocal_stmt | assert_stmt
*/
switch (TYPE(n)) {
case expr_stmt:
@@ -3079,6 +3100,8 @@ ast_for_stmt(struct compiling *c, const node *n)
return ast_for_import_stmt(c, n);
case global_stmt:
return ast_for_global_stmt(c, n);
+ case nonlocal_stmt:
+ return ast_for_nonlocal_stmt(c, n);
case assert_stmt:
return ast_for_assert_stmt(c, n);
default: