From 4abcc84b0b14cca949770aa3854280b5df71eabe Mon Sep 17 00:00:00 2001 From: mohammadkhan Date: Tue, 26 Aug 2025 22:48:08 +0530 Subject: [PATCH 1/2] feat: update tree-sitter cli and generate binding with 0.25 --- .gitignore | 2 ++ src/grammar.json | 5 +++-- src/node-types.json | 3 ++- src/parser.c | 26 +++++++++++++++++++------- src/tree_sitter/array.h | 3 ++- src/tree_sitter/parser.h | 34 +++++++++++++++++++++++++++------- 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 308fcab..42ccdd8 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ dist/ *.tar.gz *.tgz *.zip + +.DS_Store diff --git a/src/grammar.json b/src/grammar.json index bb6e8fe..3165888 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -2288,5 +2288,6 @@ "precedences": [], "externals": [], "inline": [], - "supertypes": [] -} + "supertypes": [], + "reserved": {} +} \ No newline at end of file diff --git a/src/node-types.json b/src/node-types.json index 2c586e9..f0e8efb 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -913,7 +913,8 @@ }, { "type": "comment", - "named": true + "named": true, + "extra": true }, { "type": "decimal_lit", diff --git a/src/parser.c b/src/parser.c index b380f05..c04aa3b 100644 --- a/src/parser.c +++ b/src/parser.c @@ -1,3 +1,5 @@ +/* Automatically @generated by tree-sitter v0.25.8 */ + #include "tree_sitter/parser.h" #if defined(__GNUC__) || defined(__clang__) @@ -12,7 +14,7 @@ #pragma GCC optimize ("O0") #endif -#define LANGUAGE_VERSION 14 +#define LANGUAGE_VERSION 15 #define STATE_COUNT 321 #define LARGE_STATE_COUNT 2 #define SYMBOL_COUNT 129 @@ -21,7 +23,9 @@ #define EXTERNAL_TOKEN_COUNT 0 #define FIELD_COUNT 2 #define MAX_ALIAS_SEQUENCE_LENGTH 14 +#define MAX_RESERVED_WORD_SET_SIZE 0 #define PRODUCTION_ID_COUNT 4 +#define SUPERTYPE_COUNT 0 enum ts_symbol_identifiers { anon_sym_SEMI = 1, @@ -948,7 +952,7 @@ static const char * const ts_field_names[] = { [field_year] = "year", }; -static const TSFieldMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { +static const TSMapSlice ts_field_map_slices[PRODUCTION_ID_COUNT] = { [1] = {.index = 0, .length = 1}, [2] = {.index = 1, .length = 1}, [3] = {.index = 2, .length = 1}, @@ -3771,7 +3775,7 @@ static bool ts_lex(TSLexer *lexer, TSStateId state) { } } -static const TSLexMode ts_lex_modes[STATE_COUNT] = { +static const TSLexerMode ts_lex_modes[STATE_COUNT] = { [0] = {.lex_state = 0}, [1] = {.lex_state = 200}, [2] = {.lex_state = 15}, @@ -4096,7 +4100,7 @@ static const TSLexMode ts_lex_modes[STATE_COUNT] = { }; static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { - [0] = { + [STATE(0)] = { [ts_builtin_sym_end] = ACTIONS(1), [anon_sym_SEMI] = ACTIONS(1), [anon_sym_edition] = ACTIONS(1), @@ -4162,7 +4166,7 @@ static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { [sym_escape_sequence] = ACTIONS(1), [sym_comment] = ACTIONS(3), }, - [1] = { + [STATE(1)] = { [sym_source_file] = STATE(289), [sym_empty_statement] = STATE(58), [sym_edition] = STATE(59), @@ -9350,7 +9354,7 @@ extern "C" { TS_PUBLIC const TSLanguage *tree_sitter_proto(void) { static const TSLanguage language = { - .version = LANGUAGE_VERSION, + .abi_version = LANGUAGE_VERSION, .symbol_count = SYMBOL_COUNT, .alias_count = ALIAS_COUNT, .token_count = TOKEN_COUNT, @@ -9358,6 +9362,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_proto(void) { .state_count = STATE_COUNT, .large_state_count = LARGE_STATE_COUNT, .production_id_count = PRODUCTION_ID_COUNT, + .supertype_count = SUPERTYPE_COUNT, .field_count = FIELD_COUNT, .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, .parse_table = &ts_parse_table[0][0], @@ -9372,9 +9377,16 @@ TS_PUBLIC const TSLanguage *tree_sitter_proto(void) { .public_symbol_map = ts_symbol_map, .alias_map = ts_non_terminal_alias_map, .alias_sequences = &ts_alias_sequences[0][0], - .lex_modes = ts_lex_modes, + .lex_modes = (const void*)ts_lex_modes, .lex_fn = ts_lex, .primary_state_ids = ts_primary_state_ids, + .name = "proto", + .max_reserved_word_set_size = 0, + .metadata = { + .major_version = 0, + .minor_version = 2, + .patch_version = 0, + }, }; return &language; } diff --git a/src/tree_sitter/array.h b/src/tree_sitter/array.h index 15a3b23..a17a574 100644 --- a/src/tree_sitter/array.h +++ b/src/tree_sitter/array.h @@ -14,6 +14,7 @@ extern "C" { #include #ifdef _MSC_VER +#pragma warning(push) #pragma warning(disable : 4101) #elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push @@ -278,7 +279,7 @@ static inline void _array__splice(Array *self, size_t element_size, #define _compare_int(a, b) ((int)*(a) - (int)(b)) #ifdef _MSC_VER -#pragma warning(default : 4101) +#pragma warning(pop) #elif defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index 799f599..858107d 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -18,6 +18,11 @@ typedef uint16_t TSStateId; typedef uint16_t TSSymbol; typedef uint16_t TSFieldId; typedef struct TSLanguage TSLanguage; +typedef struct TSLanguageMetadata { + uint8_t major_version; + uint8_t minor_version; + uint8_t patch_version; +} TSLanguageMetadata; #endif typedef struct { @@ -26,10 +31,11 @@ typedef struct { bool inherited; } TSFieldMapEntry; +// Used to index the field and supertype maps. typedef struct { uint16_t index; uint16_t length; -} TSFieldMapSlice; +} TSMapSlice; typedef struct { bool visible; @@ -79,6 +85,12 @@ typedef struct { uint16_t external_lex_state; } TSLexMode; +typedef struct { + uint16_t lex_state; + uint16_t external_lex_state; + uint16_t reserved_word_set_id; +} TSLexerMode; + typedef union { TSParseAction action; struct { @@ -93,7 +105,7 @@ typedef struct { } TSCharacterRange; struct TSLanguage { - uint32_t version; + uint32_t abi_version; uint32_t symbol_count; uint32_t alias_count; uint32_t token_count; @@ -109,13 +121,13 @@ struct TSLanguage { const TSParseActionEntry *parse_actions; const char * const *symbol_names; const char * const *field_names; - const TSFieldMapSlice *field_map_slices; + const TSMapSlice *field_map_slices; const TSFieldMapEntry *field_map_entries; const TSSymbolMetadata *symbol_metadata; const TSSymbol *public_symbol_map; const uint16_t *alias_map; const TSSymbol *alias_sequences; - const TSLexMode *lex_modes; + const TSLexerMode *lex_modes; bool (*lex_fn)(TSLexer *, TSStateId); bool (*keyword_lex_fn)(TSLexer *, TSStateId); TSSymbol keyword_capture_token; @@ -129,15 +141,23 @@ struct TSLanguage { void (*deserialize)(void *, const char *, unsigned); } external_scanner; const TSStateId *primary_state_ids; + const char *name; + const TSSymbol *reserved_words; + uint16_t max_reserved_word_set_size; + uint32_t supertype_count; + const TSSymbol *supertype_symbols; + const TSMapSlice *supertype_map_slices; + const TSSymbol *supertype_map_entries; + TSLanguageMetadata metadata; }; -static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { +static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { uint32_t index = 0; uint32_t size = len - index; while (size > 1) { uint32_t half_size = size / 2; uint32_t mid_index = index + half_size; - TSCharacterRange *range = &ranges[mid_index]; + const TSCharacterRange *range = &ranges[mid_index]; if (lookahead >= range->start && lookahead <= range->end) { return true; } else if (lookahead > range->end) { @@ -145,7 +165,7 @@ static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t } size -= half_size; } - TSCharacterRange *range = &ranges[index]; + const TSCharacterRange *range = &ranges[index]; return (lookahead >= range->start && lookahead <= range->end); } From 35258d5da1089d84ca46809052fd0a8d8d621864 Mon Sep 17 00:00:00 2001 From: mohammadkhan Date: Tue, 26 Aug 2025 22:57:17 +0530 Subject: [PATCH 2/2] bump: upgrade to 0.3.0 --- CMakeLists.txt | 2 +- Cargo.lock | 199 ++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 6 +- Makefile | 2 +- go.mod | 2 +- package-lock.json | 4 +- package.json | 2 +- pyproject.toml | 2 +- src/parser.c | 2 +- tree-sitter.json | 2 +- 10 files changed, 211 insertions(+), 12 deletions(-) create mode 100644 Cargo.lock diff --git a/CMakeLists.txt b/CMakeLists.txt index fb3cdee..29800be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.13) project(tree-sitter-proto - VERSION "0.2.0" + VERSION "0.3.0" DESCRIPTION "Parser for proto2 and proto3 files" HOMEPAGE_URL "https://github.com/coder3101/tree-sitter-proto" LANGUAGES C) diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..5e735a3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,199 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "cc" +version = "1.2.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" +dependencies = [ + "shlex", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" + +[[package]] +name = "indexmap" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "proc-macro2" +version = "1.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.143" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" +dependencies = [ + "indexmap", + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" + +[[package]] +name = "syn" +version = "2.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tree-sitter" +version = "0.25.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7b8994f367f16e6fa14b5aebbcb350de5d7cbea82dc5b00ae997dd71680dd2" +dependencies = [ + "cc", + "regex", + "regex-syntax", + "serde_json", + "streaming-iterator", + "tree-sitter-language", +] + +[[package]] +name = "tree-sitter-language" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4013970217383f67b18aef68f6fb2e8d409bc5755227092d32efb0422ba24b8" + +[[package]] +name = "tree-sitter-proto" +version = "0.3.0" +dependencies = [ + "cc", + "tree-sitter", + "tree-sitter-language", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" diff --git a/Cargo.toml b/Cargo.toml index 02c1c50..581e9f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-proto" description = "Parser for proto2 and proto3 files" -version = "0.2.0" +version = "0.3.0" authors = ["Mohammad Ashar Khan "] license = "MIT" readme = "README.md" @@ -21,7 +21,7 @@ path = "bindings/rust/lib.rs" tree-sitter-language = "0.1" [build-dependencies] -cc = "1.1.22" +cc = "1.2" [dev-dependencies] -tree-sitter = "0.24.3" +tree-sitter = "0.25" diff --git a/Makefile b/Makefile index a06051c..84596b8 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ endif LANGUAGE_NAME := tree-sitter-proto HOMEPAGE_URL := https://github.com/coder3101/tree-sitter-proto -VERSION := 0.2.0 +VERSION := 0.3.0 # repository SRC_DIR := src diff --git a/go.mod b/go.mod index 93ae536..d461bfd 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,6 @@ go 1.23 toolchain go1.23.2 -require github.com/tree-sitter/go-tree-sitter v0.23.1 +require github.com/tree-sitter/go-tree-sitter v0.25.0 require github.com/mattn/go-pointer v0.0.1 // indirect diff --git a/package-lock.json b/package-lock.json index b47bd77..8c22a20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tree-sitter-proto", - "version": "0.2.0", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tree-sitter-proto", - "version": "0.2.0", + "version": "0.3.0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 92305db..f6a8a3f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tree-sitter-proto", - "version": "0.2.0", + "version": "0.3.0", "description": "Parser for proto2 and proto3 files", "repository": "github:tree-sitter/tree-sitter-proto", "license": "MIT", diff --git a/pyproject.toml b/pyproject.toml index 60d99a2..b12f51a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "tree-sitter-proto" description = "Parser for proto2 and proto3 files" -version = "0.2.0" +version = "0.3.0" keywords = ["incremental", "parsing", "tree-sitter", "proto"] classifiers = [ "Intended Audience :: Developers", diff --git a/src/parser.c b/src/parser.c index c04aa3b..b60bea3 100644 --- a/src/parser.c +++ b/src/parser.c @@ -9384,7 +9384,7 @@ TS_PUBLIC const TSLanguage *tree_sitter_proto(void) { .max_reserved_word_set_size = 0, .metadata = { .major_version = 0, - .minor_version = 2, + .minor_version = 3, .patch_version = 0, }, }; diff --git a/tree-sitter.json b/tree-sitter.json index 29eb98b..aff5ddd 100644 --- a/tree-sitter.json +++ b/tree-sitter.json @@ -10,7 +10,7 @@ } ], "metadata": { - "version": "0.2.0", + "version": "0.3.0", "license": "MIT", "description": "Parser for proto2 and proto3 files", "authors": [