diff --git a/cli/generate/src/lib.rs b/cli/generate/src/lib.rs index f1196827..56b2cdc6 100644 --- a/cli/generate/src/lib.rs +++ b/cli/generate/src/lib.rs @@ -33,6 +33,7 @@ pub use parse_grammar::ParseGrammarError; use prepare_grammar::prepare_grammar; pub use prepare_grammar::PrepareGrammarError; use render::render_c_code; +pub use render::{ABI_VERSION_MAX, ABI_VERSION_MIN}; static JSON_COMMENT_REGEX: LazyLock = LazyLock::new(|| { RegexBuilder::new("^\\s*//.*") @@ -147,7 +148,7 @@ pub fn generate_parser_in_directory( repo_path: &Path, out_path: Option<&str>, grammar_path: Option<&str>, - abi_version: usize, + mut abi_version: usize, report_symbol_name: Option<&str>, js_runtime: Option<&str>, ) -> GenerateResult<()> { @@ -192,6 +193,12 @@ pub fn generate_parser_in_directory( let semantic_version = read_grammar_version(&repo_path)?; + if semantic_version.is_none() && abi_version > ABI_VERSION_MIN { + println!("Warning: No `tree-sitter.json` file found in your grammar, this file is required to generate with ABI {abi_version}. Using ABI version {ABI_VERSION_MIN} instead."); + println!("This file can be set up with `tree-sitter init`. For more information, see https://tree-sitter.github.io/tree-sitter/cli/init."); + abi_version = ABI_VERSION_MIN; + } + // Generate the parser and related files. let GeneratedParser { c_code, diff --git a/cli/generate/src/render.rs b/cli/generate/src/render.rs index e2ef2389..dc8f0825 100644 --- a/cli/generate/src/render.rs +++ b/cli/generate/src/render.rs @@ -20,8 +20,8 @@ use super::{ }; const SMALL_STATE_THRESHOLD: usize = 64; -const ABI_VERSION_MIN: usize = 14; -const ABI_VERSION_MAX: usize = tree_sitter::LANGUAGE_VERSION; +pub const ABI_VERSION_MIN: usize = 14; +pub const ABI_VERSION_MAX: usize = tree_sitter::LANGUAGE_VERSION; const ABI_VERSION_WITH_RESERVED_WORDS: usize = 15; const BUILD_VERSION: &str = env!("CARGO_PKG_VERSION"); const BUILD_SHA: Option<&'static str> = option_env!("BUILD_SHA");