comparison src/ast_convert.rs @ 79:6bf54bff8dbd

Add ast.Lambda.
author Bastien Orivel <eijebong@bananium.fr>
date Mon, 13 Jun 2016 20:06:34 +0200
parents f1a845e4121b
children c6d3f0dabbba
comparison
equal deleted inserted replaced
78:f1a845e4121b 79:6bf54bff8dbd
305 let yield_type = ast_module.get(py, "Yield").unwrap(); 305 let yield_type = ast_module.get(py, "Yield").unwrap();
306 let yield_from_type = ast_module.get(py, "YieldFrom").unwrap(); 306 let yield_from_type = ast_module.get(py, "YieldFrom").unwrap();
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 311
311 assert!(is_instance(&ast, &ast_type)); 312 assert!(is_instance(&ast, &ast_type));
312 313
313 if is_instance(&ast, &attribute_type) { 314 if is_instance(&ast, &attribute_type) {
314 let value = ast.getattr(py, "value").unwrap(); 315 let value = ast.getattr(py, "value").unwrap();
442 443
443 let elt = parse_expr(py, elt); 444 let elt = parse_expr(py, elt);
444 let generators = parse_list(py, generators, parse_comprehension); 445 let generators = parse_list(py, generators, parse_comprehension);
445 446
446 expr::GeneratorExp(Box::new(elt), generators) 447 expr::GeneratorExp(Box::new(elt), generators)
448 } else if is_instance(&ast, &lambda_type) {
449 let args = ast.getattr(py, "args").unwrap();
450 let body = ast.getattr(py, "body").unwrap();
451
452 let args = parse_arguments(py, args);
453 let body = parse_expr(py, body);
454
455 expr::Lambda(Box::new(args), Box::new(body))
447 } else { 456 } else {
448 println!("expr {}", ast); 457 println!("expr {}", ast);
449 unreachable!() 458 unreachable!()
450 } 459 }
451 } 460 }