Mercurial > python-compiler.rs
comparison src/ast_convert.rs @ 80:c6d3f0dabbba
Add ast.IfExp.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 20:12:39 +0200 |
parents | 6bf54bff8dbd |
children | dc82a0d8f144 |
comparison
equal
deleted
inserted
replaced
79:6bf54bff8dbd | 80:c6d3f0dabbba |
---|---|
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 let lambda_type = ast_module.get(py, "Lambda").unwrap(); |
311 let ifexp_type = ast_module.get(py, "IfExp").unwrap(); | |
311 | 312 |
312 assert!(is_instance(&ast, &ast_type)); | 313 assert!(is_instance(&ast, &ast_type)); |
313 | 314 |
314 if is_instance(&ast, &attribute_type) { | 315 if is_instance(&ast, &attribute_type) { |
315 let value = ast.getattr(py, "value").unwrap(); | 316 let value = ast.getattr(py, "value").unwrap(); |
451 | 452 |
452 let args = parse_arguments(py, args); | 453 let args = parse_arguments(py, args); |
453 let body = parse_expr(py, body); | 454 let body = parse_expr(py, body); |
454 | 455 |
455 expr::Lambda(Box::new(args), Box::new(body)) | 456 expr::Lambda(Box::new(args), Box::new(body)) |
457 } else if is_instance(&ast, &ifexp_type) { | |
458 let test = ast.getattr(py, "test").unwrap(); | |
459 let body = ast.getattr(py, "body").unwrap(); | |
460 let orelse = ast.getattr(py, "orelse").unwrap(); | |
461 | |
462 let test = parse_expr(py, test); | |
463 let body = parse_expr(py, body); | |
464 let orelse = parse_expr(py, orelse); | |
465 | |
466 expr::IfExp(Box::new(test), Box::new(body), Box::new(orelse)) | |
456 } else { | 467 } else { |
457 println!("expr {}", ast); | 468 println!("expr {}", ast); |
458 unreachable!() | 469 unreachable!() |
459 } | 470 } |
460 } | 471 } |