Mercurial > python-compiler.rs
diff 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 |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -307,6 +307,7 @@ fn parse_expr(py: Python, ast: PyObject) let set_type = ast_module.get(py, "Set").unwrap(); 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(); assert!(is_instance(&ast, &ast_type)); @@ -444,6 +445,14 @@ fn parse_expr(py: Python, ast: PyObject) let generators = parse_list(py, generators, parse_comprehension); expr::GeneratorExp(Box::new(elt), generators) + } else if is_instance(&ast, &lambda_type) { + let args = ast.getattr(py, "args").unwrap(); + let body = ast.getattr(py, "body").unwrap(); + + let args = parse_arguments(py, args); + let body = parse_expr(py, body); + + expr::Lambda(Box::new(args), Box::new(body)) } else { println!("expr {}", ast); unreachable!()