ruby_tree_sitter 0.20.8.1-x86_64-darwin-20 → 0.20.8.2-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/README.md +44 -11
- data/ext/tree_sitter/extconf.rb +65 -46
- data/ext/tree_sitter/logger.c +3 -3
- data/lib/tree_sitter/node.rb +0 -1
- data/lib/tree_sitter/tree_sitter.bundle +0 -0
- data/lib/tree_sitter/version.rb +2 -1
- data/test/tree_sitter/js_test.rb +48 -0
- data/test/tree_sitter/language_test.rb +6 -1
- data/test/tree_sitter/logger_test.rb +1 -0
- data/tree_sitter.gemspec +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b842a2305f9adfe075436d7fc21572e90ccf498419cf686f5a705110da630d1
|
4
|
+
data.tar.gz: 352cc3aa0d0d3ef67e60aeb023b633c400e9bb77f674695f729a5fc187cb2555
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e001b5024326bb8bbcf8083b27982cdd6aff01a3671c5fbb454f519d90899bc20ba4cf67a465e932904243efaeca51077445895f0ec489ced6767e059083af02
|
7
|
+
data.tar.gz: 6d4256ab4da4fe855c20bff4340f90869a7cfc414b3e2a30c6c1325c47159ef184fcb94f356dfd5792194e332b1fcada85991d8a2c3a57f502daae63693c7e5d
|
data/README.md
CHANGED
@@ -85,24 +85,47 @@ brew install tree-sitter
|
|
85
85
|
|
86
86
|
## Install
|
87
87
|
|
88
|
-
|
88
|
+
From [rubygems](https://rubygems.org/gems/ruby_tree_sitter), in your `Gemfile`:
|
89
89
|
|
90
|
-
|
90
|
+
```ruby
|
91
|
+
gem 'ruby_tree_sitter', '~> 0.20.8.1'
|
92
|
+
```
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
Or manually:
|
95
|
+
|
96
|
+
```sh
|
97
|
+
gem install ruby_tree_sitter
|
98
|
+
```
|
97
99
|
|
98
|
-
|
100
|
+
Or from `git` sources, which will compile on installation:
|
99
101
|
|
100
102
|
```ruby
|
101
|
-
gem '
|
103
|
+
gem 'ruby_tree_sitter', git: 'https://github.com/Faveod/ruby-tree-sitter'
|
104
|
+
```
|
105
|
+
|
106
|
+
### Disable system libraries
|
107
|
+
|
108
|
+
To install with `--disable-sys-lib`, you can either:
|
109
|
+
|
110
|
+
```sh
|
111
|
+
gem install ruby_tree_sitter -- --disable-sys-libs
|
102
112
|
```
|
103
113
|
|
104
|
-
|
105
|
-
|
114
|
+
Or via bundle:
|
115
|
+
|
116
|
+
```sh
|
117
|
+
bundle config set build.ruby_tree_sitter --disable-sys-libs
|
118
|
+
```
|
119
|
+
|
120
|
+
### No compilation
|
121
|
+
|
122
|
+
If you don't want to install from `rubygems`, `git`, or if you don't want to
|
123
|
+
compile on install, then download a native gem from this repository's
|
124
|
+
[releases](https://github.com/Faveod/ruby-tree-sitter/releases), or you can
|
125
|
+
compile it yourself (see [Build from
|
126
|
+
source](docs/Development.md#build-from-source) .)
|
127
|
+
|
128
|
+
In that case, you'd have to point your `Gemfile` to the `gem` as such:
|
106
129
|
|
107
130
|
``` ruby
|
108
131
|
gem 'tree_sitter', path: 'path/to/native/tree_sitter.gem'
|
@@ -118,6 +141,16 @@ You will have to install parsers yourself, either by:
|
|
118
141
|
[Faveod/tree-sitter-parsers](https://github.com/Faveod/tree-sitter-parsers)
|
119
142
|
which supports numerous architectures.
|
120
143
|
|
144
|
+
### A note on static vs dynamic linking
|
145
|
+
|
146
|
+
This extension will statically link against a downloaded version of
|
147
|
+
`tree-sitter` when you use the `--disable-sys-lib`. So any installed version of
|
148
|
+
`tree-sitter` will not be loaded.
|
149
|
+
|
150
|
+
The native gems are also statically linked.
|
151
|
+
|
152
|
+
All other methods will dynamically link against the installed `tree-sitter`.
|
153
|
+
|
121
154
|
## Examples
|
122
155
|
|
123
156
|
See `examples` directory.
|
data/ext/tree_sitter/extconf.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'mkmf'
|
2
4
|
require 'pathname'
|
3
5
|
|
6
|
+
require_relative 'repo'
|
7
|
+
|
4
8
|
# ################################## #
|
5
9
|
# Some helpers #
|
6
10
|
# ################################## #
|
@@ -14,71 +18,88 @@ def system_tree_sitter?
|
|
14
18
|
enable_config('sys-libs', true)
|
15
19
|
end
|
16
20
|
|
17
|
-
def sh cmd
|
18
|
-
if !system(cmd)
|
19
|
-
abort <<~MSG
|
20
|
-
|
21
|
-
Failed to run: #{cmd}
|
22
|
-
|
23
|
-
exiting…
|
24
|
-
|
25
|
-
MSG
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
21
|
def env_var_on?(var)
|
30
22
|
%w[1 on true t yes y].include?(ENV.fetch(var, '').downcase)
|
31
23
|
end
|
32
24
|
|
33
25
|
# ################################## #
|
34
|
-
#
|
35
|
-
# #
|
36
|
-
# OR #
|
37
|
-
# #
|
38
|
-
# Downloaded libs #
|
26
|
+
# System lib vs Downloaded lib #
|
39
27
|
# ################################## #
|
40
28
|
|
41
29
|
dir_include, dir_lib =
|
42
30
|
if system_tree_sitter?
|
43
|
-
[
|
44
|
-
|
31
|
+
[
|
32
|
+
%w[/opt/include /opt/local/include /usr/include /usr/local/include],
|
33
|
+
%w[/opt/lib /opt/local/lib /usr/lib /usr/local/lib]
|
34
|
+
]
|
45
35
|
else
|
46
|
-
|
47
|
-
if !
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
sh "curl -L https://github.com/tree-sitter/tree-sitter/archive/refs/tags/v#{TreeSitter::VERSION}.zip -o tree-sitter-v#{TreeSitter::VERSION}.zip"
|
57
|
-
sh "unzip -q tree-sitter-v#{TreeSitter::VERSION}.zip"
|
58
|
-
else
|
59
|
-
abort('Could not find `tar` or `zip` (and `git` was not found!)')
|
60
|
-
end
|
61
|
-
else
|
62
|
-
abort('Could not find `git` or `curl` to download tree-sitter and build from sources.')
|
63
|
-
end
|
36
|
+
repo = TreeSitter::Repo.new
|
37
|
+
if !repo.download
|
38
|
+
msg = <<~MSG
|
39
|
+
|
40
|
+
Could not fetch tree-sitter sources:
|
41
|
+
|
42
|
+
#{repo.exe.map { |k, v| "#{k}: #{v}" }.join("\n")}
|
43
|
+
|
44
|
+
MSG
|
45
|
+
abort(msg)
|
64
46
|
end
|
65
47
|
|
66
48
|
# We need to make sure we're selecting the proper toolchain.
|
67
49
|
# Especially needed for corss-compilation.
|
68
50
|
ENV.store('CC', RbConfig::CONFIG['CC'])
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
[[src / 'lib' / 'include'], [src.to_s]]
|
51
|
+
repo.compile
|
52
|
+
repo.keep_static_lib
|
53
|
+
repo.include_and_lib_dirs
|
74
54
|
end
|
75
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
|
+
|
76
98
|
# ################################## #
|
77
99
|
# Generate Makefile #
|
78
100
|
# ################################## #
|
79
101
|
|
80
102
|
header = find_header('tree_sitter/api.h', *dir_include)
|
81
|
-
|
82
103
|
library = find_library('tree-sitter', # libtree-sitter
|
83
104
|
'ts_parser_new', # a symbol
|
84
105
|
*dir_lib)
|
@@ -100,9 +121,7 @@ if !header || !library
|
|
100
121
|
MSG
|
101
122
|
end
|
102
123
|
|
103
|
-
if env_var_on?('TREE_SITTER_PEDANTIC')
|
104
|
-
cflags << '-Werror'
|
105
|
-
end
|
124
|
+
cflags << '-Werror' if env_var_on?('TREE_SITTER_PEDANTIC')
|
106
125
|
|
107
126
|
if env_var_on?('DEBUG')
|
108
127
|
cflags << '-fbounds-check'
|
data/ext/tree_sitter/logger.c
CHANGED
@@ -61,12 +61,12 @@ static void logger_payload_set(logger_t *logger, VALUE value) {
|
|
61
61
|
if (rb_respond_to(logger->payload, rb_intern("printf"))) {
|
62
62
|
logger->data.log = logger_log_printf;
|
63
63
|
} else if (rb_respond_to(logger->payload, rb_intern("puts"))) {
|
64
|
-
logger->data.log =
|
64
|
+
logger->data.log = logger_log_puts;
|
65
65
|
} else {
|
66
|
-
logger->data.log =
|
66
|
+
logger->data.log = logger_log_write;
|
67
67
|
}
|
68
68
|
} else if (!NIL_P(logger->payload)) {
|
69
|
-
logger->data.log =
|
69
|
+
logger->data.log = logger_log_write;
|
70
70
|
}
|
71
71
|
}
|
72
72
|
|
data/lib/tree_sitter/node.rb
CHANGED
Binary file
|
data/lib/tree_sitter/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../test_helper'
|
4
|
+
|
5
|
+
js = TreeSitter.lang('javascript')
|
6
|
+
parser = TreeSitter::Parser.new
|
7
|
+
parser.language = js
|
8
|
+
|
9
|
+
program = <<~JS
|
10
|
+
let a = 42;
|
11
|
+
JS
|
12
|
+
|
13
|
+
describe 'loading a language' do
|
14
|
+
before do
|
15
|
+
parser.reset
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'must set/get the same language' do
|
19
|
+
parser.language = js
|
20
|
+
assert_equal js, parser.language
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'parse_string' do
|
25
|
+
before do
|
26
|
+
parser.reset
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'must parse nil' do
|
30
|
+
res = parser.parse_string(nil, nil)
|
31
|
+
assert_nil res
|
32
|
+
end
|
33
|
+
|
34
|
+
[
|
35
|
+
['empty', '', 0],
|
36
|
+
['valid', program, 1],
|
37
|
+
# ['invalid', margorp, 3]
|
38
|
+
].each do |q, p, c|
|
39
|
+
it "must parse #{q} programs" do
|
40
|
+
res = parser.parse_string(nil, p)
|
41
|
+
assert_instance_of TreeSitter::Tree, res
|
42
|
+
|
43
|
+
root = res.root_node
|
44
|
+
assert_instance_of TreeSitter::Node, root
|
45
|
+
assert_equal c, root.child_count
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -27,7 +27,12 @@ describe 'language' do
|
|
27
27
|
if p = ENV.fetch('TREE_SITTER_PARSERS', nil)
|
28
28
|
Pathname(p) / "libtree-sitter-ruby.#{TreeSitter.ext}"
|
29
29
|
else
|
30
|
-
Pathname('tree-sitter-parsers') /
|
30
|
+
downloaded = Pathname('tree-sitter-parsers') / "libtree-sitter-ruby.#{TreeSitter.ext}"
|
31
|
+
if !downloaded.exist?
|
32
|
+
Pathname('tree-sitter-parsers') / "ruby" / "libtree-sitter-ruby.#{TreeSitter.ext}"
|
33
|
+
else
|
34
|
+
downloaded
|
35
|
+
end
|
31
36
|
end
|
32
37
|
ll = TreeSitter::Language.load('ruby', path)
|
33
38
|
assert ll.field_count.positive?
|
@@ -62,6 +62,7 @@ describe 'logging' do
|
|
62
62
|
backend = StringIO.new
|
63
63
|
parser.logger = TreeSitter::Logger.new(backend, "%s#{delim}%s")
|
64
64
|
parser.parse_string(nil, program)
|
65
|
+
refute_empty backend.string, 'the backend should be filled with logs'
|
65
66
|
backend.each_line do |l|
|
66
67
|
assert (/#{delim}/ =~ l), 'delimiter must be in every single line'
|
67
68
|
end
|
data/tree_sitter.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
lib = File.expand_path('lib', __dir__)
|
4
|
-
$LOAD_PATH.unshift(lib)
|
4
|
+
$LOAD_PATH.unshift(lib) if !$LOAD_PATH.include?(lib)
|
5
5
|
|
6
6
|
require 'tree_sitter/version'
|
7
7
|
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.version = TreeSitter::VERSION
|
18
18
|
|
19
19
|
spec.extensions = %(ext/tree_sitter/extconf.rb)
|
20
|
-
spec.files = %w
|
20
|
+
spec.files = %w[LICENSE README.md tree_sitter.gemspec]
|
21
21
|
spec.files += Dir.glob('ext/**/*.[ch]')
|
22
22
|
spec.files += Dir.glob('lib/**/*.rb')
|
23
23
|
spec.test_files = Dir.glob('test/**/*')
|
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.2
|
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-
|
11
|
+
date: 2023-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/tree_sitter/version.rb
|
147
147
|
- test/README.md
|
148
148
|
- test/test_helper.rb
|
149
|
+
- test/tree_sitter/js_test.rb
|
149
150
|
- test/tree_sitter/language_test.rb
|
150
151
|
- test/tree_sitter/logger_test.rb
|
151
152
|
- test/tree_sitter/node_test.rb
|
@@ -183,6 +184,7 @@ summary: Ruby bindings for Tree-Sitter
|
|
183
184
|
test_files:
|
184
185
|
- test/README.md
|
185
186
|
- test/test_helper.rb
|
187
|
+
- test/tree_sitter/js_test.rb
|
186
188
|
- test/tree_sitter/language_test.rb
|
187
189
|
- test/tree_sitter/logger_test.rb
|
188
190
|
- test/tree_sitter/node_test.rb
|