diff src/ast_convert.rs @ 17:f1c77634a2eb

Add ast.Tuple
author Bastien Orivel <eijebong@bananium.fr>
date Thu, 02 Jun 2016 23:47:54 +0200
parents b21a246349f3
children 51ef651266b1
line wrap: on
line diff
--- a/src/ast_convert.rs
+++ b/src/ast_convert.rs
@@ -217,6 +217,7 @@ fn parse_expr(py: Python, ast: PyObject)
     let call_type = ast_module.get(py, "Call").unwrap();
     let listcomp_type = ast_module.get(py, "ListComp").unwrap();
     let dictcomp_type = ast_module.get(py, "DictComp").unwrap();
+    let tuple_type = ast_module.get(py, "Tuple").unwrap();
 
     assert!(is_instance(&ast, &ast_type));
 
@@ -352,6 +353,17 @@ fn parse_expr(py: Python, ast: PyObject)
             new_gens.push(gen);
         }
         expr::DictComp(Box::new(key), Box::new(value), new_gens)
+    } else if is_instance(&ast, &tuple_type) {
+        let elts = ast.getattr(py, "elts").unwrap();
+        let elts = elts.iter(py).unwrap();
+
+        let mut new_elts = vec!();
+        for elt in elts {
+            let elt = elt.unwrap();
+            let elt = parse_expr(py, elt);
+            new_elts.push(elt);
+        }
+        expr::Tuple(new_elts, expr_context::Load)
     } else {
         println!("expr {}", ast);
         unreachable!()