rbs 1.5.1 → 1.7.0.beta.1

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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +10 -0
  3. data/.github/workflows/ruby.yml +0 -4
  4. data/.gitignore +1 -0
  5. data/CHANGELOG.md +51 -0
  6. data/Gemfile +2 -0
  7. data/Rakefile +7 -22
  8. data/Steepfile +9 -1
  9. data/core/enumerator.rbs +1 -0
  10. data/core/io.rbs +3 -1
  11. data/core/kernel.rbs +4 -4
  12. data/core/trace_point.rbs +1 -1
  13. data/docs/collection.md +116 -0
  14. data/ext/rbs/extension/constants.c +140 -0
  15. data/ext/rbs/extension/constants.h +72 -0
  16. data/ext/rbs/extension/extconf.rb +3 -0
  17. data/ext/rbs/extension/lexer.c +1070 -0
  18. data/ext/rbs/extension/lexer.h +145 -0
  19. data/ext/rbs/extension/location.c +295 -0
  20. data/ext/rbs/extension/location.h +59 -0
  21. data/ext/rbs/extension/main.c +9 -0
  22. data/ext/rbs/extension/parser.c +2418 -0
  23. data/ext/rbs/extension/parser.h +23 -0
  24. data/ext/rbs/extension/parserstate.c +313 -0
  25. data/ext/rbs/extension/parserstate.h +141 -0
  26. data/ext/rbs/extension/rbs_extension.h +40 -0
  27. data/ext/rbs/extension/ruby_objs.c +585 -0
  28. data/ext/rbs/extension/ruby_objs.h +46 -0
  29. data/ext/rbs/extension/unescape.c +65 -0
  30. data/goodcheck.yml +1 -1
  31. data/lib/rbs/ast/comment.rb +0 -12
  32. data/lib/rbs/buffer.rb +4 -0
  33. data/lib/rbs/builtin_names.rb +1 -0
  34. data/lib/rbs/cli.rb +98 -10
  35. data/lib/rbs/collection/cleaner.rb +29 -0
  36. data/lib/rbs/collection/config/lockfile_generator.rb +95 -0
  37. data/lib/rbs/collection/config.rb +85 -0
  38. data/lib/rbs/collection/installer.rb +27 -0
  39. data/lib/rbs/collection/sources/git.rb +162 -0
  40. data/lib/rbs/collection/sources/rubygems.rb +40 -0
  41. data/lib/rbs/collection/sources/stdlib.rb +38 -0
  42. data/lib/rbs/collection/sources.rb +22 -0
  43. data/lib/rbs/collection.rb +13 -0
  44. data/lib/rbs/environment_loader.rb +12 -0
  45. data/lib/rbs/errors.rb +16 -1
  46. data/lib/rbs/location.rb +221 -217
  47. data/lib/rbs/location_aux.rb +108 -0
  48. data/lib/rbs/locator.rb +10 -7
  49. data/lib/rbs/parser_aux.rb +24 -0
  50. data/lib/rbs/repository.rb +13 -7
  51. data/lib/rbs/types.rb +2 -3
  52. data/lib/rbs/validator.rb +4 -1
  53. data/lib/rbs/version.rb +1 -1
  54. data/lib/rbs/writer.rb +4 -2
  55. data/lib/rbs.rb +4 -7
  56. data/rbs.gemspec +2 -1
  57. data/sig/ancestor_builder.rbs +2 -2
  58. data/sig/annotation.rbs +2 -2
  59. data/sig/builtin_names.rbs +1 -0
  60. data/sig/cli.rbs +5 -0
  61. data/sig/collection/cleaner.rbs +13 -0
  62. data/sig/collection/collections.rbs +112 -0
  63. data/sig/collection/config.rbs +69 -0
  64. data/sig/collection/installer.rbs +15 -0
  65. data/sig/collection.rbs +4 -0
  66. data/sig/comment.rbs +7 -7
  67. data/sig/constant_table.rbs +1 -1
  68. data/sig/declarations.rbs +9 -9
  69. data/sig/definition.rbs +1 -1
  70. data/sig/definition_builder.rbs +2 -2
  71. data/sig/environment_loader.rbs +3 -0
  72. data/sig/errors.rbs +30 -25
  73. data/sig/location.rbs +42 -79
  74. data/sig/locator.rbs +2 -2
  75. data/sig/members.rbs +7 -7
  76. data/sig/method_types.rbs +3 -3
  77. data/sig/parser.rbs +11 -21
  78. data/sig/polyfill.rbs +12 -3
  79. data/sig/repository.rbs +4 -0
  80. data/sig/types.rbs +45 -27
  81. data/sig/writer.rbs +1 -1
  82. data/stdlib/json/0/json.rbs +3 -3
  83. data/stdlib/objspace/0/objspace.rbs +406 -0
  84. data/stdlib/openssl/0/openssl.rbs +1 -1
  85. data/stdlib/tempfile/0/tempfile.rbs +270 -0
  86. data/steep/Gemfile.lock +10 -10
  87. metadata +43 -7
  88. data/lib/rbs/parser.rb +0 -3614
