Mercurial > python-compiler.rs
diff 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 |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -308,6 +308,7 @@ fn parse_expr(py: Python, ast: PyObject) let setcomp_type = ast_module.get(py, "SetComp").unwrap(); let generatorexp_type = ast_module.get(py, "GeneratorExp").unwrap(); let lambda_type = ast_module.get(py, "Lambda").unwrap(); + let ifexp_type = ast_module.get(py, "IfExp").unwrap(); assert!(is_instance(&ast, &ast_type)); @@ -453,6 +454,16 @@ fn parse_expr(py: Python, ast: PyObject) let body = parse_expr(py, body); expr::Lambda(Box::new(args), Box::new(body)) + } else if is_instance(&ast, &ifexp_type) { + let test = ast.getattr(py, "test").unwrap(); + let body = ast.getattr(py, "body").unwrap(); + let orelse = ast.getattr(py, "orelse").unwrap(); + + let test = parse_expr(py, test); + let body = parse_expr(py, body); + let orelse = parse_expr(py, orelse); + + expr::IfExp(Box::new(test), Box::new(body), Box::new(orelse)) } else { println!("expr {}", ast); unreachable!()