Mercurial > python-compiler.rs
diff 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 |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -528,6 +528,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 raise_type = ast_module.get(py, "Raise").unwrap(); assert!(is_instance(&ast, &ast_type)); @@ -687,6 +688,21 @@ fn parse_statement(py: Python, ast: PyOb let items = parse_list(py, items, parse_withitem); let body = parse_list(py, body, parse_statement); stmt::With(items, body) + } else if is_instance(&ast, &raise_type) { + let exc = ast.getattr(py, "exc").unwrap(); + let cause = ast.getattr(py, "cause").unwrap(); + let mut exc_ = None; + let mut cause_ = None; + + if exc != py.None() { + exc_ = Some(parse_expr(py, exc)); + } + + if cause != py.None() { + cause_ = Some(parse_expr(py, cause)); + } + + stmt::Raise(exc_, cause_) } else { println!("stmt {}", ast); panic!()