data/lib/rbs/location.rb CHANGED
@@ -1,217 +1,221 @@
1
- module RBS
2
- class Location
3
- attr_reader :buffer
4
- attr_reader :start_pos
5
- attr_reader :end_pos
6
-
7
- def initialize(buffer:, start_pos:, end_pos:)
8
- @buffer = buffer
9
- @start_pos = start_pos
10
- @end_pos = end_pos
11
- end
12
-
13
- def inspect
14
- "#<#{self.class}:#{self.__id__} @buffer=#{buffer.name}, @pos=#{start_pos}...#{end_pos}, source='#{source.lines.first}', start_line=#{start_line}, start_column=#{start_column}>"
15
- end
16
-
17
- def name
18
- buffer.name
19
- end
20
-
21
- def start_line
22
- start_loc[0]
23
- end
24
-
25
- def start_column
26
- start_loc[1]
27
- end
28
-
29
- def end_line
30
- end_loc[0]
31
- end
32
-
33
- def end_column
34
- end_loc[1]
35
- end
36
-
37
- def start_loc
38
- @start_loc ||= buffer.pos_to_loc(start_pos)
39
- end
40
-
41
- def end_loc
42
- @end_loc ||= buffer.pos_to_loc(end_pos)
43
- end
44
-
45
- def range
46
- start_pos...end_pos
47
- end
48
-
49
- def source
50
- @source ||= buffer.content[start_pos...end_pos] or raise
51
- end
52
-
53
- def to_s
54
- "#{name || "-"}:#{start_line}:#{start_column}...#{end_line}:#{end_column}"
55
- end
56
-
57
- def self.to_string(location, default: "*:*:*...*:*")
58
- location&.to_s || default
59
- end
60
-
61
- def ==(other)
62
- other.is_a?(Location) &&
63
- other.buffer == buffer &&
64
- other.start_pos == start_pos &&
65
- other.end_pos == end_pos
66
- end
67
-
68
- def +(other)
69
- if other
70
- raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
71
-
72
- self.class.new(buffer: buffer,
73
- start_pos: start_pos,
74
- end_pos: other.end_pos)
75
- else
76
- self
77
- end
78
- end
79
-
80
- def concat(*others)
81
- others.each { |other| self << other }
82
- self
83
- end
84
-
85
- def <<(other)
86
- if other
87
- raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
88
- @end_pos = other.end_pos
89
- @source = nil
90
- @end_loc = nil
91
- end
92
- self
93
- end
94
-
95
- def pred?(loc)
96
- loc.is_a?(Location) &&
97
- loc.name == name &&
98
- loc.start_pos == end_pos
99
- end
100
-
101
- def to_json(state = _ = nil)
102
- {
103
- start: {
104
- line: start_line,
105
- column: start_column
106
- },
107
- end: {
108
- line: end_line,
109
- column: end_column
110
- },
111
- buffer: {
112
- name: name&.to_s
113
- }
114
- }.to_json(state)
115
- end
116
-
117
- def with_children(required: {}, optional: {})
118
- # @type var required: Hash[Symbol, Range[Integer] | Location]
119
- # @type var optional: Hash[Symbol, Range[Integer] | Location | nil]
120
-
121
- this = WithChildren.new(buffer: buffer, start_pos: start_pos, end_pos: end_pos)
122
-
123
- req = required.transform_values do |value|
124
- case value
125
- when Location
126
- value.range
127
- else
128
- value
129
- end
130
- end
131
-
132
- opt = optional.transform_values do |value|
133
- case value
134
- when Location
135
- value.range
136
- else
137
- value
138
- end
139
- end
140
-
141
- this.required_children.merge!(req)
142
- this.optional_children.merge!(opt)
143
-
144
- this
145
- end
146
-
147
- class WithChildren < Location
148
- attr_reader :required_children, :optional_children
149
-
150
- def initialize(buffer:, start_pos:, end_pos:)
151
- super(buffer: buffer, start_pos: start_pos, end_pos: end_pos)
152
-
153
- @optional_children = {}
154
- @required_children = {}
155
- end
156
-
157
- def initialize_copy(from)
158
- required_children.merge!(from.required_children)
159
- optional_children.merge!(from.optional_children)
160
- self
161
- end
162
-
163
- def [](key)
164
- case
165
- when required_children.key?(_ = key)
166
- range = required_children[_ = key]
167
- Location.new(buffer: buffer, start_pos: range.begin, end_pos: range.end)
168
- when optional_children.key?(_ = key)
169
- range = required_children[_ = key] || optional_children[_ = key]
170
- if range
171
- Location.new(buffer: buffer, start_pos: range.begin, end_pos: range.end)
172
- end
173
- else
174
- raise "Unknown key given: `#{key}`"
175
- end
176
- end
177
-
178
- def merge_required(hash)
179
- this = dup
180
-
181
- h = hash.transform_values do |value|
182
- case value
183
- when Range
184
- value
185
- when Location
186
- value.range
187
- else
188
- raise
189
- end
190
- end
191
-
192
- this.required_children.merge!(h)
193
-
194
- this
195
- end
196
-
197
- def merge_optional(hash)
198
- this = dup
199
-
200
- h = hash.transform_values do |value|
201
- case value
202
- when Range
203
- value
204
- when Location
205
- value.range
206
- else
207
- nil
208
- end
209
- end
210
-
211
- this.optional_children.merge!(h)
212
-
213
- this
214
- end
215
- end
216
- end
217
- end
1
+ # module RBS
2
+ # class Location
3
+ # attr_reader :buffer
4
+ # attr_reader :start_pos
5
+ # attr_reader :end_pos
6
+
7
+ # def initialize(buffer, start_pos, end_pos)
8
+ # @buffer = buffer
9
+ # @start_pos = start_pos
10
+ # @end_pos = end_pos
11
+ # end
12
+
13
+ # # def self.new(buffer_ = nil, start_pos_ = nil, end_pos_ = nil)
14
+ # # __skip__ = super(buffer_, start_pos_, end_pos_)
15
+ # # end
16
+
17
+ # # def inspect
18
+ # # "#<#{self.class}:#{self.__id__} @buffer=#{buffer.name}, @pos=#{start_pos}...#{end_pos}, source='#{source.lines.first}', start_line=#{start_line}, start_column=#{start_column}>"
19
+ # # end
20
+
21
+ # def name
22
+ # buffer.name
23
+ # end
24
+
25
+ # def start_line
26
+ # start_loc[0]
27
+ # end
28
+
29
+ # def start_column
30
+ # start_loc[1]
31
+ # end
32
+
33
+ # def end_line
34
+ # end_loc[0]
35
+ # end
36
+
37
+ # def end_column
38
+ # end_loc[1]
39
+ # end
40
+
41
+ # def start_loc
42
+ # @start_loc ||= buffer.pos_to_loc(start_pos)
43
+ # end
44
+
45
+ # def end_loc
46
+ # @end_loc ||= buffer.pos_to_loc(end_pos)
47
+ # end
48
+
49
+ # def range
50
+ # start_pos...end_pos
51
+ # end
52
+
53
+ # def source
54
+ # @source ||= buffer.content[start_pos...end_pos] or raise
55
+ # end
56
+
57
+ # def to_s
58
+ # "#{name || "-"}:#{start_line}:#{start_column}...#{end_line}:#{end_column}"
59
+ # end
60
+
61
+ # def self.to_string(location, default: "*:*:*...*:*")
62
+ # location&.to_s || default
63
+ # end
64
+
65
+ # def ==(other)
66
+ # other.is_a?(Location) &&
67
+ # other.buffer == buffer &&
68
+ # other.start_pos == start_pos &&
69
+ # other.end_pos == end_pos
70
+ # end
71
+
72
+ # def +(other)
73
+ # if other
74
+ # raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
75
+
76
+ # self.class.new(buffer: buffer,
77
+ # start_pos: start_pos,
78
+ # end_pos: other.end_pos)
79
+ # else
80
+ # self
81
+ # end
82
+ # end
83
+
84
+ # def concat(*others)
85
+ # others.each { |other| self << other }
86
+ # self
87
+ # end
88
+
89
+ # def <<(other)
90
+ # if other
91
+ # raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
92
+ # @end_pos = other.end_pos
93
+ # @source = nil
94
+ # @end_loc = nil
95
+ # end
96
+ # self
97
+ # end
98
+
99
+ # def pred?(loc)
100
+ # loc.is_a?(Location) &&
101
+ # loc.name == name &&
102
+ # loc.start_pos == end_pos
103
+ # end
104
+
105
+ # def to_json(state = _ = nil)
106
+ # {
107
+ # start: {
108
+ # line: start_line,
109
+ # column: start_column
110
+ # },
111
+ # end: {
112
+ # line: end_line,
113
+ # column: end_column
114
+ # },
115
+ # buffer: {
116
+ # name: name&.to_s
117
+ # }
118
+ # }.to_json(state)
119
+ # end
120
+
121
+ # def with_children(required: {}, optional: {})
122
+ # # @type var required: Hash[Symbol, Range[Integer] | Location]
123
+ # # @type var optional: Hash[Symbol, Range[Integer] | Location | nil]
124
+
125
+ # this = WithChildren.new(buffer: buffer, start_pos: start_pos, end_pos: end_pos)
126
+
127
+ # req = required.transform_values do |value|
128
+ # case value
129
+ # when Location
130
+ # value.range
131
+ # else
132
+ # value
133
+ # end
134
+ # end
135
+
136
+ # opt = optional.transform_values do |value|
137
+ # case value
138
+ # when Location
139
+ # value.range
140
+ # else
141
+ # value
142
+ # end
143
+ # end
144
+
145
+ # this.required_children.merge!(req)
146
+ # this.optional_children.merge!(opt)
147
+
148
+ # this
149
+ # end
150
+
151
+ # class WithChildren < Location
152
+ # attr_reader :required_children, :optional_children
153
+
154
+ # def initialize(buffer, start_pos, end_pos)
155
+ # super(buffer, start_pos, end_pos)
156
+
157
+ # @optional_children = {}
158
+ # @required_children = {}
159
+ # end
160
+
161
+ # def initialize_copy(from)
162
+ # required_children.merge!(from.required_children)
163
+ # optional_children.merge!(from.optional_children)
164
+ # self
165
+ # end
166
+
167
+ # def [](key)
168
+ # case
169
+ # when required_children.key?(_ = key)
170
+ # range = required_children[_ = key]
171
+ # Location.new(buffer: buffer, start_pos: range.begin, end_pos: range.end)
172
+ # when optional_children.key?(_ = key)
173
+ # range = required_children[_ = key] || optional_children[_ = key]
174
+ # if range
175
+ # Location.new(buffer: buffer, start_pos: range.begin, end_pos: range.end)
176
+ # end
177
+ # else
178
+ # raise "Unknown key given: `#{key}`"
179
+ # end
180
+ # end
181
+
182
+ # def merge_required(hash)
183
+ # this = dup
184
+
185
+ # h = hash.transform_values do |value|
186
+ # case value
187
+ # when Range
188
+ # value
189
+ # when Location
190
+ # value.range
191
+ # else
192
+ # raise
193
+ # end
194
+ # end
195
+
196
+ # this.required_children.merge!(h)
197
+
198
+ # this
199
+ # end
200
+
201
+ # def merge_optional(hash)
202
+ # this = dup
203
+
204
+ # h = hash.transform_values do |value|
205
+ # case value
206
+ # when Range
207
+ # value
208
+ # when Location
209
+ # value.range
210
+ # else
211
+ # nil
212
+ # end
213
+ # end
214
+
215
+ # this.optional_children.merge!(h)
216
+
217
+ # this
218
+ # end
219
+ # end
220
+ # end
221
+ # end
@@ -0,0 +1,108 @@
1
+ module RBS
2
+ class Location
3
+ def inspect
4
+ rks = each_required_key.to_a
5
+ ops = each_optional_key.to_a.map {|x| "?#{x}" }
6
+ "#<#{self.class}:#{self.__id__} buffer=#{buffer.name}, start=#{start_line}:#{start_column}, pos=#{start_pos}...#{end_pos}, children=#{(rks + ops).join(",")} source='#{source.lines.first&.chomp}'>"
7
+ end
8
+
9
+ def name
10
+ buffer.name
11
+ end
12
+
13
+ def start_line
14
+ start_loc[0]
15
+ end
16
+
17
+ def start_column
18
+ start_loc[1]
19
+ end
20
+
21
+ def end_line
22
+ end_loc[0]
23
+ end
24
+
25
+ def end_column
26
+ end_loc[1]
27
+ end
28
+
29
+ def start_loc
30
+ @start_loc ||= begin
31
+ _start_loc || buffer.pos_to_loc(start_pos)
32
+ end
33
+ end
34
+
35
+ def end_loc
36
+ @end_loc ||= begin
37
+ _end_loc || buffer.pos_to_loc(end_pos)
38
+ end
39
+ end
40
+
41
+ def range
42
+ @range ||= start_pos...end_pos
43
+ end
44
+
45
+ def source
46
+ @source ||= buffer.content[range] or raise
47
+ end
48
+
49
+ def to_s
50
+ "#{name || "-"}:#{start_line}:#{start_column}...#{end_line}:#{end_column}"
51
+ end
52
+
53
+ def ==(other)
54
+ other.is_a?(Location) &&
55
+ other.buffer == buffer &&
56
+ other.start_pos == start_pos &&
57
+ other.end_pos == end_pos
58
+ end
59
+
60
+ def to_json(state = _ = nil)
61
+ {
62
+ start: {
63
+ line: start_line,
64
+ column: start_column
65
+ },
66
+ end: {
67
+ line: end_line,
68
+ column: end_column
69
+ },
70
+ buffer: {
71
+ name: name&.to_s
72
+ }
73
+ }.to_json(state)
74
+ end
75
+
76
+ def self.to_string(location, default: "*:*:*...*:*")
77
+ location&.to_s || default
78
+ end
79
+
80
+ def add_required_child(name, range)
81
+ _add_required_child(name, range.begin, range.end)
82
+ end
83
+
84
+ def add_optional_child(name, range)
85
+ if range
86
+ _add_optional_child(name, range.begin, range.end)
87
+ else
88
+ _add_optional_no_child(name);
89
+ end
90
+ end
91
+
92
+ def each_optional_key(&block)
93
+ if block
94
+ _optional_keys.uniq.each(&block)
95
+ else
96
+ enum_for(:each_optional_key)
97
+ end
98
+ end
99
+
100
+ def each_required_key(&block)
101
+ if block
102
+ _required_keys.uniq.each(&block)
103
+ else
104
+ enum_for(:each_required_key)
105
+ end
106
+ end
107
+ end
108
+ end