Skip to content

Commit

Permalink
Add script to run parser on file
Browse files Browse the repository at this point in the history
  • Loading branch information
bbannier committed Dec 30, 2023
1 parent e31b68b commit e601b70
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"scripts": {
"install": "bash -c '(cd tree-sitter-spicy && tree-sitter generate && TREE_SITTER_LIBDIR=../lib tree-sitter test >/dev/null)'",
"test": "sg test"
"test": "sg test",
"parse": "node parse.js"
}
}
22 changes: 22 additions & 0 deletions parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const path = require("node:path");
const { spawn } = require("child_process");

if (process.argv.length === 2) {
console.error("Expected at least one argument!");
process.exit(1);
}

// Since we will cd into the tree-sitter parser directory make the passed path absolute.
const file = path.resolve(process.argv[2]);
process.chdir("./tree-sitter-spicy");

const parse = spawn("tree-sitter", ["parse", file]);
parse.stdout.on("data", (data) => {
console.log(`${data}`);
});
parse.stderr.on("data", (data) => {
console.log(`stderr: ${data}`);
});
parse.on("error", (error) => {
console.log(`error: ${error.message}`);
});

0 comments on commit e601b70

Please sign in to comment.