ruby_tree_sitter 0.20.8.2-x86_64-darwin-20 → 0.20.8.3-x86_64-darwin-20
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 +4 -4
- data/ext/tree_sitter/extconf.rb +0 -42
- data/ext/tree_sitter/repo.rb +121 -0
- data/lib/tree_sitter/node.rb +20 -3
- data/lib/tree_sitter/tree_sitter.bundle +0 -0
- data/lib/tree_sitter/version.rb +1 -1
- data/test/tree_sitter/node_test.rb +56 -0
- data/tree_sitter.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd1b320b75859a2c81f94f56f0e4bcc518ab9c478a053bb161053cce37855655
|
4
|
+
data.tar.gz: caa003466d910ef2e84d04cf31394979b5116b4adbb73b9767eadd1dae8e3701
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 390ade41ebe8950def40d5c517d1b1b1a57d92bbeaeebc15eb415211f655a15898bbd6152897001f0a8c4e4aa6f12aaa0460ce8daf8cf4398fa69df45e7f84a9
|
7
|
+
data.tar.gz: fd43b39cecca804d0a180021c99e4203988e836dc1ebe97496c2ddf5eaaff5dd69668f0a76b2665bafbb9806b2ea13d7ee7ae5baf590e6423320f466ab0b8fad
|
data/ext/tree_sitter/extconf.rb
CHANGED
@@ -53,48 +53,6 @@ dir_include, dir_lib =
|
|
53
53
|
repo.include_and_lib_dirs
|
54
54
|
end
|
55
55
|
|
56
|
-
# TREESITTER_SPEC = Bundler.load_gemspec('../../../../tree_sitter.gemspec')
|
57
|
-
|
58
|
-
# # def version = TREESITTER_SPEC.version.gsub(/\A(\d+\.\d+\.\d+)(\.\d+)?\z/, '\1')
|
59
|
-
|
60
|
-
# def version = '0.20.8'
|
61
|
-
|
62
|
-
# LINUX_PLATFORM_REGEX = /linux/
|
63
|
-
# DARWIN_PLATFORM_REGEX = /darwin/
|
64
|
-
|
65
|
-
# def platform = RUBY_PLATFORM
|
66
|
-
|
67
|
-
# def darwin?
|
68
|
-
# !!(platform =~ DARWIN_PLATFORM_REGEX)
|
69
|
-
# end
|
70
|
-
|
71
|
-
# def dll_ext
|
72
|
-
# darwin? ? 'dylib' : 'so'
|
73
|
-
# end
|
74
|
-
|
75
|
-
# def staging_path
|
76
|
-
# '../../stage/lib/tree_sitter'
|
77
|
-
# end
|
78
|
-
|
79
|
-
# def downloaded_dll_path
|
80
|
-
# "tree-sitter-#{version}"
|
81
|
-
# end
|
82
|
-
|
83
|
-
# def add_tree_sitter_dll_to_gem
|
84
|
-
# puts ">>>>>>>>>>>>> #{`pwd`}"
|
85
|
-
# path = "#{downloaded_dll_path}/libtree-sitter*.#{dll_ext}"
|
86
|
-
# files =
|
87
|
-
# Dir.glob(path)
|
88
|
-
# .map { |f| Pathname(f) }
|
89
|
-
# .filter { |f| !f.symlink? && f.file? }
|
90
|
-
# dll = files.first
|
91
|
-
# dst = Pathname(staging_path) / "libtree-sitter.#{dll_ext}"
|
92
|
-
# FileUtils.cp(dll, dst)
|
93
|
-
# TREESITTER_SPEC.files << dst
|
94
|
-
# end
|
95
|
-
|
96
|
-
# add_tree_sitter_dll_to_gem
|
97
|
-
|
98
56
|
# ################################## #
|
99
57
|
# Generate Makefile #
|
100
58
|
# ################################## #
|
@@ -0,0 +1,121 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../lib/tree_sitter/version'
|
4
|
+
|
5
|
+
module TreeSitter
|
6
|
+
# Fetches tree-sitter sources.
|
7
|
+
class Repo
|
8
|
+
attr_reader :exe, :src, :url, :version
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@version = TREESITTER_VERSION
|
12
|
+
|
13
|
+
# `tree-sitter-@version` is the name produced by tagged releases of sources
|
14
|
+
# by git, so we use it everywhere, including when cloning from git.
|
15
|
+
@src = Pathname.pwd / "tree-sitter-#{@version}"
|
16
|
+
|
17
|
+
@url = {
|
18
|
+
git: 'https://github.com/tree-sitter/tree-sitter',
|
19
|
+
tar: "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v#{@version}.tar.gz",
|
20
|
+
zip: "https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v#{@version}.zip"
|
21
|
+
}
|
22
|
+
|
23
|
+
@exe = {}
|
24
|
+
%i[curl git tar wget zip].each do |cmd|
|
25
|
+
@exe[cmd] = find_executable(cmd.to_s)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def compile
|
30
|
+
# We need to clean because the same folder is used over and over
|
31
|
+
# by rake-compiler-dock
|
32
|
+
sh "cd #{src} && make clean && make"
|
33
|
+
end
|
34
|
+
|
35
|
+
def exe?(name)
|
36
|
+
@exe[name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract?
|
40
|
+
!exe.filter { |k, v| %i[tar zip].include?(k) && v }.empty?
|
41
|
+
end
|
42
|
+
|
43
|
+
def download
|
44
|
+
# TODO: should we force re-download? Maybe with a flag?
|
45
|
+
return true if Dir.exist? src
|
46
|
+
|
47
|
+
res = false
|
48
|
+
%w[git curl wget].each do |cmd|
|
49
|
+
res =
|
50
|
+
if find_executable(cmd)
|
51
|
+
send("sources_from_#{cmd}")
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
break if res
|
56
|
+
end
|
57
|
+
|
58
|
+
res
|
59
|
+
end
|
60
|
+
|
61
|
+
def include_and_lib_dirs
|
62
|
+
[[src / 'lib' / 'include'], [src.to_s]]
|
63
|
+
end
|
64
|
+
|
65
|
+
def keep_static_lib
|
66
|
+
src
|
67
|
+
.children
|
68
|
+
.filter { |f| /\.(dylib|so)/ =~ f.basename.to_s }
|
69
|
+
.each(&:unlink)
|
70
|
+
end
|
71
|
+
|
72
|
+
def sh(cmd)
|
73
|
+
return if system(cmd)
|
74
|
+
|
75
|
+
abort <<~MSG
|
76
|
+
|
77
|
+
Failed to run: #{cmd}
|
78
|
+
|
79
|
+
exiting …
|
80
|
+
|
81
|
+
MSG
|
82
|
+
end
|
83
|
+
|
84
|
+
def sources_from_curl
|
85
|
+
return false if !exe?(:curl) || !extract?
|
86
|
+
|
87
|
+
if exe?(:tar)
|
88
|
+
sh "curl -L #{url[:tar]} -o tree-sitter-v#{version}.tar.gz"
|
89
|
+
sh "tar -xf tree-sitter-v#{version}.tar.gz"
|
90
|
+
elsif exe?(:zip)
|
91
|
+
sh "curl -L #{url[:zip]} -o tree-sitter-v#{version}.zip"
|
92
|
+
sh "unzip -q tree-sitter-v#{version}.zip"
|
93
|
+
end
|
94
|
+
|
95
|
+
true
|
96
|
+
end
|
97
|
+
|
98
|
+
def sources_from_git
|
99
|
+
return false if !exe?(:git)
|
100
|
+
|
101
|
+
sh "git clone #{url[:git]} #{src}"
|
102
|
+
sh "cd #{src} && git checkout tags/v#{version}"
|
103
|
+
|
104
|
+
true
|
105
|
+
end
|
106
|
+
|
107
|
+
def sources_from_wget
|
108
|
+
return false if !exe?(:wget) || !extract?
|
109
|
+
|
110
|
+
if exe?(:tar)
|
111
|
+
sh "wget #{url[:tar]} -O tree-sitter-v#{version}.tar.gz"
|
112
|
+
sh "tar -xf tree-sitter-v#{version}.tar.gz"
|
113
|
+
elsif exe?(:zip)
|
114
|
+
sh "wget #{url[:zip]} -O tree-sitter-v#{version}.zip"
|
115
|
+
sh "unzip -q tree-sitter-v#{version}.zip"
|
116
|
+
end
|
117
|
+
|
118
|
+
true
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/lib/tree_sitter/node.rb
CHANGED
@@ -142,7 +142,12 @@ module TreeSitter
|
|
142
142
|
# uses named_child | field_name_for_child
|
143
143
|
# child_by_field_name | via each_node
|
144
144
|
# ------------------------------+----------------------
|
145
|
-
|
145
|
+
# @param all [Boolean] If `true`, return an array of nodes for all the
|
146
|
+
# demanded keys, putting `nil` for missing ones. If `false`, return the
|
147
|
+
# same array after calling `compact`. Defaults to `false`.
|
148
|
+
#
|
149
|
+
# See {#fetch_all}.
|
150
|
+
def fetch(*keys, all: false, **_kwargs)
|
146
151
|
dict = {}
|
147
152
|
keys.each.with_index do |k, i|
|
148
153
|
dict[k.to_s] = i
|
@@ -151,13 +156,25 @@ module TreeSitter
|
|
151
156
|
res = {}
|
152
157
|
each_field do |f, c|
|
153
158
|
if dict.key?(f)
|
154
|
-
res[
|
159
|
+
res[f] = c
|
155
160
|
dict.delete(f)
|
156
161
|
end
|
157
162
|
break if dict.empty?
|
158
163
|
end
|
159
164
|
|
160
|
-
res.
|
165
|
+
res = keys.uniq.map { |k| res[k.to_s] }
|
166
|
+
res = res.compact if !all
|
167
|
+
res
|
168
|
+
end
|
169
|
+
|
170
|
+
# Access all named children of a node, returning `nil` for missing ones.
|
171
|
+
#
|
172
|
+
# Equivalent to `fetch(…, all: true)`.
|
173
|
+
#
|
174
|
+
# See {#fetch}.
|
175
|
+
def fetch_all(*keys, **kwargs)
|
176
|
+
kwargs[:all] = true
|
177
|
+
fetch(*keys, **kwargs)
|
161
178
|
end
|
162
179
|
end
|
163
180
|
end
|
Binary file
|
data/lib/tree_sitter/version.rb
CHANGED
@@ -352,4 +352,60 @@ describe 'fetch' do
|
|
352
352
|
assert_equal 1, m.length
|
353
353
|
assert_equal method, m.first
|
354
354
|
end
|
355
|
+
|
356
|
+
it 'should return an empty array when asked for non-existent fields' do
|
357
|
+
b = @child.fetch(:a)
|
358
|
+
assert_empty b
|
359
|
+
|
360
|
+
b = @child.fetch(:b, :focus)
|
361
|
+
assert_empty b
|
362
|
+
end
|
363
|
+
|
364
|
+
it 'should return an array of `nil` values when asked for non-existent fields with `all: true`' do
|
365
|
+
b = @child.fetch(:d, all: true)
|
366
|
+
refute_empty b
|
367
|
+
assert b.all?(&:nil?)
|
368
|
+
|
369
|
+
b = @child.fetch(:e, :f, all: true)
|
370
|
+
refute_empty b
|
371
|
+
assert b.all?(&:nil?)
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'should return values, even if `nil`, for all keys when `all: true`' do
|
375
|
+
method = @child.child(0)
|
376
|
+
arguments = @child.child(1)
|
377
|
+
|
378
|
+
m, a, f = @child.fetch(:method, :arguments, :fake, all: true)
|
379
|
+
|
380
|
+
assert_equal method, m
|
381
|
+
assert_equal arguments, a
|
382
|
+
assert_nil f
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
describe 'fetch_all' do
|
387
|
+
before do
|
388
|
+
@child = root.child(0).child(4)
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'should return an array of `nil` values when asked for non-existent fields' do
|
392
|
+
b = @child.fetch_all(:d)
|
393
|
+
refute_empty b
|
394
|
+
assert b.all?(&:nil?)
|
395
|
+
|
396
|
+
b = @child.fetch_all(:e, :f)
|
397
|
+
refute_empty b
|
398
|
+
assert b.all?(&:nil?)
|
399
|
+
end
|
400
|
+
|
401
|
+
it 'should return values, even if `nil`, for all keys' do
|
402
|
+
method = @child.child(0)
|
403
|
+
arguments = @child.child(1)
|
404
|
+
|
405
|
+
m, a, f = @child.fetch_all(:method, :arguments, :fake)
|
406
|
+
|
407
|
+
assert_equal method, m
|
408
|
+
assert_equal arguments, a
|
409
|
+
assert_nil f
|
410
|
+
end
|
355
411
|
end
|
data/tree_sitter.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
|
19
19
|
spec.extensions = %(ext/tree_sitter/extconf.rb)
|
20
20
|
spec.files = %w[LICENSE README.md tree_sitter.gemspec]
|
21
|
-
spec.files += Dir.glob('ext/**/*.
|
21
|
+
spec.files += Dir.glob('ext/**/*.{c,h,rb}')
|
22
22
|
spec.files += Dir.glob('lib/**/*.rb')
|
23
23
|
spec.test_files = Dir.glob('test/**/*')
|
24
24
|
|
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: 0.20.8.
|
4
|
+
version: 0.20.8.3
|
5
5
|
platform: x86_64-darwin-20
|
6
6
|
authors:
|
7
7
|
- Firas al-Khalil
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- ext/tree_sitter/query_match.c
|
136
136
|
- ext/tree_sitter/query_predicate_step.c
|
137
137
|
- ext/tree_sitter/range.c
|
138
|
+
- ext/tree_sitter/repo.rb
|
138
139
|
- ext/tree_sitter/symbol_type.c
|
139
140
|
- ext/tree_sitter/tree.c
|
140
141
|
- ext/tree_sitter/tree_cursor.c
|