Skip to content

Commit

Permalink
add support for generating parser.c in tree-sitter grammars
Browse files Browse the repository at this point in the history
not all tree-sitter repos ship the generated file, so we may have to
generate it ourself.
  • Loading branch information
doy committed Jul 16, 2023
1 parent 79a8fd6 commit f69c673
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions helix-loader/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ fn build_tree_sitter_library(
let parser_path = src_path.join("parser.c");
let mut scanner_path = src_path.join("scanner.c");

if !parser_path.exists() {
let mut command = Command::new("tree-sitter");
command.arg("generate");
command.current_dir(src_path.parent().unwrap());
let output = command.output().context("Failed to execute tree-sitter")?;
if !output.status.success() {
return Err(anyhow!(
"tree-sitter parser generation failed.\nStdout: {}\nStderr: {}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
));
}
}

let scanner_path = if scanner_path.exists() {
Some(scanner_path)
} else {
Expand Down

0 comments on commit f69c673

Please sign in to comment.