From 5aad87a74c6a0278ea3bcadc8e6180e5bb6f5c40 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Fri, 26 Apr 2024 18:49:49 +0300 Subject: [PATCH] fix(generate): don't check arbitrarily named dirs i.e. check `bindings/swift` rather than `bindings/swift/TreeSitterFoo` since the dir name may have different casing (e.g. `TreeSitterFOO`) --- cli/src/generate/grammar_files.rs | 32 +++++++++++++------------------ 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/cli/src/generate/grammar_files.rs b/cli/src/generate/grammar_files.rs index 9c2f9d4a..0ffb7321 100644 --- a/cli/src/generate/grammar_files.rs +++ b/cli/src/generate/grammar_files.rs @@ -408,26 +408,23 @@ pub fn generate_grammar_files( })?; // Generate Python bindings - missing_path( - bindings_dir - .join("python") - .join(format!("tree_sitter_{}", language_name.to_snake_case())), - create_dir, - )? - .apply(|path| { - missing_path(path.join("binding.c"), |path| { + missing_path(bindings_dir.join("python"), create_dir)?.apply(|path| { + let lang_path = path.join(format!("tree_sitter_{}", language_name.to_snake_case())); + missing_path(lang_path.clone(), create_dir)?; + + missing_path(lang_path.join("binding.c"), |path| { generate_file(path, PY_BINDING_C_TEMPLATE, language_name) })?; - missing_path(path.join("__init__.py"), |path| { + missing_path(lang_path.join("__init__.py"), |path| { generate_file(path, INIT_PY_TEMPLATE, language_name) })?; - missing_path(path.join("__init__.pyi"), |path| { + missing_path(lang_path.join("__init__.pyi"), |path| { generate_file(path, INIT_PYI_TEMPLATE, language_name) })?; - missing_path(path.join("py.typed"), |path| { + missing_path(lang_path.join("py.typed"), |path| { generate_file(path, "", language_name) // py.typed is empty })?; @@ -443,14 +440,11 @@ pub fn generate_grammar_files( })?; // Generate Swift bindings - missing_path( - bindings_dir - .join("swift") - .join(format!("TreeSitter{}", language_name.to_upper_camel_case())), - create_dir, - )? - .apply(|path| { - missing_path(path.join(format!("{language_name}.h")), |path| { + missing_path(bindings_dir.join("swift"), create_dir)?.apply(|path| { + let lang_path = path.join(format!("TreeSitter{}", language_name.to_upper_camel_case())); + missing_path(lang_path.clone(), create_dir)?; + + missing_path(lang_path.join(format!("{language_name}.h")), |path| { generate_file(path, PARSER_NAME_H_TEMPLATE, language_name) })?;