Mercurial > python-compiler.rs
changeset 69:a73eaf42bea1
Add ast.AsyncDefFunction.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 17:54:19 +0200 |
parents | c59ad5ccd8a6 |
children | c9b9165abb9e |
files | src/ast_convert.rs src/ast_dump.rs src/python_ast.rs tests/test_parse_files/test_async_function_def.py |
diffstat | 4 files changed, 16 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -525,6 +525,7 @@ fn parse_statement(py: Python, ast: PyOb let ast_type = ast_module.get(py, "AST").unwrap(); let class_def_type = ast_module.get(py, "ClassDef").unwrap(); let function_def_type = ast_module.get(py, "FunctionDef").unwrap(); + let async_function_def_type = ast_module.get(py, "AsyncFunctionDef").unwrap(); let global_type = ast_module.get(py, "Global").unwrap(); let nonlocal_type = ast_module.get(py, "Nonlocal").unwrap(); let assign_type = ast_module.get(py, "Assign").unwrap(); @@ -575,7 +576,7 @@ fn parse_statement(py: Python, ast: PyOb let decorator_list = parse_list(py, decorator_list, parse_expr); stmt::ClassDef(name, bases, keywords, body, decorator_list) - } else if is_instance(&ast, &function_def_type) { + } else if is_instance(&ast, &function_def_type) || is_instance(&ast, &async_function_def_type) { let name = ast.getattr(py, "name").unwrap(); let args = ast.getattr(py, "args").unwrap(); let body = ast.getattr(py, "body").unwrap(); @@ -588,7 +589,7 @@ fn parse_statement(py: Python, ast: PyOb let decorator_list = parse_list(py, decorator_list, parse_expr); let returns = parse_optional_expr(py, returns); - stmt::FunctionDef(name, args, body, decorator_list, returns) + stmt::FunctionDef(name, args, body, decorator_list, returns, is_instance(&ast, &async_function_def_type)) } else if is_instance(&ast, &global_type) { let names = ast.getattr(py, "names").unwrap(); let names = parse_list(py, names, get_str);
--- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -272,9 +272,10 @@ impl stmt { statements_to_string(indent, body) ) }, - stmt::FunctionDef(name, arguments, body, decorator_list, returns) => { - format!("{}{}def {}({}){}:\n{}", + stmt::FunctionDef(name, arguments, body, decorator_list, returns, async) => { + format!("{}{}{}def {}({}){}:\n{}", decorator_list_to_string(decorator_list, indent), + if async { "async " } else { "" }, current_indent, name, arguments.to_string(),
--- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -9,10 +9,9 @@ pub struct Module { #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum stmt { // FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns) - FunctionDef(String, arguments, Vec<stmt>, Vec<expr>, Option<expr>), - // AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns) - //AsyncFunctionDef(String/*, arguments, Vec<expr>), + // If the last field is true, then it's an AsyncFunctionDef. + FunctionDef(String, arguments, Vec<stmt>, Vec<expr>, Option<expr>, bool), // ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list) ClassDef(String, Vec<expr>, Vec<keyword>, Vec<stmt>, Vec<expr>),