Mercurial > python-compiler.rs
comparison 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 |
comparison
equal
deleted
inserted
replaced
56:c3cc16b933d2 | 57:e5a808ec31c0 |
---|---|
510 let expr_type = ast_module.get(py, "Expr").unwrap(); | 510 let expr_type = ast_module.get(py, "Expr").unwrap(); |
511 let break_type = ast_module.get(py, "Break").unwrap(); | 511 let break_type = ast_module.get(py, "Break").unwrap(); |
512 let delete_type = ast_module.get(py, "Delete").unwrap(); | 512 let delete_type = ast_module.get(py, "Delete").unwrap(); |
513 let pass_type = ast_module.get(py, "Pass").unwrap(); | 513 let pass_type = ast_module.get(py, "Pass").unwrap(); |
514 let continue_type = ast_module.get(py, "Continue").unwrap(); | 514 let continue_type = ast_module.get(py, "Continue").unwrap(); |
515 let assert_type = ast_module.get(py, "Assert").unwrap(); | |
515 | 516 |
516 assert!(is_instance(&ast, &ast_type)); | 517 assert!(is_instance(&ast, &ast_type)); |
517 | 518 |
518 /* | 519 /* |
519 // TODO: implement Hash for PyObject. (trivial) | 520 // TODO: implement Hash for PyObject. (trivial) |
651 stmt::Delete(targets) | 652 stmt::Delete(targets) |
652 } else if is_instance(&ast, &pass_type) { | 653 } else if is_instance(&ast, &pass_type) { |
653 stmt::Pass | 654 stmt::Pass |
654 } else if is_instance(&ast, &continue_type) { | 655 } else if is_instance(&ast, &continue_type) { |
655 stmt::Continue | 656 stmt::Continue |
657 } else if is_instance(&ast, &assert_type) { | |
658 let test = ast.getattr(py, "test").unwrap(); | |
659 let test = parse_expr(py, test); | |
660 let msg = ast.getattr(py, "msg").unwrap(); | |
661 | |
662 if msg == py.None() { | |
663 stmt::Assert(test, None) | |
664 } else { | |
665 let msg = parse_expr(py, msg); | |
666 stmt::Assert(test, Some(msg)) | |
667 } | |
656 } else { | 668 } else { |
657 println!("stmt {}", ast); | 669 println!("stmt {}", ast); |
658 panic!() | 670 panic!() |
659 } | 671 } |
660 } | 672 } |