comparison src/ast_convert.rs @ 81:dc82a0d8f144

Add ast.Dict.
author Bastien Orivel <eijebong@bananium.fr>
date Mon, 13 Jun 2016 20:45:19 +0200
parents c6d3f0dabbba
children 2d906d1cb940
comparison
equal deleted inserted replaced
80:c6d3f0dabbba 81:dc82a0d8f144
307 let set_type = ast_module.get(py, "Set").unwrap(); 307 let set_type = ast_module.get(py, "Set").unwrap();
308 let setcomp_type = ast_module.get(py, "SetComp").unwrap(); 308 let setcomp_type = ast_module.get(py, "SetComp").unwrap();
309 let generatorexp_type = ast_module.get(py, "GeneratorExp").unwrap(); 309 let generatorexp_type = ast_module.get(py, "GeneratorExp").unwrap();
310 let lambda_type = ast_module.get(py, "Lambda").unwrap(); 310 let lambda_type = ast_module.get(py, "Lambda").unwrap();
311 let ifexp_type = ast_module.get(py, "IfExp").unwrap(); 311 let ifexp_type = ast_module.get(py, "IfExp").unwrap();
312 let dict_type = ast_module.get(py, "Dict").unwrap();
312 313
313 assert!(is_instance(&ast, &ast_type)); 314 assert!(is_instance(&ast, &ast_type));
314 315
315 if is_instance(&ast, &attribute_type) { 316 if is_instance(&ast, &attribute_type) {
316 let value = ast.getattr(py, "value").unwrap(); 317 let value = ast.getattr(py, "value").unwrap();
462 let test = parse_expr(py, test); 463 let test = parse_expr(py, test);
463 let body = parse_expr(py, body); 464 let body = parse_expr(py, body);
464 let orelse = parse_expr(py, orelse); 465 let orelse = parse_expr(py, orelse);
465 466
466 expr::IfExp(Box::new(test), Box::new(body), Box::new(orelse)) 467 expr::IfExp(Box::new(test), Box::new(body), Box::new(orelse))
468 } else if is_instance(&ast, &dict_type) {
469 let keys = ast.getattr(py, "keys").unwrap();
470 let values = ast.getattr(py, "values").unwrap();
471
472 let keys = parse_list(py, keys, parse_optional_expr);
473 let values = parse_list(py, values, parse_expr);
474
475 expr::Dict(keys, values)
467 } else { 476 } else {
468 println!("expr {}", ast); 477 println!("expr {}", ast);
469 unreachable!() 478 unreachable!()
470 } 479 }
471 } 480 }