comparison src/ast_convert.rs @ 7:680d15073f55

Add ast.List literal.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 31 May 2016 04:26:58 +0100
parents 6f2bf13f4cb5
children 94ff501bf336
comparison
equal deleted inserted replaced
6:6f2bf13f4cb5 7:680d15073f55
117 let name_constant_type = ast_module.get(py, "NameConstant").unwrap(); 117 let name_constant_type = ast_module.get(py, "NameConstant").unwrap();
118 let attribute_type = ast_module.get(py, "Attribute").unwrap(); 118 let attribute_type = ast_module.get(py, "Attribute").unwrap();
119 let name_type = ast_module.get(py, "Name").unwrap(); 119 let name_type = ast_module.get(py, "Name").unwrap();
120 let num_type = ast_module.get(py, "Num").unwrap(); 120 let num_type = ast_module.get(py, "Num").unwrap();
121 let str_type = ast_module.get(py, "Str").unwrap(); 121 let str_type = ast_module.get(py, "Str").unwrap();
122 let list_type = ast_module.get(py, "List").unwrap();
122 let compare_type = ast_module.get(py, "Compare").unwrap(); 123 let compare_type = ast_module.get(py, "Compare").unwrap();
123 let call_type = ast_module.get(py, "Call").unwrap(); 124 let call_type = ast_module.get(py, "Call").unwrap();
124 let alias_type = ast_module.get(py, "alias").unwrap(); 125 let alias_type = ast_module.get(py, "alias").unwrap();
125 126
126 assert!(is_instance(&ast, &ast_type)); 127 assert!(is_instance(&ast, &ast_type));
151 Expr::Num(n) 152 Expr::Num(n)
152 } else if is_instance(&ast, &str_type) { 153 } else if is_instance(&ast, &str_type) {
153 let s = ast.getattr(py, "s").unwrap(); 154 let s = ast.getattr(py, "s").unwrap();
154 let s = get_str(py, s); 155 let s = get_str(py, s);
155 Expr::Str(s) 156 Expr::Str(s)
157 } else if is_instance(&ast, &list_type) {
158 let elts = ast.getattr(py, "elts").unwrap();
159
160 let mut elements = vec!();
161 for elt in elts.iter(py).unwrap() {
162 let elt = elt.unwrap();
163 elements.push(parse_expr(py, elt));
164 }
165
166 Expr::List(elements)
156 } else if is_instance(&ast, &unary_op_type) { 167 } else if is_instance(&ast, &unary_op_type) {
157 let op = ast.getattr(py, "op").unwrap(); 168 let op = ast.getattr(py, "op").unwrap();
158 let operand = ast.getattr(py, "operand").unwrap(); 169 let operand = ast.getattr(py, "operand").unwrap();
159 170
160 let op = parse_unaryop(py, op); 171 let op = parse_unaryop(py, op);