comparison src/ast_convert.rs @ 21:7af637f444d1

Add ast.Delete
author Bastien Orivel <eijebong@bananium.fr>
date Fri, 03 Jun 2016 10:52:02 +0200
parents ace12d6b9855
children 5f1d285471af
comparison
equal deleted inserted replaced
20:ace12d6b9855 21:7af637f444d1
18 }; 18 };
19 19
20 let ast_module = py.import("ast").unwrap(); 20 let ast_module = py.import("ast").unwrap();
21 let store_type = ast_module.get(py, "Store").unwrap(); 21 let store_type = ast_module.get(py, "Store").unwrap();
22 let load_type = ast_module.get(py, "Load").unwrap(); 22 let load_type = ast_module.get(py, "Load").unwrap();
23 let del_type = ast_module.get(py, "Del").unwrap();
23 24
24 let ctx = object.getattr(py, "ctx").unwrap(); 25 let ctx = object.getattr(py, "ctx").unwrap();
25 if is_instance(&ctx, &store_type) { 26 if is_instance(&ctx, &store_type) {
26 expr_context::Store 27 expr_context::Store
27 } else if is_instance(&ctx, &load_type) { 28 } else if is_instance(&ctx, &load_type) {
28 expr_context::Load 29 expr_context::Load
30 } else if is_instance(&ctx, &del_type) {
31 expr_context::Del
29 } else{ 32 } else{
30 unreachable!(); 33 unreachable!();
31 } 34 }
32 } 35 }
33 36
424 let if_type = ast_module.get(py, "If").unwrap(); 427 let if_type = ast_module.get(py, "If").unwrap();
425 let while_type = ast_module.get(py, "While").unwrap(); 428 let while_type = ast_module.get(py, "While").unwrap();
426 let for_type = ast_module.get(py, "For").unwrap(); 429 let for_type = ast_module.get(py, "For").unwrap();
427 let expr_type = ast_module.get(py, "Expr").unwrap(); 430 let expr_type = ast_module.get(py, "Expr").unwrap();
428 let break_type = ast_module.get(py, "Break").unwrap(); 431 let break_type = ast_module.get(py, "Break").unwrap();
432 let delete_type = ast_module.get(py, "Delete").unwrap();
429 433
430 assert!(is_instance(&ast, &ast_type)); 434 assert!(is_instance(&ast, &ast_type));
431 435
432 /* 436 /*
433 // TODO: implement Hash for PyObject. (trivial) 437 // TODO: implement Hash for PyObject. (trivial)
552 let value = ast.getattr(py, "value").unwrap(); 556 let value = ast.getattr(py, "value").unwrap();
553 let value = parse_expr(py, value); 557 let value = parse_expr(py, value);
554 stmt::Expr(value) 558 stmt::Expr(value)
555 } else if is_instance(&ast, &break_type) { 559 } else if is_instance(&ast, &break_type) {
556 stmt::Break 560 stmt::Break
561 } else if is_instance(&ast, &delete_type) {
562 let targets = ast.getattr(py, "targets").unwrap();
563 let targets = parse_list(py, targets, parse_expr);
564 stmt::Delete(targets)
557 } else { 565 } else {
558 println!("stmt {}", ast); 566 println!("stmt {}", ast);
559 panic!() 567 panic!()
560 } 568 }
561 } 569 }