# HG changeset patch # User Bastien Orivel # Date 1465835206 -7200 # Node ID 1abc8ca9f30b3b81880d3a2e02aff2dbe0d600e5 # Parent 97537c90d92d3f6c5d7d315ad26d35587d590b88 Add ast.YieldFrom. diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -303,6 +303,7 @@ fn parse_expr(py: Python, ast: PyObject) let ellipsis_type = ast_module.get(py, "Ellipsis").unwrap(); 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(); assert!(is_instance(&ast, &ast_type)); @@ -414,6 +415,11 @@ fn parse_expr(py: Python, ast: PyObject) let value = parse_optional_expr(py, value); expr::Yield(Box::new(value)) + } else if is_instance(&ast, &yield_from_type) { + let value = ast.getattr(py, "value").unwrap(); + let value = parse_expr(py, value); + + expr::YieldFrom(Box::new(value)) } 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 @@ -193,6 +193,7 @@ impl to_string_able for expr { Some(value) => format!("yield {}", value.to_string()) } }, + expr::YieldFrom(value) => format!("yield from {}", value.to_string()), } } } diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -93,7 +93,7 @@ pub enum expr { // the grammar constrains where yield expressions can occur Await(Box), Yield(Box>), - //YieldFrom(expr value) + YieldFrom(Box), // need sequences for compare to distinguish between // x < 4 < 3 and (x < 4) < 3 diff --git a/tests/test_parse_files/test_yield_from.py b/tests/test_parse_files/test_yield_from.py new file mode 100644 --- /dev/null +++ b/tests/test_parse_files/test_yield_from.py @@ -0,0 +1,2 @@ +def a(): + yield from b()