ruby_tree_sitter 2.0.0-arm64-darwin → 2.1.0-arm64-darwin

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 762e85c03b1ac0aff82accdabde06c3bdce317f407618b372472c19a4c4d0e9f
4
- data.tar.gz: 053c98c04d1f4b7bb9b9f4ee1c6cfa5b78e2b0fd286033747bf40584b5a80b67
3
+ metadata.gz: 7b7c4451a5742fa58563957e313101cd381bc6a09e6f21fd976dde4b72916fc1
4
+ data.tar.gz: 1aca7f12a7e13ef674b1d36a2f7d6e174ca5c523c2b9ff958280caa6ca0c848c
5
5
  SHA512:
6
- metadata.gz: bcb0cf7c31580f0b57dc7f4a6d244beff6b8ea7b2217cc79c9f65bfd82859d3a8ae983488170e7c651bf125f8f4f7100aaae130b3fbf2469c40eef22155a62db
7
- data.tar.gz: 791a4a64e943acfbe06cce027008da67f223cff1aa3cb1ce63d11e39088804f31718c8b6f8aa73db99f750b4274ecc79ff55fca7f948442ce9d7d1ef2fe0f1ad
6
+ metadata.gz: 03d4c5b4a3ff7b3fc66936aba365a37baacf72712c544e09afd61846ca9ab75930b0868b4e1ec2cfab15deb5c96a73bf15e4189d74cd03b5bf8a26c961705bd7
7
+ data.tar.gz: af72e5c01c65ee780a0adcd44e4b25dcedab27d5c85f097665fcc812e8e80ebdab93e9928bc8b7db5feac95686581e897d34568d82cb554617307bd05b74b8f4
@@ -14,7 +14,8 @@ TSInputEncoding value_to_encoding(VALUE encoding) {
14
14
 
15
15
  // NOTE: should we emit a warning instead of defaulting to UTF8?
16
16
  if (enc == u16) {
17
- return TSInputEncodingUTF16;
17
+ // tree-sitter 0.26+ split UTF16 into UTF16LE and UTF16BE
18
+ return TSInputEncodingUTF16LE;
18
19
  } else {
19
20
  return TSInputEncodingUTF8;
20
21
  }
@@ -121,25 +121,27 @@ if sanitizers
121
121
  $warnflags.gsub!(/#{r}/, '')
122
122
  end
123
123
 
124
- cflags.concat %W[
125
- -fms-extensions
126
- -fdeclspec
127
- -fsanitize=#{sanitizers}
128
- -fsanitize-blacklist=../../../../.asanignore
129
- -fsanitize-recover=#{sanitizers}
130
- -fno-sanitize-recover=all
131
- -fno-sanitize=null
132
- -fno-sanitize=alignment
133
- -fno-omit-frame-pointer
134
- ]
135
-
136
- ldflags.concat %W[
137
- -fsanitize=#{sanitizers}
138
- -dynamic-libasan
139
- ]
124
+ cflags.push(*
125
+ %W[
126
+ -fms-extensions
127
+ -fdeclspec
128
+ -fsanitize=#{sanitizers}
129
+ -fsanitize-blacklist=../../../../.asanignore
130
+ -fsanitize-recover=#{sanitizers}
131
+ -fno-sanitize-recover=all
132
+ -fno-sanitize=null
133
+ -fno-sanitize=alignment
134
+ -fno-omit-frame-pointer
135
+ ])
136
+
137
+ ldflags.push(*
138
+ %W[
139
+ -fsanitize=#{sanitizers}
140
+ -dynamic-libasan
141
+ ])
140
142
  end
141
143
 
142
- cflags.concat %w[-std=c99 -fPIC -Wall]
144
+ cflags.push(*%w[-std=c99 -fPIC -Wall])
143
145
 
144
146
  append_cflags(cflags)
145
147
  append_ldflags(ldflags)
@@ -3,7 +3,8 @@
3
3
  #include <stdint.h>
4
4
  #include <stdio.h>
5
5
 
6
- typedef TSLanguage *(tree_sitter_lang)(void);
6
+ // tree-sitter 0.26+ returns const TSLanguage*
7
+ typedef const TSLanguage *(tree_sitter_lang)(void);
7
8
  const char *tree_sitter_prefix = "tree_sitter_";
8
9
 
9
10
  extern VALUE mTreeSitter;
@@ -40,26 +41,32 @@ static VALUE language_load(VALUE self, VALUE name, VALUE path) {
40
41
  VALUE path_s = rb_funcall(path, rb_intern("to_s"), 0);
41
42
  char *path_cstr = StringValueCStr(path_s);
42
43
  void *lib = dlopen(path_cstr, RTLD_NOW);
43
- const char *err = dlerror();
44
- if (err != NULL) {
44
+ if (lib == NULL) {
45
+ const char *err = dlerror();
45
46
  VALUE parser_not_found = rb_const_get(mTreeSitter, rb_intern("ParserNotFoundError"));
46
47
  rb_raise(parser_not_found,
47
- "Could not load shared library `%s'.\nReason: %s", path_cstr, err);
48
+ "Could not load shared library `%s'.\nReason: %s", path_cstr, err ? err : "unknown error");
48
49
  }
49
50
 
50
- char buf[256];
51
- snprintf(buf, sizeof(buf), "tree_sitter_%s", StringValueCStr(name));
51
+ VALUE symbol_name = rb_sprintf("tree_sitter_%s", StringValueCStr(name));
52
+ char *buf = StringValueCStr(symbol_name);
53
+
54
+ // Clear any previous error before dlsym (POSIX requirement)
55
+ dlerror();
56
+
52
57
  tree_sitter_lang *make_ts_language = dlsym(lib, buf);
53
- err = dlerror();
54
- if (err != NULL) {
58
+
59
+ // Only check dlerror if dlsym returned NULL
60
+ if (make_ts_language == NULL) {
61
+ const char *err = dlerror();
55
62
  dlclose(lib);
56
63
  VALUE symbol_not_found = rb_const_get(mTreeSitter, rb_intern("SymbolNotFoundError"));
57
64
  rb_raise(symbol_not_found,
58
- "Could not load symbol `%s' from library `%s'.\nReason:%s",
59
- StringValueCStr(name), path_cstr, err);
65
+ "Could not load symbol `%s' from library `%s'.\nReason: %s",
66
+ buf, path_cstr, err ? err : "symbol not found");
60
67
  }
61
68
 
62
- TSLanguage *lang = make_ts_language();
69
+ const TSLanguage *lang = make_ts_language();
63
70
  if (lang == NULL) {
64
71
  dlclose(lib);
65
72
  VALUE language_load_error = rb_const_get(mTreeSitter, rb_intern("LanguageLoadError"));
@@ -69,7 +76,8 @@ static VALUE language_load(VALUE self, VALUE name, VALUE path) {
69
76
  StringValueCStr(name), path_cstr);
70
77
  }
71
78
 
72
- uint32_t version = ts_language_version(lang);
79
+ // tree-sitter 0.26+ renamed ts_language_version to ts_language_abi_version
80
+ uint32_t version = ts_language_abi_version(lang);
73
81
  if (version < TREE_SITTER_MIN_COMPATIBLE_LANGUAGE_VERSION) {
74
82
  VALUE version_error = rb_const_get(mTreeSitter, rb_intern("ParserVersionError"));
75
83
  rb_raise(version_error,
@@ -194,7 +202,8 @@ static VALUE language_symbol_type(VALUE self, VALUE symbol) {
194
202
  * @see Parser#language=
195
203
  */
196
204
  static VALUE language_version(VALUE self) {
197
- return UINT2NUM(ts_language_version(SELF));
205
+ // tree-sitter 0.26+ renamed ts_language_version to ts_language_abi_version
206
+ return UINT2NUM(ts_language_abi_version(SELF));
198
207
  }
199
208
 
200
209
  void init_language(void) {
@@ -220,4 +229,5 @@ void init_language(void) {
220
229
  rb_define_method(cLanguage, "symbol_name", language_symbol_name, 1);
221
230
  rb_define_method(cLanguage, "symbol_type", language_symbol_type, 1);
222
231
  rb_define_method(cLanguage, "version", language_version, 0);
232
+ rb_define_method(cLanguage, "abi_version", language_version, 0);
223
233
  }
@@ -7,6 +7,7 @@ VALUE cParser;
7
7
  typedef struct {
8
8
  TSParser *data;
9
9
  size_t cancellation_flag;
10
+ VALUE logger;
10
11
  } parser_t;
11
12
 
12
13
  static void parser_free(void *ptr) {
@@ -19,14 +20,24 @@ static size_t parser_memsize(const void *ptr) {
19
20
  return sizeof(type);
20
21
  }
21
22
 
23
+ static void parser_mark(void *ptr) {
24
+ parser_t *parser = (parser_t *)ptr;
25
+ rb_gc_mark_movable(parser->logger);
26
+ }
27
+
28
+ static void parser_compact(void *ptr) {
29
+ parser_t *parser = (parser_t *)ptr;
30
+ parser->logger = rb_gc_location(parser->logger);
31
+ }
32
+
22
33
  const rb_data_type_t parser_data_type = {
23
34
  .wrap_struct_name = "parser",
24
35
  .function =
25
36
  {
26
- .dmark = NULL,
37
+ .dmark = parser_mark,
27
38
  .dfree = parser_free,
28
39
  .dsize = parser_memsize,
29
- .dcompact = NULL,
40
+ .dcompact = parser_compact,
30
41
  },
31
42
  .flags = RUBY_TYPED_FREE_IMMEDIATELY,
32
43
  };
@@ -37,6 +48,7 @@ static VALUE parser_allocate(VALUE klass) {
37
48
  parser_t *parser;
38
49
  VALUE res = TypedData_Make_Struct(klass, parser_t, &parser_data_type, parser);
39
50
  parser->data = ts_parser_new();
51
+ parser->logger = Qnil;
40
52
  return res;
41
53
  }
42
54
 
@@ -44,9 +56,14 @@ static VALUE parser_allocate(VALUE klass) {
44
56
  * Get the parser's current cancellation flag pointer.
45
57
  *
46
58
  * @return [Integer]
59
+ *
60
+ * @note DEPRECATED in tree-sitter 0.26+. This API was removed.
61
+ * Use TSParseOptions with progress_callback instead.
47
62
  */
48
63
  static VALUE parser_get_cancellation_flag(VALUE self) {
49
- return SIZET2NUM(*ts_parser_cancellation_flag(SELF));
64
+ // tree-sitter 0.26+ removed cancellation_flag API
65
+ // Return the stored value for backward compatibility
66
+ return SIZET2NUM(unwrap(self)->cancellation_flag);
50
67
  }
51
68
 
52
69
  /**
@@ -58,13 +75,15 @@ static VALUE parser_get_cancellation_flag(VALUE self) {
58
75
  *
59
76
  * @see parse
60
77
  *
61
- * @note This is not well-tested in the bindings.
78
+ * @note DEPRECATED in tree-sitter 0.26+. This API was removed.
79
+ * Use TSParseOptions with progress_callback instead.
62
80
  *
63
81
  * @return nil
64
82
  */
65
83
  static VALUE parser_set_cancellation_flag(VALUE self, VALUE flag) {
84
+ // tree-sitter 0.26+ removed cancellation_flag API
85
+ // Store the value for backward compatibility but it won't affect parsing
66
86
  unwrap(self)->cancellation_flag = NUM2SIZET(flag);
67
- ts_parser_set_cancellation_flag(SELF, &unwrap(self)->cancellation_flag);
68
87
  return Qnil;
69
88
  }
70
89
 
@@ -171,6 +190,7 @@ static VALUE parser_get_logger(VALUE self) {
171
190
  */
172
191
  static VALUE parser_set_logger(VALUE self, VALUE logger) {
173
192
  ts_parser_set_logger(SELF, value_to_logger(logger));
193
+ unwrap(self)->logger = logger;
174
194
  return Qnil;
175
195
  }
176
196
 
@@ -345,32 +365,6 @@ static VALUE parser_reset(VALUE self) {
345
365
  return Qnil;
346
366
  }
347
367
 
348
- /**
349
- * Get the duration in microseconds that parsing is allowed to take.
350
- *
351
- * @return [Integer]
352
- */
353
- static VALUE parser_get_timeout_micros(VALUE self) {
354
- return ULL2NUM(ts_parser_timeout_micros(SELF));
355
- }
356
-
357
- /**
358
- * Set the maximum duration in microseconds that parsing should be allowed to
359
- * take before halting.
360
- *
361
- * If parsing takes longer than this, it will halt early, returning +nil+.
362
- *
363
- * @see parse
364
- *
365
- * @param timeout [Integer]
366
- *
367
- * @return [nil]
368
- */
369
- static VALUE parser_set_timeout_micros(VALUE self, VALUE timeout) {
370
- ts_parser_set_timeout_micros(SELF, NUM2ULL(timeout));
371
- return Qnil;
372
- }
373
-
374
368
  void init_parser(void) {
375
369
  cParser = rb_define_class_under(mTreeSitter, "Parser", rb_cObject);
376
370
 
@@ -393,6 +387,4 @@ void init_parser(void) {
393
387
  parser_parse_string_encoding, 3);
394
388
  rb_define_method(cParser, "print_dot_graphs", parser_print_dot_graphs, 1);
395
389
  rb_define_method(cParser, "reset", parser_reset, 0);
396
- rb_define_method(cParser, "timeout_micros", parser_get_timeout_micros, 0);
397
- rb_define_method(cParser, "timeout_micros=", parser_set_timeout_micros, 1);
398
390
  }
@@ -204,10 +204,9 @@ void init_query_cursor(void) {
204
204
 
205
205
  rb_define_alloc_func(cQueryCursor, query_cursor_allocate);
206
206
 
207
- /* Module methods */
208
- rb_define_module_function(cQueryCursor, "exec", query_cursor_exec_static, 2);
209
-
210
207
  /* Class methods */
208
+ rb_define_singleton_method(cQueryCursor, "exec", query_cursor_exec_static, 2);
209
+
211
210
  // Accessors
212
211
  DECLARE_ACCESSOR(cQueryCursor, query_cursor, match_limit)
213
212
 
@@ -215,10 +214,6 @@ void init_query_cursor(void) {
215
214
  rb_define_method(cQueryCursor, "exec", query_cursor_exec, 2);
216
215
  rb_define_method(cQueryCursor, "exceed_match_limit?",
217
216
  query_cursor_did_exceed_match_limit, 0);
218
- rb_define_method(cQueryCursor, "match_limit", query_cursor_get_match_limit,
219
- 0);
220
- rb_define_method(cQueryCursor, "match_limit=", query_cursor_set_match_limit,
221
- 1);
222
217
  rb_define_method(cQueryCursor,
223
218
  "max_start_depth=", query_cursor_set_max_start_depth, 1);
224
219
  rb_define_method(cQueryCursor, "next_capture", query_cursor_next_capture, 0);
@@ -39,7 +39,7 @@ module TreeSitter
39
39
  end
40
40
 
41
41
  def extract?
42
- !exe.filter { |k, v| %i[tar zip].include?(k) && v }.empty?
42
+ exe.any? { |k, v| %i[tar zip].include?(k) && v }
43
43
  end
44
44
 
45
45
  def download
@@ -50,7 +50,7 @@ module TreeSitter
50
50
  %w[git curl wget].each do |cmd|
51
51
  res =
52
52
  if find_executable(cmd)
53
- send("sources_from_#{cmd}")
53
+ send("sources_from_#{cmd}?")
54
54
  else
55
55
  false
56
56
  end
@@ -76,7 +76,7 @@ module TreeSitter
76
76
  MSG
77
77
  end
78
78
 
79
- def sources_from_curl
79
+ def sources_from_curl?
80
80
  return false if !exe?(:curl) || !extract?
81
81
 
82
82
  if exe?(:tar)
@@ -90,7 +90,7 @@ module TreeSitter
90
90
  true
91
91
  end
92
92
 
93
- def sources_from_git
93
+ def sources_from_git?
94
94
  return false if !exe?(:git)
95
95
 
96
96
  sh <<~SHELL.chomp
@@ -104,7 +104,7 @@ module TreeSitter
104
104
  true
105
105
  end
106
106
 
107
- def sources_from_wget
107
+ def sources_from_wget?
108
108
  return false if !exe?(:wget) || !extract?
109
109
 
110
110
  if exe?(:tar)
Binary file
Binary file
Binary file
Binary file
@@ -45,11 +45,7 @@ module TreeSitter
45
45
  pattern_count.times do |i| # rubocop:disable Metrics/BlockLength
46
46
  predicate_steps = predicates_for_pattern(i)
47
47
  byte_offset = start_byte_for_pattern(i)
48
- row =
49
- source.chars.map.with_index
50
- .take_while { |_, i| i < byte_offset } # rubocop:disable Lint/ShadowingOuterLocalVariable
51
- .filter { |c, _| c == "\n" }
52
- .size
48
+ row = source[0...byte_offset].count("\n")
53
49
  text_predicates = []
54
50
  property_predicates = []
55
51
  property_settings = []
@@ -2,7 +2,7 @@
2
2
 
3
3
  module TreeSitter
4
4
  # The version of the tree-sitter library.
5
- TREESITTER_VERSION = '0.24.7'
5
+ TREESITTER_VERSION = '0.26.5'
6
6
  # The current version of the gem.
7
- VERSION = '2.0.0'
7
+ VERSION = '2.1.0'
8
8
  end
data/lib/tree_sitter.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
-
5
3
  begin
6
4
  RUBY_VERSION =~ /(\d+\.\d+)/
7
5
  require "tree_sitter/#{Regexp.last_match(1)}/tree_sitter"
data/tree_sitter.gemspec CHANGED
@@ -6,7 +6,7 @@ $LOAD_PATH.unshift(lib) if !$LOAD_PATH.include?(lib)
6
6
  require 'tree_sitter/version'
7
7
 
8
8
  Gem::Specification.new do |spec|
9
- spec.required_ruby_version = Gem::Requirement.new('>= 3.1.0')
9
+ spec.required_ruby_version = Gem::Requirement.new('>= 3.2.0')
10
10
 
11
11
  spec.authors = ['Firas al-Khalil', 'Derek Stride']
12
12
  spec.email = ['firasalkhalil@gmail.com', 'derek@stride.host']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_tree_sitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: arm64-darwin
6
6
  authors:
7
7
  - Firas al-Khalil
8
8
  - Derek Stride
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-22 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oppen
@@ -56,8 +56,8 @@ email:
56
56
  - firasalkhalil@gmail.com
57
57
  - derek@stride.host
58
58
  executables:
59
- - rbts
60
59
  - print_matches
60
+ - rbts
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.6.2
148
+ rubygems_version: 4.0.3
149
149
  specification_version: 4
150
150
  summary: Ruby bindings for Tree-Sitter
151
151
  test_files: []