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

Function lex_python_source

compat/src/lexer_compat.rs:123–141  ·  view source on GitHub ↗
(source: &str)

Source from the content-addressed store, hash-verified

121}
122
123pub fn lex_python_source(source: &str) -> Result<Vec<PythonToken>> {
124 let mut process = spawn_python_script_command(
125 "compat/lex_python.py",
126 vec!["--stdin", "--output-format", "json"],
127 default_python_path()?,
128 )?;
129
130 // Get process stdin and write the input string.
131 if let Some(mut stdin) = process.stdin.take() {
132 stdin.write_all(source.as_bytes()).into_diagnostic()?;
133 } else {
134 bail!("Failed to open stdin when running `compat/lex_python.py`");
135 }
136 // Get process stdout and parse result.
137 let output = process.wait_with_output().into_diagnostic()?;
138 let python_tokens: Vec<PythonToken> =
139 serde_json::from_str(String::from_utf8_lossy(&output.stdout).as_ref()).into_diagnostic()?;
140 Ok(python_tokens)
141}
142
143pub fn assert_tokens_eq(
144 python_tokens: Vec<PythonToken>,

Callers 3

run_compatibility_testFunction · 0.85
test_simple_compatFunction · 0.85

Calls 2

default_python_pathFunction · 0.85

Tested by 1

test_simple_compatFunction · 0.68