syntax_tree-rbs 0.5.0 → 1.0.0
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/.github/dependabot.yml +4 -0
- data/.github/workflows/auto-merge.yml +22 -0
- data/.github/workflows/main.yml +6 -17
- data/CHANGELOG.md +20 -1
- data/Gemfile.lock +9 -11
- data/gemfiles/rbs3.gemfile +7 -0
- data/lib/syntax_tree/rbs/entrypoints.rb +8 -8
- data/lib/syntax_tree/rbs/format.rb +29 -24
- data/lib/syntax_tree/rbs/pretty_print.rb +20 -14
- data/lib/syntax_tree/rbs/shims.rb +51 -18
- data/lib/syntax_tree/rbs/version.rb +1 -1
- data/lib/syntax_tree/rbs.rb +6 -6
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b66221375118043b0ba6f425de966904df6a558be4e2d07f67455947de1cc55
|
4
|
+
data.tar.gz: e6e0e6df40192b49c6e1dc073a55803bcdebb2523024bdf7f6a71ebe6736f93f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0253f026e5248ec173de6c2f135f7b60135655c55883c94767ba5217f73066f45e7c0eefeff4205208a61112ea8ec1b857416023831f14487b9483a579e04a4c
|
7
|
+
data.tar.gz: c2009e30dafd9c04b95f688a9353d2b20f947a6d9b9f7f98d58b71bf92a91c8c843947b85d96274777726124272f1fae0591f24536c53517d7af7c96e9918f79
|
data/.github/dependabot.yml
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
name: Dependabot auto-merge
|
2
|
+
on: pull_request
|
3
|
+
|
4
|
+
permissions:
|
5
|
+
contents: write
|
6
|
+
pull-requests: write
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
dependabot:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
if: ${{ github.actor == 'dependabot[bot]' }}
|
12
|
+
steps:
|
13
|
+
- name: Dependabot metadata
|
14
|
+
id: metadata
|
15
|
+
uses: dependabot/fetch-metadata@v1.3.6
|
16
|
+
with:
|
17
|
+
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
18
|
+
- name: Enable auto-merge for Dependabot PRs
|
19
|
+
run: gh pr merge --auto --merge "$PR_URL"
|
20
|
+
env:
|
21
|
+
PR_URL: ${{github.event.pull_request.html_url}}
|
22
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
data/.github/workflows/main.yml
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
name: Main
|
2
|
+
|
2
3
|
on:
|
3
4
|
- push
|
4
|
-
-
|
5
|
+
- pull_request
|
6
|
+
|
5
7
|
jobs:
|
6
8
|
ci:
|
7
9
|
strategy:
|
8
10
|
fail-fast: false
|
9
11
|
matrix:
|
10
12
|
ruby:
|
11
|
-
- '2.7.
|
13
|
+
- '2.7.0'
|
12
14
|
- '3.0'
|
13
15
|
- '3.1'
|
16
|
+
- '3.2'
|
14
17
|
gemfile:
|
15
18
|
- rbs1
|
16
19
|
- rbs2
|
20
|
+
- rbs3
|
17
21
|
name: CI
|
18
22
|
runs-on: ubuntu-latest
|
19
23
|
env:
|
20
24
|
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
21
|
-
CI: true
|
22
25
|
steps:
|
23
26
|
- uses: actions/checkout@master
|
24
27
|
- uses: ruby/setup-ruby@v1
|
@@ -29,17 +32,3 @@ jobs:
|
|
29
32
|
run: |
|
30
33
|
bundle exec rake test
|
31
34
|
bundle exec rake stree:check
|
32
|
-
automerge:
|
33
|
-
name: AutoMerge
|
34
|
-
needs: ci
|
35
|
-
runs-on: ubuntu-latest
|
36
|
-
if: github.event_name == 'pull_request_target' && github.actor == 'dependabot[bot]'
|
37
|
-
steps:
|
38
|
-
- uses: actions/github-script@v3
|
39
|
-
with:
|
40
|
-
script: |
|
41
|
-
github.pulls.merge({
|
42
|
-
owner: context.payload.repository.owner.login,
|
43
|
-
repo: context.payload.repository.name,
|
44
|
-
pull_number: context.payload.pull_request.number
|
45
|
-
})
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.0] - 2023-03-07
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Support for RBS 3.
|
14
|
+
|
15
|
+
### Changed
|
16
|
+
|
17
|
+
- The `visit_alias_declaration` method has been renamed to `visit_type_alias` to better reflect RBS 3.
|
18
|
+
- The `visit_alias_member` method has been renamed to `visit_alias` to better reflect RBS 3.
|
19
|
+
|
20
|
+
## [0.5.1] - 2022-09-03
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Ruby 2.7.0 is now supported, not just 2.7.3 and above. This allows usage on Ubuntu 20.04 by default.
|
25
|
+
|
9
26
|
## [0.5.0] - 2022-07-07
|
10
27
|
|
11
28
|
### Added
|
@@ -42,7 +59,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
|
|
42
59
|
|
43
60
|
- 🎉 Initial release! 🎉
|
44
61
|
|
45
|
-
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/
|
62
|
+
[unreleased]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v1.0.0...HEAD
|
63
|
+
[1.0.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.5.1...v1.0.0
|
64
|
+
[0.5.1]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.5.0...v0.5.1
|
46
65
|
[0.5.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.4.0...v0.5.0
|
47
66
|
[0.4.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.3.0...v0.4.0
|
48
67
|
[0.3.0]: https://github.com/ruby-syntax-tree/syntax_tree-rbs/compare/v0.2.0...v0.3.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
syntax_tree-rbs (0.
|
4
|
+
syntax_tree-rbs (1.0.0)
|
5
5
|
prettier_print
|
6
6
|
rbs
|
7
7
|
syntax_tree (>= 2.0.1)
|
@@ -10,23 +10,21 @@ GEM
|
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
12
|
docile (1.4.0)
|
13
|
-
minitest (5.
|
14
|
-
prettier_print (
|
13
|
+
minitest (5.18.0)
|
14
|
+
prettier_print (1.2.0)
|
15
15
|
rake (13.0.6)
|
16
|
-
rbs (
|
17
|
-
simplecov (0.
|
16
|
+
rbs (3.0.3)
|
17
|
+
simplecov (0.22.0)
|
18
18
|
docile (~> 1.1)
|
19
19
|
simplecov-html (~> 0.11)
|
20
20
|
simplecov_json_formatter (~> 0.1)
|
21
21
|
simplecov-html (0.12.3)
|
22
22
|
simplecov_json_formatter (0.1.4)
|
23
|
-
syntax_tree (
|
24
|
-
prettier_print
|
23
|
+
syntax_tree (6.0.2)
|
24
|
+
prettier_print (>= 1.2.0)
|
25
25
|
|
26
26
|
PLATFORMS
|
27
|
-
|
28
|
-
x86_64-darwin-21
|
29
|
-
x86_64-linux
|
27
|
+
arm64-darwin-21
|
30
28
|
|
31
29
|
DEPENDENCIES
|
32
30
|
bundler
|
@@ -36,4 +34,4 @@ DEPENDENCIES
|
|
36
34
|
syntax_tree-rbs!
|
37
35
|
|
38
36
|
BUNDLED WITH
|
39
|
-
2.3.
|
37
|
+
2.3.24
|
@@ -48,13 +48,6 @@ module RBS
|
|
48
48
|
include SyntaxTree::RBS::Entrypoints
|
49
49
|
end
|
50
50
|
|
51
|
-
# type foo = String
|
52
|
-
class Alias
|
53
|
-
def accept(visitor)
|
54
|
-
visitor.visit_alias_declaration(self)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
51
|
# class Foo end
|
59
52
|
class Class
|
60
53
|
def accept(visitor)
|
@@ -89,6 +82,13 @@ module RBS
|
|
89
82
|
visitor.visit_module_declaration(self)
|
90
83
|
end
|
91
84
|
end
|
85
|
+
|
86
|
+
# type foo = String
|
87
|
+
class TypeAlias
|
88
|
+
def accept(visitor)
|
89
|
+
visitor.visit_type_alias(self)
|
90
|
+
end
|
91
|
+
end
|
92
92
|
end
|
93
93
|
|
94
94
|
module Members
|
@@ -100,7 +100,7 @@ module RBS
|
|
100
100
|
# alias self.foo self.bar
|
101
101
|
class Alias
|
102
102
|
def accept(visitor)
|
103
|
-
visitor.
|
103
|
+
visitor.visit_alias(self)
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
@@ -13,26 +13,8 @@ module SyntaxTree
|
|
13
13
|
q.text(node.to_s)
|
14
14
|
end
|
15
15
|
|
16
|
-
# Visit a RBS::AST::Declarations::Alias node.
|
17
|
-
def visit_alias_declaration(node)
|
18
|
-
print_comment(node)
|
19
|
-
print_annotations(node)
|
20
|
-
|
21
|
-
q.group do
|
22
|
-
q.text("type ")
|
23
|
-
visit(node.name)
|
24
|
-
q.text(" =")
|
25
|
-
q.group do
|
26
|
-
q.indent do
|
27
|
-
q.breakable
|
28
|
-
visit(node.type)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
16
|
# Visit a RBS::AST::Members::Alias node.
|
35
|
-
def
|
17
|
+
def visit_alias(node)
|
36
18
|
print_comment(node)
|
37
19
|
print_annotations(node)
|
38
20
|
|
@@ -299,9 +281,9 @@ module SyntaxTree
|
|
299
281
|
)
|
300
282
|
q.text(":")
|
301
283
|
|
302
|
-
if node.
|
284
|
+
if node.overloads.length == 1 && !node.overloading?
|
303
285
|
q.text(" ")
|
304
|
-
|
286
|
+
print_method_overload(node.overloads.first)
|
305
287
|
else
|
306
288
|
separator =
|
307
289
|
lambda do
|
@@ -312,11 +294,11 @@ module SyntaxTree
|
|
312
294
|
q.group do
|
313
295
|
q.indent do
|
314
296
|
q.breakable
|
315
|
-
q.seplist(node.
|
316
|
-
|
297
|
+
q.seplist(node.overloads, separator) do |overload|
|
298
|
+
print_method_overload(overload)
|
317
299
|
end
|
318
300
|
|
319
|
-
if node.
|
301
|
+
if node.overloading?
|
320
302
|
separator.call
|
321
303
|
q.text("...")
|
322
304
|
end
|
@@ -452,6 +434,24 @@ module SyntaxTree
|
|
452
434
|
end
|
453
435
|
end
|
454
436
|
|
437
|
+
# Visit a RBS::AST::Declarations::TypeAlias node.
|
438
|
+
def visit_type_alias(node)
|
439
|
+
print_comment(node)
|
440
|
+
print_annotations(node)
|
441
|
+
|
442
|
+
q.group do
|
443
|
+
q.text("type ")
|
444
|
+
visit(node.name)
|
445
|
+
q.text(" =")
|
446
|
+
q.group do
|
447
|
+
q.indent do
|
448
|
+
q.breakable
|
449
|
+
visit(node.type)
|
450
|
+
end
|
451
|
+
end
|
452
|
+
end
|
453
|
+
end
|
454
|
+
|
455
455
|
# Visit a RBS::TypeName node.
|
456
456
|
def visit_type_name(node)
|
457
457
|
q.text(node.to_s)
|
@@ -550,6 +550,11 @@ module SyntaxTree
|
|
550
550
|
end
|
551
551
|
end
|
552
552
|
|
553
|
+
# (T t) -> void
|
554
|
+
def print_method_overload(node)
|
555
|
+
print_method_signature(node.method_type)
|
556
|
+
end
|
557
|
+
|
553
558
|
# (T t) -> void
|
554
559
|
def print_method_signature(node)
|
555
560
|
q.group do
|
@@ -13,18 +13,8 @@ module SyntaxTree
|
|
13
13
|
q.text("(#{node.class.name.downcase})")
|
14
14
|
end
|
15
15
|
|
16
|
-
# Visit a RBS::AST::Declarations::Alias node.
|
17
|
-
def visit_alias_declaration(node)
|
18
|
-
group("constant") do
|
19
|
-
print_comment(node)
|
20
|
-
print_annotations(node)
|
21
|
-
visit_field("name", node.name)
|
22
|
-
visit_field("type", node.type)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
16
|
# Visit a RBS::AST::Members::Alias node.
|
27
|
-
def
|
17
|
+
def visit_alias(node)
|
28
18
|
group("alias") do
|
29
19
|
print_comment(node)
|
30
20
|
print_annotations(node)
|
@@ -209,12 +199,14 @@ module SyntaxTree
|
|
209
199
|
pp_field("kind", node.kind)
|
210
200
|
pp_field("name", node.name)
|
211
201
|
pp_field("visibility", node.visibility) if node.visibility
|
212
|
-
bool_field("overload") if node.
|
202
|
+
bool_field("overload") if node.overloading?
|
213
203
|
|
214
204
|
q.breakable
|
215
|
-
q.text("
|
205
|
+
q.text("overloads=")
|
216
206
|
q.group(2, "[", "]") do
|
217
|
-
q.seplist(node.
|
207
|
+
q.seplist(node.overloads) do |overload|
|
208
|
+
print_method_overload(overload)
|
209
|
+
end
|
218
210
|
end
|
219
211
|
end
|
220
212
|
end
|
@@ -293,6 +285,16 @@ module SyntaxTree
|
|
293
285
|
group("tuple") { pp_field("types", node.types) }
|
294
286
|
end
|
295
287
|
|
288
|
+
# Visit a RBS::AST::Declarations::TypeAlias node.
|
289
|
+
def visit_type_alias(node)
|
290
|
+
group("constant") do
|
291
|
+
print_comment(node)
|
292
|
+
print_annotations(node)
|
293
|
+
visit_field("name", node.name)
|
294
|
+
visit_field("type", node.type)
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
296
298
|
# Visit a RBS::TypeName node.
|
297
299
|
def visit_type_name(node)
|
298
300
|
group("type-name") do
|
@@ -404,6 +406,10 @@ module SyntaxTree
|
|
404
406
|
end
|
405
407
|
end
|
406
408
|
|
409
|
+
def print_method_overload(node)
|
410
|
+
print_method_signature(node.method_type)
|
411
|
+
end
|
412
|
+
|
407
413
|
def print_method_signature(node)
|
408
414
|
if node.respond_to?(:type_params) && node.type_params.any?
|
409
415
|
q.breakable
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# If we're using RBS 1, then we need to include these monkey-patches to have a
|
4
|
+
# consistent interface in RBS 2+.
|
5
|
+
if RBS::VERSION < "2.0.0"
|
4
6
|
require "delegate"
|
5
7
|
|
6
|
-
|
7
|
-
# information for type params. So here we wrap them up in order to maintain the
|
8
|
-
# same API.
|
9
|
-
module ShimTypeParams
|
8
|
+
module RBS::AST::Declarations
|
10
9
|
class ShimTypeParam < SimpleDelegator
|
11
10
|
def unchecked?
|
12
11
|
false
|
@@ -17,29 +16,63 @@ if defined?(RBS::AST::Declarations::ModuleTypeParams)
|
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
#
|
21
|
-
|
22
|
-
|
19
|
+
# Previously there were specialized types that didn't include some
|
20
|
+
# additional information for type params. So here we wrap them up in order
|
21
|
+
# to maintain the same API.
|
22
|
+
module ShimTypeParams
|
23
|
+
def type_params
|
24
|
+
super.params.map { |param| ShimTypeParam.new(param) }
|
25
|
+
end
|
23
26
|
end
|
24
|
-
end
|
25
27
|
|
26
|
-
module RBS::AST::Declarations
|
27
28
|
Alias.prepend(ShimTypeParams)
|
28
29
|
Class.prepend(ShimTypeParams)
|
29
30
|
Interface.prepend(ShimTypeParams)
|
30
31
|
Module.prepend(ShimTypeParams)
|
31
32
|
end
|
32
|
-
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
module RBS::AST::Members::Attribute
|
35
|
+
def visibility
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class RBS::AST::Members::MethodDefinition
|
40
|
+
def visibility
|
41
|
+
end
|
38
42
|
end
|
39
43
|
end
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
|
45
|
+
# If we're using RBS 2, then we need to include these monkey-patches to have a
|
46
|
+
# consistent interface in RBS 3+.
|
47
|
+
if RBS::VERSION < "3.0.0"
|
48
|
+
class RBS::AST::Declarations::Alias
|
49
|
+
def accept(visitor)
|
50
|
+
visitor.visit_type_alias(self)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class RBS::AST::Members::MethodDefinition
|
55
|
+
class MethodOverloadShim
|
56
|
+
attr_reader :method_type
|
57
|
+
|
58
|
+
def initialize(method_type)
|
59
|
+
@method_type = method_type
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
alias overloading? overload?
|
64
|
+
|
65
|
+
def overloads
|
66
|
+
types.map { |method_type| MethodOverloadShim.new(method_type) }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
module SyntaxTree::RBS
|
71
|
+
class << self
|
72
|
+
undef parse
|
73
|
+
def parse(source)
|
74
|
+
Root.new(::RBS::Parser.parse_signature(source))
|
75
|
+
end
|
76
|
+
end
|
44
77
|
end
|
45
78
|
end
|
data/lib/syntax_tree/rbs.rb
CHANGED
@@ -4,9 +4,6 @@ require "prettier_print"
|
|
4
4
|
require "rbs"
|
5
5
|
require "syntax_tree"
|
6
6
|
|
7
|
-
require_relative "rbs/shims"
|
8
|
-
require_relative "rbs/version"
|
9
|
-
|
10
7
|
module SyntaxTree
|
11
8
|
module RBS
|
12
9
|
# This is the parent class of any of the visitors that we define in this
|
@@ -24,8 +21,8 @@ module SyntaxTree
|
|
24
21
|
class Formatter < PrettierPrint
|
25
22
|
attr_reader :source
|
26
23
|
|
27
|
-
def initialize(source,
|
28
|
-
super(
|
24
|
+
def initialize(source, *rest)
|
25
|
+
super(*rest)
|
29
26
|
@source = source
|
30
27
|
@force_parens = false
|
31
28
|
end
|
@@ -53,7 +50,8 @@ module SyntaxTree
|
|
53
50
|
end
|
54
51
|
|
55
52
|
def parse(source)
|
56
|
-
|
53
|
+
_, _, declarations = ::RBS::Parser.parse_signature(source)
|
54
|
+
Root.new(declarations)
|
57
55
|
end
|
58
56
|
|
59
57
|
def read(filepath)
|
@@ -65,6 +63,8 @@ module SyntaxTree
|
|
65
63
|
register_handler(".rbs", RBS)
|
66
64
|
end
|
67
65
|
|
66
|
+
require_relative "rbs/shims"
|
68
67
|
require_relative "rbs/entrypoints"
|
69
68
|
require_relative "rbs/format"
|
70
69
|
require_relative "rbs/pretty_print"
|
70
|
+
require_relative "rbs/version"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: syntax_tree-rbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Newton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prettier_print
|
@@ -116,6 +116,7 @@ extensions: []
|
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
118
|
- ".github/dependabot.yml"
|
119
|
+
- ".github/workflows/auto-merge.yml"
|
119
120
|
- ".github/workflows/main.yml"
|
120
121
|
- ".gitignore"
|
121
122
|
- CHANGELOG.md
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- bin/setup
|
131
132
|
- gemfiles/rbs1.gemfile
|
132
133
|
- gemfiles/rbs2.gemfile
|
134
|
+
- gemfiles/rbs3.gemfile
|
133
135
|
- lib/syntax_tree/rbs.rb
|
134
136
|
- lib/syntax_tree/rbs/entrypoints.rb
|
135
137
|
- lib/syntax_tree/rbs/format.rb
|
@@ -157,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
159
|
- !ruby/object:Gem::Version
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
|
-
rubygems_version: 3.3.
|
162
|
+
rubygems_version: 3.3.21
|
161
163
|
signing_key:
|
162
164
|
specification_version: 4
|
163
165
|
summary: Syntax Tree support for RBS
|