diff src/ast_convert.rs @ 7:680d15073f55

Add ast.List literal.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 31 May 2016 04:26:58 +0100
parents 6f2bf13f4cb5
children 94ff501bf336
line wrap: on
line diff
--- a/src/ast_convert.rs
+++ b/src/ast_convert.rs
@@ -119,6 +119,7 @@ fn parse_expr(py: Python, ast: PyObject)
     let name_type = ast_module.get(py, "Name").unwrap();
     let num_type = ast_module.get(py, "Num").unwrap();
     let str_type = ast_module.get(py, "Str").unwrap();
+    let list_type = ast_module.get(py, "List").unwrap();
     let compare_type = ast_module.get(py, "Compare").unwrap();
     let call_type = ast_module.get(py, "Call").unwrap();
     let alias_type = ast_module.get(py, "alias").unwrap();
@@ -153,6 +154,16 @@ fn parse_expr(py: Python, ast: PyObject)
         let s = ast.getattr(py, "s").unwrap();
         let s = get_str(py, s);
         Expr::Str(s)
+    } else if is_instance(&ast, &list_type) {
+        let elts = ast.getattr(py, "elts").unwrap();
+
+        let mut elements = vec!();
+        for elt in elts.iter(py).unwrap() {
+            let elt = elt.unwrap();
+            elements.push(parse_expr(py, elt));
+        }
+
+        Expr::List(elements)
     } else if is_instance(&ast, &unary_op_type) {
         let op = ast.getattr(py, "op").unwrap();
         let operand = ast.getattr(py, "operand").unwrap();