From d52a11fd03a7d348275422990fb4ab8fc23ca2fa Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Thu, 17 Jan 2019 10:09:03 -0800 Subject: [PATCH] Avoid using a string literal to pass grammar path to JS Backslashes in windows path were getting interpeted as escape characters. --- cli/src/generate/dsl.js | 3 +++ cli/src/generate/mod.rs | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cli/src/generate/dsl.js b/cli/src/generate/dsl.js index fa60dfa7..950b2d3b 100644 --- a/cli/src/generate/dsl.js +++ b/cli/src/generate/dsl.js @@ -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)); diff --git a/cli/src/generate/mod.rs b/cli/src/generate/mod.rs index f42dff96..baaeb182 100644 --- a/cli/src/generate/mod.rs +++ b/cli/src/generate/mod.rs @@ -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()