MCPcopy Create free account
hub / github.com/Glyphack/enderpy / parse_python_source

Function parse_python_source

compat/src/parser_compat.rs:19–38  ·  view source on GitHub ↗
(source: &str)

Source from the content-addressed store, hash-verified

17use terminal_size::{terminal_size, Width as TerminalWidth};
18
19fn parse_python_source(source: &str) -> Result<Value> {
20 let mut process = spawn_python_script_command(
21 "compat/ast_python.py",
22 vec!["--stdin"],
23 default_python_path()?,
24 )?;
25
26 // Get process stdin and write the input string.
27 if let Some(mut stdin) = process.stdin.take() {
28 stdin.write_all(source.as_bytes()).into_diagnostic()?;
29 } else {
30 bail!("Failed to open stdin when running `compat/ast_python.py`");
31 }
32 // Get process stdout and parse result.
33 let output = process.wait_with_output().into_diagnostic()?;
34 let mut ast =
35 serde_json::from_str(String::from_utf8_lossy(&output.stdout).as_ref()).into_diagnostic()?;
36 remove_unimplemented_attributes(&mut ast);
37 Ok(ast)
38}
39pub fn python_parser_test_ast(inputs: &[&str]) {
40 for test_input in inputs.iter() {
41 let enderpy_ast = parse_enderpy_source(test_input).unwrap();

Callers 1

python_parser_test_astFunction · 0.85

Calls 3

default_python_pathFunction · 0.85

Tested by

no test coverage detected