Mercurial > python-compiler.rs
diff src/ast_convert.rs @ 57:e5a808ec31c0
Add ast.Assert.
author | Bastien Orivel <eijebong@bananium.fr> |
---|---|
date | Sun, 12 Jun 2016 18:21:15 +0200 |
parents | c3cc16b933d2 |
children | 407b3b217928 |
line wrap: on
line diff
--- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -512,6 +512,7 @@ fn parse_statement(py: Python, ast: PyOb let delete_type = ast_module.get(py, "Delete").unwrap(); let pass_type = ast_module.get(py, "Pass").unwrap(); let continue_type = ast_module.get(py, "Continue").unwrap(); + let assert_type = ast_module.get(py, "Assert").unwrap(); assert!(is_instance(&ast, &ast_type)); @@ -653,6 +654,17 @@ fn parse_statement(py: Python, ast: PyOb stmt::Pass } else if is_instance(&ast, &continue_type) { stmt::Continue + } else if is_instance(&ast, &assert_type) { + let test = ast.getattr(py, "test").unwrap(); + let test = parse_expr(py, test); + let msg = ast.getattr(py, "msg").unwrap(); + + if msg == py.None() { + stmt::Assert(test, None) + } else { + let msg = parse_expr(py, msg); + stmt::Assert(test, Some(msg)) + } } else { println!("stmt {}", ast); panic!()