Mercurial > python-compiler.rs
changeset 21:7af637f444d1
Add ast.Delete
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Fri, 03 Jun 2016 10:52:02 +0200 |
parents | ace12d6b9855 |
children | 25b202005d1d |
files | example/delete.py src/ast_convert.rs src/ast_dump.rs src/python_ast.rs |
diffstat | 4 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/example/delete.py @@ -0,0 +1,4 @@ +def function(a): + b = a + c = b + del a, b
--- 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!()
--- 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)) } } }