comparison src/python_parse.rs @ 0:211b0df72e64

Hello world!
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 29 May 2016 19:15:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:211b0df72e64
1 extern crate cpython;
2
3 use cpython::{Python, PyObject, PyErr};
4 use cpython::ObjectProtocol; //for call method
5
6 pub fn parse_ast(code: String) -> Result<PyObject, PyErr> {
7 let gil = Python::acquire_gil();
8 let py = gil.python();
9
10 let ast_module = py.import("ast").unwrap();
11 let ast_parse = ast_module.get(py, "parse").unwrap();
12
13 let real_ast = try!(ast_parse.call(py, (code,), None));
14 Ok(real_ast)
15 }