From 96485c61b17b43d5adef0c23e32cf3764cd254a9 Mon Sep 17 00:00:00 2001 From: Cole MacKenzie Date: Wed, 17 Apr 2024 16:17:59 -0700 Subject: [PATCH] chore: update tree-sitter to 0.22.5 and bump crate to 1.6.0 This commit updates the tree-sitter version to 0.22.5 and bumps the crate version to 1.6.0. All bindings were regenerated using `npm run build`. --- Cargo.toml | 4 +-- bindings/node/binding.cc | 12 +++---- bindings/node/index.js | 8 ++--- bindings/rust/README.md | 4 +-- bindings/rust/build.rs | 27 ++++++++++++++- bindings/rust/lib.rs | 34 ++++++------------ bindings/swift/capnp.h | 16 --------- package.json | 6 ++-- src/parser.c | 74 ++++++++++++++++++++-------------------- 9 files changed, 90 insertions(+), 95 deletions(-) delete mode 100644 bindings/swift/capnp.h diff --git a/Cargo.toml b/Cargo.toml index 840418b..321c175 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tree-sitter-capnp" -version = "1.5.0" +version = "1.6.0" authors = ["Amaan Qureshi "] autoexamples = false categories = ["parsing", "text-editors"] @@ -18,7 +18,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] path = "bindings/rust/lib.rs" [dependencies] -tree-sitter = "~0.20.10" +tree-sitter = "~0.22.5" [build-dependencies] cc = "~1.0" diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc index 73a7530..fa4730c 100644 --- a/bindings/node/binding.cc +++ b/bindings/node/binding.cc @@ -1,10 +1,10 @@ -#include "nan.h" #include "tree_sitter/parser.h" #include +#include "nan.h" using namespace v8; -extern "C" TSLanguage *tree_sitter_capnp(); +extern "C" TSLanguage * tree_sitter_capnp(); namespace { @@ -16,15 +16,13 @@ void Init(Local exports, Local module) { tpl->InstanceTemplate()->SetInternalFieldCount(1); Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); - Local instance = - constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); + Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); Nan::SetInternalFieldPointer(instance, 0, tree_sitter_capnp()); - Nan::Set(instance, Nan::New("name").ToLocalChecked(), - Nan::New("capnp").ToLocalChecked()); + Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("capnp").ToLocalChecked()); Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); } NODE_MODULE(tree_sitter_capnp_binding, Init) -} // namespace +} // namespace diff --git a/bindings/node/index.js b/bindings/node/index.js index 15f08fc..3daef3a 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -1,19 +1,19 @@ try { - module.exports = require('../../build/Release/tree_sitter_capnp_binding'); + module.exports = require("../../build/Release/tree_sitter_capnp_binding"); } catch (error1) { if (error1.code !== 'MODULE_NOT_FOUND') { throw error1; } try { - module.exports = require('../../build/Debug/tree_sitter_capnp_binding'); + module.exports = require("../../build/Debug/tree_sitter_capnp_binding"); } catch (error2) { if (error2.code !== 'MODULE_NOT_FOUND') { throw error2; } - throw error1; + throw error1 } } try { - module.exports.nodeTypeInfo = require('../../src/node-types.json'); + module.exports.nodeTypeInfo = require("../../src/node-types.json"); } catch (_) {} diff --git a/bindings/rust/README.md b/bindings/rust/README.md index ad9c5fc..74f538c 100644 --- a/bindings/rust/README.md +++ b/bindings/rust/README.md @@ -8,8 +8,8 @@ way.) ```toml [dependencies] -tree-sitter = "~0.20.3" -tree-sitter-capnp = "1.5.0" +tree-sitter = "~0.22.5" +tree-sitter-capnp = "1.6.0" ``` Typically, you will use the [language][language func] function to add this diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index fc83979..c6061f0 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -2,7 +2,7 @@ fn main() { let src_dir = std::path::Path::new("src"); let mut c_config = cc::Build::new(); - c_config.include(src_dir); + c_config.include(&src_dir); c_config .flag_if_supported("-Wno-unused-parameter") .flag_if_supported("-Wno-unused-but-set-variable") @@ -10,6 +10,31 @@ fn main() { let parser_path = src_dir.join("parser.c"); c_config.file(&parser_path); + // If your language uses an external scanner written in C, + // then include this block of code: + + /* + let scanner_path = src_dir.join("scanner.c"); + c_config.file(&scanner_path); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + */ + c_config.compile("parser"); println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); + + // If your language uses an external scanner written in C++, + // then include this block of code: + + /* + let mut cpp_config = cc::Build::new(); + cpp_config.cpp(true); + cpp_config.include(&src_dir); + cpp_config + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable"); + let scanner_path = src_dir.join("scanner.cc"); + cpp_config.file(&scanner_path); + cpp_config.compile("scanner"); + println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); + */ } diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 904e233..f2c871c 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,4 +1,4 @@ -//! This crate provides Cap'n Proto language support for the [tree-sitter][] parsing library. +//! This crate provides capnp language support for the [tree-sitter][] parsing library. //! //! Typically, you will use the [language][language func] function to add this language to a //! tree-sitter [Parser][], and then use the parser to parse some code: @@ -6,7 +6,7 @@ //! ``` //! let code = ""; //! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_capnp::language()).expect("Error loading Cap'n Proto grammar"); +//! parser.set_language(tree_sitter_capnp::language()).expect("Error loading capnp grammar"); //! let tree = parser.parse(code, None).unwrap(); //! ``` //! @@ -28,29 +28,17 @@ pub fn language() -> Language { unsafe { tree_sitter_capnp() } } -/// The content of the [`node-types.json`][] file for this grammar. -/// The source of the Rust tree-sitter grammar description. -pub const GRAMMAR: &str = include_str!("../../grammar.js"); - -/// The folds query for this language. -pub const FOLDS_QUERY: &str = include_str!("../../queries/folds.scm"); - -/// The syntax highlighting query for this language. -pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); - -/// The indents query for this language. -pub const INDENTS_QUERY: &str = include_str!("../../queries/indents.scm"); - -/// The injection query for this language. -pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); - -/// The symbol tagging query for this language. -pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); - /// The content of the [`node-types.json`][] file for this grammar. /// /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types -pub const NODE_TYPES: &str = include_str!("../../src/node-types.json"); +pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); + +// Uncomment these to include any queries that this grammar contains + +// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); +// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); +// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); +// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); #[cfg(test)] mod tests { @@ -59,6 +47,6 @@ mod tests { let mut parser = tree_sitter::Parser::new(); parser .set_language(super::language()) - .expect("Error loading Cap'n Proto grammar"); + .expect("Error loading capnp language"); } } diff --git a/bindings/swift/capnp.h b/bindings/swift/capnp.h deleted file mode 100644 index a68739a..0000000 --- a/bindings/swift/capnp.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef TREE_SITTER_CAPNP_H_ -#define TREE_SITTER_CAPNP_H_ - -typedef struct TSLanguage TSLanguage; - -#ifdef __cplusplus -extern "C" { -#endif - -extern TSLanguage *tree_sitter_capnp(); - -#ifdef __cplusplus -} -#endif - -#endif // TREE_SITTER_CAPNP_H_ diff --git a/package.json b/package.json index 765fdda..0457d38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter-capnp", - "version": "1.5.0", + "version": "1.6.0", "description": "Cap'n Proto grammar for tree-sitter", "main": "bindings/node", "keywords": [ @@ -16,12 +16,12 @@ }, "homepage": "https://github.com/amaanq/tree-sitter-capnp#readme", "dependencies": { - "nan": "^2.17.0" + "nan": "^2.19.0" }, "devDependencies": { "eslint": "^8.32.0", "eslint-config-google": "^0.14.0", - "tree-sitter-cli": "^0.20.7" + "tree-sitter-cli": "^0.22.5" }, "repository": "https://github.com/amaanq/tree-sitter-capnp", "scripts": { diff --git a/src/parser.c b/src/parser.c index bece884..2dc05ec 100644 --- a/src/parser.c +++ b/src/parser.c @@ -5883,7 +5883,7 @@ static const uint16_t ts_small_parse_table[] = { sym_string, STATE(190), 1, aux_sym_block_text_repeat2, - STATE(318), 1, + STATE(449), 1, sym_const_value, STATE(466), 1, aux_sym__internal_const_identifier_repeat1, @@ -6012,7 +6012,7 @@ static const uint16_t ts_small_parse_table[] = { sym_string, STATE(190), 1, aux_sym_block_text_repeat2, - STATE(367), 1, + STATE(318), 1, sym_const_value, STATE(466), 1, aux_sym__internal_const_identifier_repeat1, @@ -6098,7 +6098,7 @@ static const uint16_t ts_small_parse_table[] = { sym_string, STATE(190), 1, aux_sym_block_text_repeat2, - STATE(346), 1, + STATE(367), 1, sym_const_value, STATE(466), 1, aux_sym__internal_const_identifier_repeat1, @@ -6141,7 +6141,7 @@ static const uint16_t ts_small_parse_table[] = { sym_string, STATE(190), 1, aux_sym_block_text_repeat2, - STATE(408), 1, + STATE(346), 1, sym_const_value, STATE(466), 1, aux_sym__internal_const_identifier_repeat1, @@ -6184,7 +6184,7 @@ static const uint16_t ts_small_parse_table[] = { sym_string, STATE(190), 1, aux_sym_block_text_repeat2, - STATE(448), 1, + STATE(408), 1, sym_const_value, STATE(466), 1, aux_sym__internal_const_identifier_repeat1, @@ -6227,7 +6227,7 @@ static const uint16_t ts_small_parse_table[] = { sym_string, STATE(190), 1, aux_sym_block_text_repeat2, - STATE(449), 1, + STATE(448), 1, sym_const_value, STATE(466), 1, aux_sym__internal_const_identifier_repeat1, @@ -6318,7 +6318,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(182), 2, sym__unnamed_union, sym__named_union, - STATE(43), 3, + STATE(44), 3, sym_using_directive, sym_field, aux_sym_struct_repeat1, @@ -6373,23 +6373,23 @@ static const uint16_t ts_small_parse_table[] = { [2604] = 15, ACTIONS(3), 1, sym_comment, - ACTIONS(119), 1, + ACTIONS(99), 1, sym_identifier, - ACTIONS(122), 1, + ACTIONS(101), 1, anon_sym_using, - ACTIONS(125), 1, + ACTIONS(103), 1, anon_sym_annotation, - ACTIONS(128), 1, + ACTIONS(105), 1, anon_sym_const, - ACTIONS(131), 1, + ACTIONS(107), 1, anon_sym_enum, - ACTIONS(134), 1, + ACTIONS(109), 1, anon_sym_interface, - ACTIONS(137), 1, + ACTIONS(111), 1, anon_sym_struct, - ACTIONS(140), 1, + ACTIONS(113), 1, anon_sym_union, - ACTIONS(143), 1, + ACTIONS(117), 1, anon_sym_RBRACE, STATE(177), 1, sym_struct, @@ -6398,7 +6398,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(182), 2, sym__unnamed_union, sym__named_union, - STATE(43), 3, + STATE(44), 3, sym_using_directive, sym_field, aux_sym_struct_repeat1, @@ -6413,23 +6413,23 @@ static const uint16_t ts_small_parse_table[] = { [2659] = 15, ACTIONS(3), 1, sym_comment, - ACTIONS(99), 1, + ACTIONS(119), 1, sym_identifier, - ACTIONS(101), 1, + ACTIONS(122), 1, anon_sym_using, - ACTIONS(103), 1, + ACTIONS(125), 1, anon_sym_annotation, - ACTIONS(105), 1, + ACTIONS(128), 1, anon_sym_const, - ACTIONS(107), 1, + ACTIONS(131), 1, anon_sym_enum, - ACTIONS(109), 1, + ACTIONS(134), 1, anon_sym_interface, - ACTIONS(111), 1, + ACTIONS(137), 1, anon_sym_struct, - ACTIONS(113), 1, + ACTIONS(140), 1, anon_sym_union, - ACTIONS(115), 1, + ACTIONS(143), 1, anon_sym_RBRACE, STATE(177), 1, sym_struct, @@ -6438,7 +6438,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(182), 2, sym__unnamed_union, sym__named_union, - STATE(47), 3, + STATE(44), 3, sym_using_directive, sym_field, aux_sym_struct_repeat1, @@ -6518,7 +6518,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(182), 2, sym__unnamed_union, sym__named_union, - STATE(43), 3, + STATE(44), 3, sym_using_directive, sym_field, aux_sym_struct_repeat1, @@ -6549,7 +6549,7 @@ static const uint16_t ts_small_parse_table[] = { anon_sym_struct, ACTIONS(113), 1, anon_sym_union, - ACTIONS(117), 1, + ACTIONS(115), 1, anon_sym_RBRACE, STATE(177), 1, sym_struct, @@ -6638,7 +6638,7 @@ static const uint16_t ts_small_parse_table[] = { STATE(182), 2, sym__unnamed_union, sym__named_union, - STATE(43), 3, + STATE(44), 3, sym_using_directive, sym_field, aux_sym_struct_repeat1, @@ -13391,7 +13391,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [657] = {.entry = {.count = 1, .reusable = true}}, SHIFT(505), [659] = {.entry = {.count = 1, .reusable = true}}, SHIFT(127), [661] = {.entry = {.count = 1, .reusable = true}}, SHIFT(501), - [663] = {.entry = {.count = 1, .reusable = true}}, SHIFT(36), + [663] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), [665] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym__internal_const_identifier, 2), [667] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_annotation_repeat1, 9, .production_id = 25), [669] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_const_list, 4), @@ -13444,7 +13444,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [767] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_type, 1), [769] = {.entry = {.count = 1, .reusable = true}}, SHIFT(363), [771] = {.entry = {.count = 1, .reusable = true}}, SHIFT(362), - [773] = {.entry = {.count = 1, .reusable = true}}, SHIFT(39), + [773] = {.entry = {.count = 1, .reusable = true}}, SHIFT(31), [775] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_named_return_type_repeat1, 4, .production_id = 34), [777] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_method, 6), [779] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_method, 6), @@ -13492,7 +13492,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [863] = {.entry = {.count = 1, .reusable = true}}, SHIFT(248), [865] = {.entry = {.count = 1, .reusable = true}}, SHIFT(265), [867] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym__annotation_array_def_repeat2, 2), - [869] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__annotation_array_def_repeat2, 2), SHIFT_REPEAT(34), + [869] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym__annotation_array_def_repeat2, 2), SHIFT_REPEAT(36), [872] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_return_type, 1), [874] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_generic_parameters, 2, .production_id = 7), [876] = {.entry = {.count = 1, .reusable = true}}, SHIFT(65), @@ -13516,7 +13516,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [914] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_generic_parameters_repeat1, 2), SHIFT_REPEAT(65), [917] = {.entry = {.count = 1, .reusable = true}}, SHIFT(359), [919] = {.entry = {.count = 1, .reusable = true}}, SHIFT(26), - [921] = {.entry = {.count = 1, .reusable = true}}, SHIFT(31), + [921] = {.entry = {.count = 1, .reusable = true}}, SHIFT(34), [923] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_named_return_type, 4, .production_id = 32), [925] = {.entry = {.count = 1, .reusable = true}}, SHIFT(73), [927] = {.entry = {.count = 1, .reusable = true}}, SHIFT(423), @@ -13548,7 +13548,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [980] = {.entry = {.count = 1, .reusable = true}}, SHIFT(20), [982] = {.entry = {.count = 1, .reusable = true}}, SHIFT(214), [984] = {.entry = {.count = 1, .reusable = true}}, SHIFT(249), - [986] = {.entry = {.count = 1, .reusable = true}}, SHIFT(38), + [986] = {.entry = {.count = 1, .reusable = true}}, SHIFT(39), [988] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_named_return_type_repeat1, 5, .production_id = 34), [990] = {.entry = {.count = 1, .reusable = true}}, SHIFT(120), [992] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_named_return_type, 7, .production_id = 32), @@ -13640,7 +13640,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [1168] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_parameters_repeat1, 2), [1170] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_parameters_repeat1, 2), SHIFT_REPEAT(462), [1173] = {.entry = {.count = 1, .reusable = true}}, SHIFT(245), - [1175] = {.entry = {.count = 1, .reusable = true}}, SHIFT(44), + [1175] = {.entry = {.count = 1, .reusable = true}}, SHIFT(47), [1177] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42), [1179] = {.entry = {.count = 1, .reusable = true}}, SHIFT(258), [1181] = {.entry = {.count = 1, .reusable = true}}, SHIFT(134), @@ -13702,7 +13702,7 @@ static const TSParseActionEntry ts_parse_actions[] = { [1295] = {.entry = {.count = 1, .reusable = true}}, SHIFT(68), [1297] = {.entry = {.count = 1, .reusable = true}}, SHIFT(144), [1299] = {.entry = {.count = 1, .reusable = true}}, SHIFT(219), - [1301] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), + [1301] = {.entry = {.count = 1, .reusable = true}}, SHIFT(38), [1303] = {.entry = {.count = 1, .reusable = true}}, SHIFT(204), [1305] = {.entry = {.count = 1, .reusable = true}}, SHIFT(544), [1307] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_top_level_annotation_body, 3),