# HG changeset patch # User Bastien Orivel # Date 1465838389 -7200 # Node ID efd42fc280e857a4bec75bd27c223b75aa6a5856 # Parent 1abc8ca9f30b3b81880d3a2e02aff2dbe0d600e5 Add ast.Set. diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -304,6 +304,7 @@ fn parse_expr(py: Python, ast: PyObject) let await_type = ast_module.get(py, "Await").unwrap(); let yield_type = ast_module.get(py, "Yield").unwrap(); let yield_from_type = ast_module.get(py, "YieldFrom").unwrap(); + let set_type = ast_module.get(py, "Set").unwrap(); assert!(is_instance(&ast, &ast_type)); @@ -420,6 +421,11 @@ fn parse_expr(py: Python, ast: PyObject) let value = parse_expr(py, value); expr::YieldFrom(Box::new(value)) + } else if is_instance(&ast, &set_type) { + let elts = ast.getattr(py, "elts").unwrap(); + let elements = parse_list(py, elts, parse_expr); + + expr::Set(elements) } else { println!("expr {}", ast); unreachable!() diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -194,6 +194,7 @@ impl to_string_able for expr { } }, expr::YieldFrom(value) => format!("yield from {}", value.to_string()), + expr::Set(elts) => format!("{{{}}}", vec_to_strings_vec(elts).join(", ")), } } } diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -84,7 +84,7 @@ pub enum expr { //Lambda(arguments, Box) //IfExp(Box, Box, Box) //Dict(Vec, Vec) - //Set(Vec) + Set(Vec), ListComp(Box, Vec), //SetComp(Box, Vec) DictComp(Box, Box, Vec), diff --git a/tests/test_parse_files/test_set.py b/tests/test_parse_files/test_set.py new file mode 100644 --- /dev/null +++ b/tests/test_parse_files/test_set.py @@ -0,0 +1,1 @@ +a = {1, 2, 3}