From 8676eda663d43c5ab03c9d714b309c1040b749a0 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sun, 13 Jul 2025 18:01:00 +0200 Subject: [PATCH] feat: Only evaluate grammar.js to grammar.json This adds an `--evaluate-only` option to `tree-sitter generate` so that it only does the evaluation of `grammar.js` to `src/grammar.json`, without continuing on with the generation of `src/parser.c` and related files. It's a follow-up to #4580. --- crates/cli/src/main.rs | 4 ++++ crates/generate/src/generate.rs | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index 391bfe9c..60314d28 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -133,6 +133,9 @@ struct Generate { default_value = "node" )] pub js_runtime: Option, + /// Only generate `grammar.json` by evaluating `grammar.js`, but do not generate `parser.c` and related files afterwards + #[arg(long)] + pub evaluate_only: bool, } #[derive(Args)] @@ -807,6 +810,7 @@ impl Generate { abi_version, self.report_states_for_rule.as_deref(), self.js_runtime.as_deref(), + self.evaluate_only, ) { if self.json { eprintln!("{}", serde_json::to_string_pretty(&err)?); diff --git a/crates/generate/src/generate.rs b/crates/generate/src/generate.rs index babee772..586995be 100644 --- a/crates/generate/src/generate.rs +++ b/crates/generate/src/generate.rs @@ -152,6 +152,7 @@ pub fn generate_parser_in_directory( mut abi_version: usize, report_symbol_name: Option<&str>, js_runtime: Option<&str>, + generate_parser: bool, ) -> GenerateResult<()> where T: Into, @@ -196,6 +197,11 @@ where })?; } + // If our job is only to generate `grammar.json` and not `parser.c`, stop here. + if !generate_parser { + return Ok(()); + } + // Parse and preprocess the grammar. let input_grammar = parse_grammar(&grammar_json)?;