Mercurial > python-compiler.rs
changeset 72:7ac23f4336b1
Add ast.AsyncWith.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 18:09:15 +0200 |
parents | 2c1e2ce41263 |
children | 2a6629ea82b5 |
files | src/ast_convert.rs src/ast_dump.rs src/python_ast.rs tests/test_parse_files/test_async_with.py |
diffstat | 4 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -544,6 +544,7 @@ fn parse_statement(py: Python, ast: PyOb let continue_type = ast_module.get(py, "Continue").unwrap(); let assert_type = ast_module.get(py, "Assert").unwrap(); let with_type = ast_module.get(py, "With").unwrap(); + let async_with_type = ast_module.get(py, "AsyncWith").unwrap(); let raise_type = ast_module.get(py, "Raise").unwrap(); let try_type = ast_module.get(py, "Try").unwrap(); @@ -695,13 +696,13 @@ fn parse_statement(py: Python, ast: PyOb let msg = parse_optional_expr(py, msg); stmt::Assert(test, msg) - } else if is_instance(&ast, &with_type) { + } else if is_instance(&ast, &with_type) || is_instance(&ast, &async_with_type) { let items = ast.getattr(py, "items").unwrap(); let body = ast.getattr(py, "body").unwrap(); let items = parse_list(py, items, parse_withitem); let body = parse_list(py, body, parse_statement); - stmt::With(items, body) + stmt::With(items, body, is_instance(&ast, &async_with_type)) } else if is_instance(&ast, &raise_type) { let exc = ast.getattr(py, "exc").unwrap(); let cause = ast.getattr(py, "cause").unwrap();
--- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -354,9 +354,10 @@ impl stmt { } ) }, - stmt::With(items, body) => { - format!("{}with {}:\n{}", + stmt::With(items, body, async) => { + format!("{}{}with {}:\n{}", current_indent, + if async { "async " } else { "" }, vec_to_strings_vec(items).join(", "), statements_to_string(indent, body) )
--- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -40,9 +40,10 @@ pub enum stmt { If(expr, Vec<stmt>, Vec<stmt>), // With(withitem* items, stmt* body) - With(Vec<withitem>, Vec<stmt>), + // AsyncWith(withitem* items, stmt* body) + // If the last field is true, then it's an AsyncWith. + With(Vec<withitem>, Vec<stmt>, bool), - // AsyncWith(withitem* items, stmt* body) //AsyncWith(Vec<withitem>, Vec<stmt>) // Raise(expr? exc, expr? cause)