rbs 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +15 -0
- data/BSDL +22 -0
- data/CHANGELOG.md +9 -0
- data/COPYING +56 -0
- data/Gemfile +6 -0
- data/README.md +93 -0
- data/Rakefile +142 -0
- data/bin/annotate-with-rdoc +157 -0
- data/bin/console +14 -0
- data/bin/query-rdoc +103 -0
- data/bin/setup +10 -0
- data/bin/sort +89 -0
- data/bin/test_runner.rb +16 -0
- data/docs/CONTRIBUTING.md +97 -0
- data/docs/sigs.md +148 -0
- data/docs/stdlib.md +152 -0
- data/docs/syntax.md +528 -0
- data/exe/rbs +7 -0
- data/lib/rbs.rb +64 -0
- data/lib/rbs/ast/annotation.rb +27 -0
- data/lib/rbs/ast/comment.rb +27 -0
- data/lib/rbs/ast/declarations.rb +395 -0
- data/lib/rbs/ast/members.rb +362 -0
- data/lib/rbs/buffer.rb +50 -0
- data/lib/rbs/builtin_names.rb +55 -0
- data/lib/rbs/cli.rb +558 -0
- data/lib/rbs/constant.rb +26 -0
- data/lib/rbs/constant_table.rb +150 -0
- data/lib/rbs/definition.rb +170 -0
- data/lib/rbs/definition_builder.rb +919 -0
- data/lib/rbs/environment.rb +281 -0
- data/lib/rbs/environment_loader.rb +136 -0
- data/lib/rbs/environment_walker.rb +124 -0
- data/lib/rbs/errors.rb +187 -0
- data/lib/rbs/location.rb +102 -0
- data/lib/rbs/method_type.rb +123 -0
- data/lib/rbs/namespace.rb +91 -0
- data/lib/rbs/parser.y +1344 -0
- data/lib/rbs/prototype/rb.rb +553 -0
- data/lib/rbs/prototype/rbi.rb +587 -0
- data/lib/rbs/prototype/runtime.rb +381 -0
- data/lib/rbs/substitution.rb +46 -0
- data/lib/rbs/test.rb +26 -0
- data/lib/rbs/test/errors.rb +61 -0
- data/lib/rbs/test/hook.rb +294 -0
- data/lib/rbs/test/setup.rb +58 -0
- data/lib/rbs/test/spy.rb +325 -0
- data/lib/rbs/test/test_helper.rb +183 -0
- data/lib/rbs/test/type_check.rb +254 -0
- data/lib/rbs/type_name.rb +70 -0
- data/lib/rbs/types.rb +936 -0
- data/lib/rbs/variance_calculator.rb +138 -0
- data/lib/rbs/vendorer.rb +47 -0
- data/lib/rbs/version.rb +3 -0
- data/lib/rbs/writer.rb +269 -0
- data/lib/ruby/signature.rb +7 -0
- data/rbs.gemspec +46 -0
- data/stdlib/abbrev/abbrev.rbs +60 -0
- data/stdlib/base64/base64.rbs +71 -0
- data/stdlib/benchmark/benchmark.rbs +372 -0
- data/stdlib/builtin/array.rbs +1997 -0
- data/stdlib/builtin/basic_object.rbs +280 -0
- data/stdlib/builtin/binding.rbs +177 -0
- data/stdlib/builtin/builtin.rbs +45 -0
- data/stdlib/builtin/class.rbs +145 -0
- data/stdlib/builtin/comparable.rbs +116 -0
- data/stdlib/builtin/complex.rbs +400 -0
- data/stdlib/builtin/constants.rbs +37 -0
- data/stdlib/builtin/data.rbs +5 -0
- data/stdlib/builtin/deprecated.rbs +2 -0
- data/stdlib/builtin/dir.rbs +413 -0
- data/stdlib/builtin/encoding.rbs +607 -0
- data/stdlib/builtin/enumerable.rbs +404 -0
- data/stdlib/builtin/enumerator.rbs +260 -0
- data/stdlib/builtin/errno.rbs +781 -0
- data/stdlib/builtin/errors.rbs +582 -0
- data/stdlib/builtin/exception.rbs +194 -0
- data/stdlib/builtin/false_class.rbs +40 -0
- data/stdlib/builtin/fiber.rbs +68 -0
- data/stdlib/builtin/fiber_error.rbs +12 -0
- data/stdlib/builtin/file.rbs +1076 -0
- data/stdlib/builtin/file_test.rbs +59 -0
- data/stdlib/builtin/float.rbs +696 -0
- data/stdlib/builtin/gc.rbs +243 -0
- data/stdlib/builtin/hash.rbs +1029 -0
- data/stdlib/builtin/integer.rbs +707 -0
- data/stdlib/builtin/io.rbs +683 -0
- data/stdlib/builtin/kernel.rbs +576 -0
- data/stdlib/builtin/marshal.rbs +161 -0
- data/stdlib/builtin/match_data.rbs +271 -0
- data/stdlib/builtin/math.rbs +369 -0
- data/stdlib/builtin/method.rbs +185 -0
- data/stdlib/builtin/module.rbs +1104 -0
- data/stdlib/builtin/nil_class.rbs +82 -0
- data/stdlib/builtin/numeric.rbs +409 -0
- data/stdlib/builtin/object.rbs +824 -0
- data/stdlib/builtin/proc.rbs +429 -0
- data/stdlib/builtin/process.rbs +1227 -0
- data/stdlib/builtin/random.rbs +267 -0
- data/stdlib/builtin/range.rbs +226 -0
- data/stdlib/builtin/rational.rbs +424 -0
- data/stdlib/builtin/rb_config.rbs +57 -0
- data/stdlib/builtin/regexp.rbs +1083 -0
- data/stdlib/builtin/ruby_vm.rbs +14 -0
- data/stdlib/builtin/signal.rbs +55 -0
- data/stdlib/builtin/string.rbs +1901 -0
- data/stdlib/builtin/string_io.rbs +284 -0
- data/stdlib/builtin/struct.rbs +40 -0
- data/stdlib/builtin/symbol.rbs +228 -0
- data/stdlib/builtin/thread.rbs +1108 -0
- data/stdlib/builtin/thread_group.rbs +23 -0
- data/stdlib/builtin/time.rbs +1047 -0
- data/stdlib/builtin/trace_point.rbs +290 -0
- data/stdlib/builtin/true_class.rbs +46 -0
- data/stdlib/builtin/unbound_method.rbs +153 -0
- data/stdlib/builtin/warning.rbs +17 -0
- data/stdlib/coverage/coverage.rbs +62 -0
- data/stdlib/csv/csv.rbs +773 -0
- data/stdlib/erb/erb.rbs +392 -0
- data/stdlib/find/find.rbs +40 -0
- data/stdlib/ipaddr/ipaddr.rbs +247 -0
- data/stdlib/json/json.rbs +335 -0
- data/stdlib/pathname/pathname.rbs +1093 -0
- data/stdlib/prime/integer-extension.rbs +23 -0
- data/stdlib/prime/prime.rbs +188 -0
- data/stdlib/securerandom/securerandom.rbs +9 -0
- data/stdlib/set/set.rbs +301 -0
- data/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +292 -0
@@ -0,0 +1,362 @@
|
|
1
|
+
module RBS
|
2
|
+
module AST
|
3
|
+
module Members
|
4
|
+
class MethodDefinition
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :kind
|
7
|
+
attr_reader :types
|
8
|
+
attr_reader :annotations
|
9
|
+
attr_reader :location
|
10
|
+
attr_reader :comment
|
11
|
+
attr_reader :attributes
|
12
|
+
|
13
|
+
def initialize(name:, kind:, types:, annotations:, location:, comment:, attributes:)
|
14
|
+
@name = name
|
15
|
+
@kind = kind
|
16
|
+
@types = types
|
17
|
+
@annotations = annotations
|
18
|
+
@location = location
|
19
|
+
@comment = comment
|
20
|
+
@attributes = attributes
|
21
|
+
end
|
22
|
+
|
23
|
+
def ==(other)
|
24
|
+
other.is_a?(MethodDefinition) &&
|
25
|
+
other.name == name &&
|
26
|
+
other.kind == kind &&
|
27
|
+
other.types == types &&
|
28
|
+
other.attributes == attributes
|
29
|
+
end
|
30
|
+
|
31
|
+
alias eql? ==
|
32
|
+
|
33
|
+
def hash
|
34
|
+
self.class.hash ^ name.hash ^ kind.hash ^ types.hash ^ attributes.hash
|
35
|
+
end
|
36
|
+
|
37
|
+
def instance?
|
38
|
+
kind == :instance || kind == :singleton_instance
|
39
|
+
end
|
40
|
+
|
41
|
+
def singleton?
|
42
|
+
kind == :singleton || kind == :singleton_instance
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_json(*a)
|
46
|
+
{
|
47
|
+
member: :method_definition,
|
48
|
+
kind: kind,
|
49
|
+
types: types,
|
50
|
+
annotations: annotations,
|
51
|
+
location: location,
|
52
|
+
comment: comment,
|
53
|
+
attributes: attributes
|
54
|
+
}.to_json(*a)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module Var
|
59
|
+
attr_reader :name
|
60
|
+
attr_reader :type
|
61
|
+
attr_reader :location
|
62
|
+
attr_reader :comment
|
63
|
+
|
64
|
+
def initialize(name:, type:, location:, comment:)
|
65
|
+
@name = name
|
66
|
+
@type = type
|
67
|
+
@location = location
|
68
|
+
@comment = comment
|
69
|
+
end
|
70
|
+
|
71
|
+
def ==(other)
|
72
|
+
other.is_a?(self.class) && other.name == name && other.type == type
|
73
|
+
end
|
74
|
+
|
75
|
+
alias eql? ==
|
76
|
+
|
77
|
+
def hash
|
78
|
+
self.class.hash ^ name.hash ^ type.hash
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class InstanceVariable
|
83
|
+
include Var
|
84
|
+
|
85
|
+
def to_json(*a)
|
86
|
+
{
|
87
|
+
member: :instance_variable,
|
88
|
+
name: name,
|
89
|
+
type: type,
|
90
|
+
location: location,
|
91
|
+
comment: comment
|
92
|
+
}.to_json(*a)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class ClassInstanceVariable
|
97
|
+
include Var
|
98
|
+
|
99
|
+
def to_json(*a)
|
100
|
+
{
|
101
|
+
member: :class_instance_variable,
|
102
|
+
name: name,
|
103
|
+
type: type,
|
104
|
+
location: location,
|
105
|
+
comment: comment
|
106
|
+
}.to_json(*a)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class ClassVariable
|
111
|
+
include Var
|
112
|
+
|
113
|
+
def to_json(*a)
|
114
|
+
{
|
115
|
+
member: :class_variable,
|
116
|
+
name: name,
|
117
|
+
type: type,
|
118
|
+
location: location,
|
119
|
+
comment: comment
|
120
|
+
}.to_json(*a)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
module Mixin
|
125
|
+
attr_reader :name
|
126
|
+
attr_reader :args
|
127
|
+
attr_reader :annotations
|
128
|
+
attr_reader :location
|
129
|
+
attr_reader :comment
|
130
|
+
|
131
|
+
def initialize(name:, args:, annotations:, location:, comment:)
|
132
|
+
@name = name
|
133
|
+
@args = args
|
134
|
+
@annotations = annotations
|
135
|
+
@location = location
|
136
|
+
@comment = comment
|
137
|
+
end
|
138
|
+
|
139
|
+
def ==(other)
|
140
|
+
other.is_a?(self.class) && other.name == name && other.args == args
|
141
|
+
end
|
142
|
+
|
143
|
+
def eql?(other)
|
144
|
+
self == other
|
145
|
+
end
|
146
|
+
|
147
|
+
def hash
|
148
|
+
self.class.hash ^ name.hash ^ args.hash
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class Include
|
153
|
+
include Mixin
|
154
|
+
|
155
|
+
def to_json(*a)
|
156
|
+
{
|
157
|
+
member: :include,
|
158
|
+
name: name,
|
159
|
+
args: args,
|
160
|
+
annotations: annotations,
|
161
|
+
location: location,
|
162
|
+
comment: comment
|
163
|
+
}.to_json(*a)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class Extend
|
168
|
+
include Mixin
|
169
|
+
|
170
|
+
def to_json(*a)
|
171
|
+
{
|
172
|
+
member: :extend,
|
173
|
+
name: name,
|
174
|
+
args: args,
|
175
|
+
annotations: annotations,
|
176
|
+
location: location,
|
177
|
+
comment: comment
|
178
|
+
}.to_json(*a)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class Prepend
|
183
|
+
include Mixin
|
184
|
+
|
185
|
+
def to_json(*a)
|
186
|
+
{
|
187
|
+
member: :prepend,
|
188
|
+
name: name,
|
189
|
+
args: args,
|
190
|
+
annotations: annotations,
|
191
|
+
location: location,
|
192
|
+
comment: comment
|
193
|
+
}.to_json(*a)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
module Attribute
|
198
|
+
attr_reader :name
|
199
|
+
attr_reader :type
|
200
|
+
attr_reader :ivar_name
|
201
|
+
attr_reader :annotations
|
202
|
+
attr_reader :location
|
203
|
+
attr_reader :comment
|
204
|
+
|
205
|
+
def initialize(name:, type:, ivar_name:, annotations:, location:, comment:)
|
206
|
+
@name = name
|
207
|
+
@type = type
|
208
|
+
@ivar_name = ivar_name
|
209
|
+
@annotations = annotations
|
210
|
+
@location = location
|
211
|
+
@comment = comment
|
212
|
+
end
|
213
|
+
|
214
|
+
def ==(other)
|
215
|
+
other.is_a?(self.class) &&
|
216
|
+
other.name == name &&
|
217
|
+
other.type == type &&
|
218
|
+
other.ivar_name == ivar_name
|
219
|
+
end
|
220
|
+
|
221
|
+
alias eql? ==
|
222
|
+
|
223
|
+
def hash
|
224
|
+
self.class.hash ^ name.hash ^ type.hash ^ ivar_name.hash
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
class AttrReader
|
229
|
+
include Attribute
|
230
|
+
|
231
|
+
def to_json(*a)
|
232
|
+
{
|
233
|
+
member: :attr_reader,
|
234
|
+
name: name,
|
235
|
+
type: type,
|
236
|
+
ivar_name: ivar_name,
|
237
|
+
annotations: annotations,
|
238
|
+
location: location,
|
239
|
+
comment: comment
|
240
|
+
}.to_json(*a)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
class AttrAccessor
|
245
|
+
include Attribute
|
246
|
+
|
247
|
+
def to_json(*a)
|
248
|
+
{
|
249
|
+
member: :attr_accessor,
|
250
|
+
name: name,
|
251
|
+
type: type,
|
252
|
+
ivar_name: ivar_name,
|
253
|
+
annotations: annotations,
|
254
|
+
location: location,
|
255
|
+
comment: comment
|
256
|
+
}.to_json(*a)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
class AttrWriter
|
261
|
+
include Attribute
|
262
|
+
|
263
|
+
def to_json(*a)
|
264
|
+
{
|
265
|
+
member: :attr_writer,
|
266
|
+
name: name,
|
267
|
+
type: type,
|
268
|
+
ivar_name: ivar_name,
|
269
|
+
annotations: annotations,
|
270
|
+
location: location,
|
271
|
+
comment: comment
|
272
|
+
}.to_json(*a)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
module LocationOnly
|
277
|
+
attr_reader :location
|
278
|
+
|
279
|
+
def initialize(location:)
|
280
|
+
@location = location
|
281
|
+
end
|
282
|
+
|
283
|
+
def ==(other)
|
284
|
+
other.is_a?(self.class)
|
285
|
+
end
|
286
|
+
|
287
|
+
alias eql? ==
|
288
|
+
|
289
|
+
def hash
|
290
|
+
self.class.hash
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
class Public
|
295
|
+
include LocationOnly
|
296
|
+
|
297
|
+
def to_json(*a)
|
298
|
+
{ member: :public, location: location }.to_json(*a)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
class Private
|
303
|
+
include LocationOnly
|
304
|
+
|
305
|
+
def to_json(*a)
|
306
|
+
{ member: :private, location: location }.to_json(*a)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
class Alias
|
311
|
+
attr_reader :new_name
|
312
|
+
attr_reader :old_name
|
313
|
+
attr_reader :kind
|
314
|
+
attr_reader :annotations
|
315
|
+
attr_reader :location
|
316
|
+
attr_reader :comment
|
317
|
+
|
318
|
+
def initialize(new_name:, old_name:, kind:, annotations:, location:, comment:)
|
319
|
+
@new_name = new_name
|
320
|
+
@old_name = old_name
|
321
|
+
@kind = kind
|
322
|
+
@annotations = annotations
|
323
|
+
@location = location
|
324
|
+
@comment = comment
|
325
|
+
end
|
326
|
+
|
327
|
+
def ==(other)
|
328
|
+
other.is_a?(self.class) &&
|
329
|
+
other.new_name == new_name &&
|
330
|
+
other.old_name == old_name &&
|
331
|
+
other.kind == kind
|
332
|
+
end
|
333
|
+
|
334
|
+
alias eql? ==
|
335
|
+
|
336
|
+
def hash
|
337
|
+
self.class.hash ^ new_name.hash ^ old_name.hash ^ kind.hash
|
338
|
+
end
|
339
|
+
|
340
|
+
def to_json(*a)
|
341
|
+
{
|
342
|
+
member: :alias,
|
343
|
+
new_name: new_name,
|
344
|
+
old_name: old_name,
|
345
|
+
kind: kind,
|
346
|
+
annotations: annotations,
|
347
|
+
location: location,
|
348
|
+
comment: comment
|
349
|
+
}.to_json(*a)
|
350
|
+
end
|
351
|
+
|
352
|
+
def instance?
|
353
|
+
kind == :instance
|
354
|
+
end
|
355
|
+
|
356
|
+
def singleton?
|
357
|
+
kind == :singleton
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
data/lib/rbs/buffer.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module RBS
|
2
|
+
class Buffer
|
3
|
+
attr_reader :name
|
4
|
+
attr_reader :content
|
5
|
+
attr_reader :lines
|
6
|
+
attr_reader :ranges
|
7
|
+
|
8
|
+
def initialize(name:, content:)
|
9
|
+
@name = name
|
10
|
+
@content = content
|
11
|
+
|
12
|
+
@lines = content.lines
|
13
|
+
|
14
|
+
@ranges = []
|
15
|
+
offset = 0
|
16
|
+
lines.each do |line|
|
17
|
+
size = line.size
|
18
|
+
range = offset...(offset+size)
|
19
|
+
ranges << range
|
20
|
+
offset += size
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def pos_to_loc(pos)
|
25
|
+
index = ranges.bsearch_index do |range|
|
26
|
+
pos < range.end
|
27
|
+
end
|
28
|
+
|
29
|
+
if index
|
30
|
+
[index + 1, pos - ranges[index].begin]
|
31
|
+
else
|
32
|
+
[ranges.size + 1, 0]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def loc_to_pos(loc)
|
37
|
+
line, column = loc
|
38
|
+
|
39
|
+
if range = ranges[line - 1]
|
40
|
+
range.begin + column
|
41
|
+
else
|
42
|
+
last_position
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def last_position
|
47
|
+
content.size
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module RBS
|
2
|
+
module BuiltinNames
|
3
|
+
class Name
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(name:)
|
7
|
+
@name = name
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
name.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance_type(*args)
|
15
|
+
Types::ClassInstance.new(name: name, args: args, location: nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
def instance_type?(type)
|
19
|
+
type.is_a?(Types::ClassInstance) && type.name == name
|
20
|
+
end
|
21
|
+
|
22
|
+
def singleton_type
|
23
|
+
@singleton_type ||= Types::ClassSingleton.new(name: name, location: nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
def singleton_type?(type)
|
27
|
+
type.is_a?(Types::ClassSingleton) && type.name == name
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.define(name, namespace: Namespace.root)
|
31
|
+
new(name: TypeName.new(name: name, namespace: namespace))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
BasicObject = Name.new(name: TypeName.new(name: :BasicObject, namespace: Namespace.root))
|
36
|
+
Object = Name.new(name: TypeName.new(name: :Object, namespace: Namespace.root))
|
37
|
+
Kernel = Name.new(name: TypeName.new(name: :Kernel, namespace: Namespace.root))
|
38
|
+
String = Name.define(:String)
|
39
|
+
Comparable = Name.define(:Comparable)
|
40
|
+
Enumerable = Name.define(:Enumerable)
|
41
|
+
Class = Name.define(:Class)
|
42
|
+
Module = Name.define(:Module)
|
43
|
+
Array = Name.define(:Array)
|
44
|
+
Hash = Name.define(:Hash)
|
45
|
+
Range = Name.define(:Range)
|
46
|
+
Enumerator = Name.define(:Enumerator)
|
47
|
+
Set = Name.define(:Set)
|
48
|
+
Symbol = Name.define(:Symbol)
|
49
|
+
Integer = Name.define(:Integer)
|
50
|
+
Float = Name.define(:Float)
|
51
|
+
Regexp = Name.define(:Regexp)
|
52
|
+
TrueClass = Name.define(:TrueClass)
|
53
|
+
FalseClass = Name.define(:FalseClass)
|
54
|
+
end
|
55
|
+
end
|