comparison src/ast_convert.rs @ 4:f27a4aee9dfa

Add ast.Attribute.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 31 May 2016 03:59:05 +0100
parents 326d7f2a94d4
children ddf372373a77
comparison
equal deleted inserted replaced
3:326d7f2a94d4 4:f27a4aee9dfa
78 let ast_module = py.import("ast").unwrap(); 78 let ast_module = py.import("ast").unwrap();
79 let ast_type = ast_module.get(py, "AST").unwrap(); 79 let ast_type = ast_module.get(py, "AST").unwrap();
80 let arg_type = ast_module.get(py, "arg").unwrap(); 80 let arg_type = ast_module.get(py, "arg").unwrap();
81 let bin_op_type = ast_module.get(py, "BinOp").unwrap(); 81 let bin_op_type = ast_module.get(py, "BinOp").unwrap();
82 let name_constant_type = ast_module.get(py, "NameConstant").unwrap(); 82 let name_constant_type = ast_module.get(py, "NameConstant").unwrap();
83 let attribute_type = ast_module.get(py, "Attribute").unwrap();
83 let name_type = ast_module.get(py, "Name").unwrap(); 84 let name_type = ast_module.get(py, "Name").unwrap();
84 let num_type = ast_module.get(py, "Num").unwrap(); 85 let num_type = ast_module.get(py, "Num").unwrap();
85 let str_type = ast_module.get(py, "Str").unwrap(); 86 let str_type = ast_module.get(py, "Str").unwrap();
86 let compare_type = ast_module.get(py, "Compare").unwrap(); 87 let compare_type = ast_module.get(py, "Compare").unwrap();
87 let call_type = ast_module.get(py, "Call").unwrap(); 88 let call_type = ast_module.get(py, "Call").unwrap();
91 92
92 if is_instance(&ast, &arg_type) { 93 if is_instance(&ast, &arg_type) {
93 let arg = ast.getattr(py, "arg").unwrap(); 94 let arg = ast.getattr(py, "arg").unwrap();
94 let arg = get_str(py, arg); 95 let arg = get_str(py, arg);
95 Expr::Name(arg) 96 Expr::Name(arg)
97 } else if is_instance(&ast, &attribute_type) {
98 let value = ast.getattr(py, "value").unwrap();
99 let attr = ast.getattr(py, "attr").unwrap();
100
101 let value = parse_expr(py, value);
102 let attr = get_str(py, attr);
103
104 Expr::Attribute(Box::new(value), attr)
96 } else if is_instance(&ast, &name_type) { 105 } else if is_instance(&ast, &name_type) {
97 let id = ast.getattr(py, "id").unwrap(); 106 let id = ast.getattr(py, "id").unwrap();
98 let id = get_str(py, id); 107 let id = get_str(py, id);
99 Expr::Name(id) 108 Expr::Name(id)
100 } else if is_instance(&ast, &name_constant_type) { 109 } else if is_instance(&ast, &name_constant_type) {