feat(generate): defer to ABI 14 if tree-sitter.json doesn't exist, rather than hard failing
This commit is contained in:
parent
016dd7afbf
commit
959f096a89
2 changed files with 10 additions and 3 deletions
|
|
@ -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<Regex> = 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,
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue