# HG changeset patch # User Bastien Orivel # Date 1464943922 -7200 # Node ID 7af637f444d1f6fd4981f6bd1eb9bf506bc08764 # Parent ace12d6b98553a84bba47b527f657194b7769025 Add ast.Delete diff --git a/example/delete.py b/example/delete.py new file mode 100644 --- /dev/null +++ b/example/delete.py @@ -0,0 +1,4 @@ +def function(a): + b = a + c = b + del a, b diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -20,12 +20,15 @@ fn get_ctx(py: Python, object: PyObject) let ast_module = py.import("ast").unwrap(); let store_type = ast_module.get(py, "Store").unwrap(); let load_type = ast_module.get(py, "Load").unwrap(); + let del_type = ast_module.get(py, "Del").unwrap(); let ctx = object.getattr(py, "ctx").unwrap(); if is_instance(&ctx, &store_type) { expr_context::Store } else if is_instance(&ctx, &load_type) { expr_context::Load + } else if is_instance(&ctx, &del_type) { + expr_context::Del } else{ unreachable!(); } @@ -426,6 +429,7 @@ fn parse_statement(py: Python, ast: PyOb let for_type = ast_module.get(py, "For").unwrap(); let expr_type = ast_module.get(py, "Expr").unwrap(); let break_type = ast_module.get(py, "Break").unwrap(); + let delete_type = ast_module.get(py, "Delete").unwrap(); assert!(is_instance(&ast, &ast_type)); @@ -554,6 +558,10 @@ fn parse_statement(py: Python, ast: PyOb stmt::Expr(value) } else if is_instance(&ast, &break_type) { stmt::Break + } else if is_instance(&ast, &delete_type) { + let targets = ast.getattr(py, "targets").unwrap(); + let targets = parse_list(py, targets, parse_expr); + stmt::Delete(targets) } else { println!("stmt {}", ast); panic!() diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -202,7 +202,8 @@ impl stmt { "".to_string() }), stmt::Expr(expr) => format!("{}{}", current_indent, expr.to_string()), - stmt::Break => format!("{}break", current_indent) + stmt::Break => format!("{}break", current_indent), + stmt::Delete(targets) => format!("{}del {}", current_indent, args_to_string(targets)) } } } diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -19,7 +19,7 @@ pub enum stmt { Return(Option), // Delete(expr* targets) - //Delete(Vec), + Delete(Vec), // Assign(expr* targets, expr value) Assign(Vec, expr),