Mercurial > python-compiler.rs
changeset 64:53817b39f139
Add FunctionDef.decorator_list support.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Mon, 13 Jun 2016 01:18:48 +0100 |
parents | 5df52b40fe54 |
children | ce5e27a3f277 |
files | src/ast_convert.rs src/ast_dump.rs tests/test_parse_files/test_functiondef_decorators.py |
diffstat | 3 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -564,16 +564,16 @@ fn parse_statement(py: Python, ast: PyOb let name = ast.getattr(py, "name").unwrap(); let args = ast.getattr(py, "args").unwrap(); let body = ast.getattr(py, "body").unwrap(); + let decorator_list = ast.getattr(py, "decorator_list").unwrap(); let returns = ast.getattr(py, "returns").unwrap(); let name = get_str(py, name); let args = parse_arguments(py, args); let body = parse_list(py, body, parse_statement); - - let decorators = vec!(); + let decorator_list = parse_list(py, decorator_list, parse_expr); let returns = parse_optional_expr(py, returns); - stmt::FunctionDef(name, args, body, decorators, returns) + stmt::FunctionDef(name, args, body, decorator_list, returns) } 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 @@ -227,7 +227,15 @@ impl stmt { match self.clone() { stmt::ClassDef(name, bases, keywords, body, decorator_list) => format!("{}class {}({}):\n{}", current_indent, name, vec_to_strings_vec(bases).join(", "), statements_to_string(indent, body)), stmt::FunctionDef(name, arguments, body, decorator_list, returns) => { - format!("{}def {}({}){}:\n{}", + format!("{}{}def {}({}){}:\n{}", + { + let decorators = vec_to_strings_vec(decorator_list); + if decorators.is_empty() { + String::new() + } else { + format!("{}@{}\n", current_indent, decorators.join(format!("\n{}@", current_indent).as_str())) + } + }, current_indent, name, arguments.to_string(),