# HG changeset patch # User Emmanuel Gil Peyrot # Date 1464665218 -3600 # Node ID 680d15073f550f3c7066ec21c1779db83e7be3bb # Parent 6f2bf13f4cb5f7a7687c2a0f9639077ebaf27bb9 Add ast.List literal. diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- 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(); diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -70,6 +70,13 @@ impl Expr { Expr::NameConstant(name) => format!("{}", name), Expr::Str(s) => format!("\"{}\"", s), Expr::Num(n) => format!("{}", n), + Expr::List(elts) => format!("[{}]", { + let mut elements = vec!(); + for elt in elts { + elements.push(elt.to_string()); + } + elements.join(", ") + }), Expr::Error => "Expr::Error".to_string() } } diff --git a/src/ast_type.rs b/src/ast_type.rs --- a/src/ast_type.rs +++ b/src/ast_type.rs @@ -9,6 +9,7 @@ enum Type { Bool, Int, Str, + List(Box), Function(Vec, Vec), Bottom } @@ -236,6 +237,7 @@ impl Visitor for Typing { }, Expr::Str(_) => Type::Str, Expr::Num(_) => Type::Int, + Expr::List(_) => Type::List(Box::new(Type::Bottom)), Expr::Error => { println!("Expr::Error"); panic!() diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -32,6 +32,7 @@ pub enum Expr { NameConstant(String), Str(String), Num(String), + List(Vec), Error }