Avoid using a string literal to pass grammar path to JS
Backslashes in windows path were getting interpeted as escape characters.
This commit is contained in:
parent
d903371709
commit
d52a11fd03
2 changed files with 6 additions and 8 deletions
|
|
@ -327,3 +327,6 @@ global.seq = seq;
|
|||
global.sym = sym;
|
||||
global.token = token;
|
||||
global.grammar = grammar;
|
||||
|
||||
const result = require(process.env.TREE_SITTER_GRAMMAR_PATH);
|
||||
console.log(JSON.stringify(result, null, 2));
|
||||
|
|
|
|||
|
|
@ -104,23 +104,18 @@ fn load_grammar_file(grammar_path: &PathBuf) -> String {
|
|||
|
||||
fn load_js_grammar_file(grammar_path: &PathBuf) -> String {
|
||||
let mut node_process = Command::new("node")
|
||||
.env("TREE_SITTER_GRAMMAR_PATH", grammar_path)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.spawn()
|
||||
.expect("Failed to run `node`");
|
||||
|
||||
let js_prelude = include_str!("./dsl.js");
|
||||
let mut node_stdin = node_process
|
||||
.stdin
|
||||
.take()
|
||||
.expect("Failed to open stdin for node");
|
||||
write!(
|
||||
node_stdin,
|
||||
"{}\nconsole.log(JSON.stringify(require(\"{}\"), null, 2));\n",
|
||||
js_prelude,
|
||||
grammar_path.to_str().unwrap()
|
||||
)
|
||||
.expect("Failed to write to node's stdin");
|
||||
let javascript_code = include_bytes!("./dsl.js");
|
||||
node_stdin.write(javascript_code).expect("Failed to write to node's stdin");
|
||||
drop(node_stdin);
|
||||
let output = node_process
|
||||
.wait_with_output()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue