comparison src/ast_convert.rs @ 17:f1c77634a2eb

Add ast.Tuple
author Bastien Orivel <eijebong@bananium.fr>
date Thu, 02 Jun 2016 23:47:54 +0200
parents b21a246349f3
children 51ef651266b1
comparison
equal deleted inserted replaced
16:b21a246349f3 17:f1c77634a2eb
215 let list_type = ast_module.get(py, "List").unwrap(); 215 let list_type = ast_module.get(py, "List").unwrap();
216 let compare_type = ast_module.get(py, "Compare").unwrap(); 216 let compare_type = ast_module.get(py, "Compare").unwrap();
217 let call_type = ast_module.get(py, "Call").unwrap(); 217 let call_type = ast_module.get(py, "Call").unwrap();
218 let listcomp_type = ast_module.get(py, "ListComp").unwrap(); 218 let listcomp_type = ast_module.get(py, "ListComp").unwrap();
219 let dictcomp_type = ast_module.get(py, "DictComp").unwrap(); 219 let dictcomp_type = ast_module.get(py, "DictComp").unwrap();
220 let tuple_type = ast_module.get(py, "Tuple").unwrap();
220 221
221 assert!(is_instance(&ast, &ast_type)); 222 assert!(is_instance(&ast, &ast_type));
222 223
223 if is_instance(&ast, &arg_type) { 224 if is_instance(&ast, &arg_type) {
224 let arg = ast.getattr(py, "arg").unwrap(); 225 let arg = ast.getattr(py, "arg").unwrap();
350 let gen = gen.unwrap(); 351 let gen = gen.unwrap();
351 let gen = parse_comprehension(py, gen); 352 let gen = parse_comprehension(py, gen);
352 new_gens.push(gen); 353 new_gens.push(gen);
353 } 354 }
354 expr::DictComp(Box::new(key), Box::new(value), new_gens) 355 expr::DictComp(Box::new(key), Box::new(value), new_gens)
356 } else if is_instance(&ast, &tuple_type) {
357 let elts = ast.getattr(py, "elts").unwrap();
358 let elts = elts.iter(py).unwrap();
359
360 let mut new_elts = vec!();
361 for elt in elts {
362 let elt = elt.unwrap();
363 let elt = parse_expr(py, elt);
364 new_elts.push(elt);
365 }
366 expr::Tuple(new_elts, expr_context::Load)
355 } else { 367 } else {
356 println!("expr {}", ast); 368 println!("expr {}", ast);
357 unreachable!() 369 unreachable!()
358 } 370 }
359 } 371 }