# HG changeset patch # User Bastien Orivel # Date 1465399569 -7200 # Node ID ded1907b7a6991abdad9dc801938d818c1b292cf # Parent 5edbc24b625f83673f8cd73c9f1480958ad6b4c1 Add ast.Nonlocal. diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -430,6 +430,7 @@ fn parse_statement(py: Python, ast: PyOb let class_def_type = ast_module.get(py, "ClassDef").unwrap(); let function_def_type = ast_module.get(py, "FunctionDef").unwrap(); let global_type = ast_module.get(py, "Global").unwrap(); + let nonlocal_type = ast_module.get(py, "Nonlocal").unwrap(); let assign_type = ast_module.get(py, "Assign").unwrap(); let aug_assign_type = ast_module.get(py, "AugAssign").unwrap(); let return_type = ast_module.get(py, "Return").unwrap(); @@ -489,6 +490,10 @@ fn parse_statement(py: Python, ast: PyOb let names = ast.getattr(py, "names").unwrap(); let names = parse_list(py, names, get_str); stmt::Global(names) + } else if is_instance(&ast, &nonlocal_type) { + let names = ast.getattr(py, "names").unwrap(); + let names = parse_list(py, names, get_str); + stmt::Nonlocal(names) } else if is_instance(&ast, &if_type) { let test = ast.getattr(py, "test").unwrap(); let body = ast.getattr(py, "body").unwrap(); diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -181,6 +181,7 @@ impl stmt { stmt::ClassDef(name, bases, keywords, body, decorator_list) => format!("{}class {}({}):\n{}", current_indent, name, args_to_string(bases), statements_to_string(indent, body)), stmt::FunctionDef(name, arguments, body, decorator_list, returns) => format!("{}def {}({}):\n{}", current_indent, name, arguments_to_string(arguments), statements_to_string(indent, body)), stmt::Global(names) => format!("{}global {}", current_indent, names.join(", ")), + stmt::Nonlocal(names) => format!("{}nonlocal {}", current_indent, names.join(", ")), stmt::If(test, body, orelse) => format!("{}if {}:\n{}", current_indent, test.to_string(), if_else_statements_to_string(indent, body, orelse)), stmt::While(test, body, orelse) => format!("{}while {}:\n{}", current_indent, test.to_string(), if_else_statements_to_string(indent, body, orelse)), stmt::For(target, iter, body, orelse) => format!("{}for {} in {}:\n{}", current_indent, target.to_string(), iter.to_string(), if_else_statements_to_string(indent, body, orelse)), diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -64,7 +64,7 @@ pub enum stmt { Global(Vec), // Nonlocal(identifier* names) - //Nonlocal(Vec), + Nonlocal(Vec), // expr(expr value) Expr(expr), diff --git a/tests/test_parse_files/test_nonlocal.py b/tests/test_parse_files/test_nonlocal.py new file mode 100644 --- /dev/null +++ b/tests/test_parse_files/test_nonlocal.py @@ -0,0 +1,2 @@ +def a(): + nonlocal b, c