Mercurial > python-compiler.rs
diff 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 |
line wrap: on
line diff
new file mode 100644 --- /dev/null +++ b/src/python_parse.rs @@ -0,0 +1,15 @@ +extern crate cpython; + +use cpython::{Python, PyObject, PyErr}; +use cpython::ObjectProtocol; //for call method + +pub fn parse_ast(code: String) -> Result<PyObject, PyErr> { + let gil = Python::acquire_gil(); + let py = gil.python(); + + let ast_module = py.import("ast").unwrap(); + let ast_parse = ast_module.get(py, "parse").unwrap(); + + let real_ast = try!(ast_parse.call(py, (code,), None)); + Ok(real_ast) +}