Mercurial > python-compiler.rs
comparison src/ast_convert.rs @ 60:9f0f457a67f6
Add ast.Raise.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Mon, 13 Jun 2016 01:24:09 +0200 |
parents | 407b3b217928 |
children | 6b73843c5b4a |
comparison
equal
deleted
inserted
replaced
59:407b3b217928 | 60:9f0f457a67f6 |
---|---|
526 let delete_type = ast_module.get(py, "Delete").unwrap(); | 526 let delete_type = ast_module.get(py, "Delete").unwrap(); |
527 let pass_type = ast_module.get(py, "Pass").unwrap(); | 527 let pass_type = ast_module.get(py, "Pass").unwrap(); |
528 let continue_type = ast_module.get(py, "Continue").unwrap(); | 528 let continue_type = ast_module.get(py, "Continue").unwrap(); |
529 let assert_type = ast_module.get(py, "Assert").unwrap(); | 529 let assert_type = ast_module.get(py, "Assert").unwrap(); |
530 let with_type = ast_module.get(py, "With").unwrap(); | 530 let with_type = ast_module.get(py, "With").unwrap(); |
531 let raise_type = ast_module.get(py, "Raise").unwrap(); | |
531 | 532 |
532 assert!(is_instance(&ast, &ast_type)); | 533 assert!(is_instance(&ast, &ast_type)); |
533 | 534 |
534 /* | 535 /* |
535 // TODO: implement Hash for PyObject. (trivial) | 536 // TODO: implement Hash for PyObject. (trivial) |
685 let body = ast.getattr(py, "body").unwrap(); | 686 let body = ast.getattr(py, "body").unwrap(); |
686 | 687 |
687 let items = parse_list(py, items, parse_withitem); | 688 let items = parse_list(py, items, parse_withitem); |
688 let body = parse_list(py, body, parse_statement); | 689 let body = parse_list(py, body, parse_statement); |
689 stmt::With(items, body) | 690 stmt::With(items, body) |
691 } else if is_instance(&ast, &raise_type) { | |
692 let exc = ast.getattr(py, "exc").unwrap(); | |
693 let cause = ast.getattr(py, "cause").unwrap(); | |
694 let mut exc_ = None; | |
695 let mut cause_ = None; | |
696 | |
697 if exc != py.None() { | |
698 exc_ = Some(parse_expr(py, exc)); | |
699 } | |
700 | |
701 if cause != py.None() { | |
702 cause_ = Some(parse_expr(py, cause)); | |
703 } | |
704 | |
705 stmt::Raise(exc_, cause_) | |
690 } else { | 706 } else { |
691 println!("stmt {}", ast); | 707 println!("stmt {}", ast); |
692 panic!() | 708 panic!() |
693 } | 709 } |
694 } | 710 } |