Mercurial > python-compiler.rs
changeset 75:1abc8ca9f30b
Add ast.YieldFrom.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 18:26:46 +0200 |
parents | 97537c90d92d |
children | efd42fc280e8 |
files | src/ast_convert.rs src/ast_dump.rs src/python_ast.rs tests/test_parse_files/test_yield_from.py |
diffstat | 4 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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!()
--- 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()), } } }
--- 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<expr>), Yield(Box<Option<expr>>), - //YieldFrom(expr value) + YieldFrom(Box<expr>), // need sequences for compare to distinguish between // x < 4 < 3 and (x < 4) < 3