nac3embedded: parse
This commit is contained in:
parent
b79d8ad640
commit
aa8b4e2305
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -460,6 +460,7 @@ name = "nac3embedded"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"pyo3",
|
||||
"rustpython-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -8,6 +8,6 @@ edition = "2018"
|
||||
name = "nac3embedded"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies.pyo3]
|
||||
version = "0.12.4"
|
||||
features = ["extension-module"]
|
||||
[dependencies]
|
||||
pyo3 = { version = "0.12.4", features = ["extension-module"] }
|
||||
rustpython-parser = { git = "https://github.com/RustPython/RustPython", branch = "master" }
|
||||
|
@ -1,5 +1,7 @@
|
||||
use pyo3::prelude::*;
|
||||
use pyo3::wrap_pyfunction;
|
||||
use pyo3::exceptions;
|
||||
use rustpython_parser::parser;
|
||||
|
||||
#[pyfunction]
|
||||
fn add_host_object(obj: PyObject) -> PyResult<()> {
|
||||
@ -7,7 +9,9 @@ fn add_host_object(obj: PyObject) -> PyResult<()> {
|
||||
let obj: &PyAny = obj.extract(py)?;
|
||||
let inspect = PyModule::import(py, "inspect")?;
|
||||
let source = inspect.call1("getsource", (obj.get_type(), ))?;
|
||||
println!("source:\n{}", source);
|
||||
let ast = parser::parse_program(source.extract()?).map_err(|e|
|
||||
exceptions::PySyntaxError::new_err(format!("failed to parse host object source: {}", e)))?;
|
||||
println!("{:?}", ast);
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(())
|
||||
@ -16,6 +20,5 @@ fn add_host_object(obj: PyObject) -> PyResult<()> {
|
||||
#[pymodule]
|
||||
fn nac3embedded(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_function(wrap_pyfunction!(add_host_object, m)?)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user