diff 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
line wrap: on
line diff
--- a/src/ast_convert.rs
+++ b/src/ast_convert.rs
@@ -309,6 +309,7 @@ fn parse_expr(py: Python, ast: PyObject)
     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();
+    let dict_type = ast_module.get(py, "Dict").unwrap();
 
     assert!(is_instance(&ast, &ast_type));
 
@@ -464,6 +465,14 @@ fn parse_expr(py: Python, ast: PyObject)
         let orelse = parse_expr(py, orelse);
 
         expr::IfExp(Box::new(test), Box::new(body), Box::new(orelse))
+    } else if is_instance(&ast, &dict_type) {
+        let keys = ast.getattr(py, "keys").unwrap();
+        let values = ast.getattr(py, "values").unwrap();
+
+        let keys = parse_list(py, keys, parse_optional_expr);
+        let values = parse_list(py, values, parse_expr);
+
+        expr::Dict(keys, values)
     } else {
         println!("expr {}", ast);
         unreachable!()