Mercurial > python-compiler.rs
comparison src/ast_convert.rs @ 69:a73eaf42bea1
Add ast.AsyncDefFunction.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 17:54:19 +0200 |
parents | c59ad5ccd8a6 |
children | 2c1e2ce41263 |
comparison
equal
deleted
inserted
replaced
68:c59ad5ccd8a6 | 69:a73eaf42bea1 |
---|---|
523 | 523 |
524 let ast_module = py.import("ast").unwrap(); | 524 let ast_module = py.import("ast").unwrap(); |
525 let ast_type = ast_module.get(py, "AST").unwrap(); | 525 let ast_type = ast_module.get(py, "AST").unwrap(); |
526 let class_def_type = ast_module.get(py, "ClassDef").unwrap(); | 526 let class_def_type = ast_module.get(py, "ClassDef").unwrap(); |
527 let function_def_type = ast_module.get(py, "FunctionDef").unwrap(); | 527 let function_def_type = ast_module.get(py, "FunctionDef").unwrap(); |
528 let async_function_def_type = ast_module.get(py, "AsyncFunctionDef").unwrap(); | |
528 let global_type = ast_module.get(py, "Global").unwrap(); | 529 let global_type = ast_module.get(py, "Global").unwrap(); |
529 let nonlocal_type = ast_module.get(py, "Nonlocal").unwrap(); | 530 let nonlocal_type = ast_module.get(py, "Nonlocal").unwrap(); |
530 let assign_type = ast_module.get(py, "Assign").unwrap(); | 531 let assign_type = ast_module.get(py, "Assign").unwrap(); |
531 let aug_assign_type = ast_module.get(py, "AugAssign").unwrap(); | 532 let aug_assign_type = ast_module.get(py, "AugAssign").unwrap(); |
532 let return_type = ast_module.get(py, "Return").unwrap(); | 533 let return_type = ast_module.get(py, "Return").unwrap(); |
573 let keywords = parse_list(py, keywords, parse_keyword); | 574 let keywords = parse_list(py, keywords, parse_keyword); |
574 let body = parse_list(py, body, parse_statement); | 575 let body = parse_list(py, body, parse_statement); |
575 let decorator_list = parse_list(py, decorator_list, parse_expr); | 576 let decorator_list = parse_list(py, decorator_list, parse_expr); |
576 | 577 |
577 stmt::ClassDef(name, bases, keywords, body, decorator_list) | 578 stmt::ClassDef(name, bases, keywords, body, decorator_list) |
578 } else if is_instance(&ast, &function_def_type) { | 579 } else if is_instance(&ast, &function_def_type) || is_instance(&ast, &async_function_def_type) { |
579 let name = ast.getattr(py, "name").unwrap(); | 580 let name = ast.getattr(py, "name").unwrap(); |
580 let args = ast.getattr(py, "args").unwrap(); | 581 let args = ast.getattr(py, "args").unwrap(); |
581 let body = ast.getattr(py, "body").unwrap(); | 582 let body = ast.getattr(py, "body").unwrap(); |
582 let decorator_list = ast.getattr(py, "decorator_list").unwrap(); | 583 let decorator_list = ast.getattr(py, "decorator_list").unwrap(); |
583 let returns = ast.getattr(py, "returns").unwrap(); | 584 let returns = ast.getattr(py, "returns").unwrap(); |
586 let args = parse_arguments(py, args); | 587 let args = parse_arguments(py, args); |
587 let body = parse_list(py, body, parse_statement); | 588 let body = parse_list(py, body, parse_statement); |
588 let decorator_list = parse_list(py, decorator_list, parse_expr); | 589 let decorator_list = parse_list(py, decorator_list, parse_expr); |
589 let returns = parse_optional_expr(py, returns); | 590 let returns = parse_optional_expr(py, returns); |
590 | 591 |
591 stmt::FunctionDef(name, args, body, decorator_list, returns) | 592 stmt::FunctionDef(name, args, body, decorator_list, returns, is_instance(&ast, &async_function_def_type)) |
592 } else if is_instance(&ast, &global_type) { | 593 } else if is_instance(&ast, &global_type) { |
593 let names = ast.getattr(py, "names").unwrap(); | 594 let names = ast.getattr(py, "names").unwrap(); |
594 let names = parse_list(py, names, get_str); | 595 let names = parse_list(py, names, get_str); |
595 stmt::Global(names) | 596 stmt::Global(names) |
596 } else if is_instance(&ast, &nonlocal_type) { | 597 } else if is_instance(&ast, &nonlocal_type) { |