rbs-inline 0.4.0 → 0.6.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/README.md +8 -5
- data/Rakefile +12 -0
- data/lib/rbs/inline/annotation_parser/tokenizer.rb +361 -0
- data/lib/rbs/inline/annotation_parser.rb +548 -326
- data/lib/rbs/inline/ast/annotations.rb +433 -138
- data/lib/rbs/inline/ast/comment_lines.rb +17 -20
- data/lib/rbs/inline/ast/declarations.rb +301 -28
- data/lib/rbs/inline/ast/members.rb +130 -121
- data/lib/rbs/inline/ast/tree.rb +37 -22
- data/lib/rbs/inline/cli.rb +12 -12
- data/lib/rbs/inline/node_utils.rb +1 -1
- data/lib/rbs/inline/parser.rb +165 -67
- data/lib/rbs/inline/version.rb +1 -1
- data/lib/rbs/inline/writer.rb +395 -118
- data/lib/rbs/inline.rb +1 -0
- data/rbs_collection.lock.yaml +2 -2
- data/sig/generated/rbs/inline/annotation_parser/tokenizer.rbs +221 -0
- data/sig/generated/rbs/inline/annotation_parser.rbs +148 -92
- data/sig/generated/rbs/inline/ast/annotations.rbs +143 -37
- data/sig/generated/rbs/inline/ast/comment_lines.rbs +8 -4
- data/sig/generated/rbs/inline/ast/declarations.rbs +133 -10
- data/sig/generated/rbs/inline/ast/members.rbs +26 -15
- data/sig/generated/rbs/inline/ast/tree.rbs +23 -17
- data/sig/generated/rbs/inline/cli.rbs +3 -3
- data/sig/generated/rbs/inline/node_utils.rbs +1 -1
- data/sig/generated/rbs/inline/parser.rbs +35 -18
- data/sig/generated/rbs/inline/writer.rbs +62 -22
- metadata +5 -3
data/lib/rbs/inline/writer.rb
CHANGED
@@ -3,25 +3,33 @@
|
|
3
3
|
module RBS
|
4
4
|
module Inline
|
5
5
|
class Writer
|
6
|
-
|
7
|
-
|
6
|
+
# @rbs!
|
7
|
+
# interface _Content
|
8
|
+
# def <<: (RBS::AST::Declarations::t | RBS::AST::Members::t) -> void
|
9
|
+
#
|
10
|
+
# def concat: (Array[RBS::AST::Declarations::t | RBS::AST::Members::t]) -> void
|
11
|
+
# end
|
12
|
+
|
13
|
+
attr_reader :output #: String
|
14
|
+
attr_reader :writer #: RBS::Writer
|
8
15
|
|
9
16
|
# @rbs buffer: String
|
10
|
-
def initialize(buffer = +"")
|
17
|
+
def initialize(buffer = +"") #: void
|
11
18
|
@output = buffer
|
12
19
|
@writer = RBS::Writer.new(out: StringIO.new(buffer))
|
13
20
|
end
|
14
21
|
|
15
22
|
# @rbs uses: Array[AST::Annotations::Use]
|
16
23
|
# @rbs decls: Array[AST::Declarations::t]
|
17
|
-
|
24
|
+
# @rbs rbs_decls: Array[RBS::AST::Declarations::t]
|
25
|
+
def self.write(uses, decls, rbs_decls) #: void
|
18
26
|
writer = Writer.new()
|
19
|
-
writer.write(uses, decls)
|
27
|
+
writer.write(uses, decls, rbs_decls)
|
20
28
|
writer.output
|
21
29
|
end
|
22
30
|
|
23
|
-
# @rbs lines:
|
24
|
-
# @rbs
|
31
|
+
# @rbs *lines: String
|
32
|
+
# @rbs return: void
|
25
33
|
def header(*lines)
|
26
34
|
lines.each do |line|
|
27
35
|
writer.out.puts("# " + line)
|
@@ -31,8 +39,10 @@ module RBS
|
|
31
39
|
|
32
40
|
# @rbs uses: Array[AST::Annotations::Use]
|
33
41
|
# @rbs decls: Array[AST::Declarations::t]
|
34
|
-
# @rbs
|
35
|
-
|
42
|
+
# @rbs rbs_decls: Array[RBS::AST::Declarations::t] --
|
43
|
+
# Top level `rbs!` declarations
|
44
|
+
# @rbs return: void
|
45
|
+
def write(uses, decls, rbs_decls)
|
36
46
|
use_dirs = uses.map do |use|
|
37
47
|
RBS::AST::Directives::Use.new(
|
38
48
|
clauses: use.clauses,
|
@@ -40,54 +50,64 @@ module RBS
|
|
40
50
|
)
|
41
51
|
end
|
42
52
|
|
43
|
-
rbs =
|
44
|
-
|
53
|
+
rbs = [] #: Array[RBS::AST::Declarations::t]
|
54
|
+
|
55
|
+
decls.each do |decl|
|
56
|
+
translate_decl(
|
57
|
+
decl,
|
58
|
+
rbs #: Array[RBS::AST::Declarations::t | RBS::AST::Members::t]
|
59
|
+
)
|
45
60
|
end
|
46
61
|
|
47
|
-
|
62
|
+
rbs.concat(rbs_decls)
|
63
|
+
|
64
|
+
writer.write(
|
65
|
+
use_dirs + rbs
|
66
|
+
)
|
48
67
|
end
|
49
68
|
|
50
69
|
# @rbs decl: AST::Declarations::t
|
51
|
-
# @rbs
|
52
|
-
|
70
|
+
# @rbs rbs: _Content
|
71
|
+
# @rbs return: void
|
72
|
+
def translate_decl(decl, rbs)
|
53
73
|
case decl
|
54
74
|
when AST::Declarations::ClassDecl
|
55
|
-
translate_class_decl(decl)
|
75
|
+
translate_class_decl(decl, rbs)
|
56
76
|
when AST::Declarations::ModuleDecl
|
57
|
-
translate_module_decl(decl)
|
77
|
+
translate_module_decl(decl, rbs)
|
58
78
|
when AST::Declarations::ConstantDecl
|
59
|
-
translate_constant_decl(decl)
|
79
|
+
translate_constant_decl(decl, rbs)
|
80
|
+
when AST::Declarations::DataAssignDecl
|
81
|
+
translate_data_assign_decl(decl, rbs)
|
82
|
+
when AST::Declarations::StructAssignDecl
|
83
|
+
translate_struct_assign_decl(decl, rbs)
|
84
|
+
when AST::Declarations::BlockDecl
|
85
|
+
if decl.module_class_annotation
|
86
|
+
case decl.module_class_annotation
|
87
|
+
when AST::Annotations::ModuleDecl
|
88
|
+
translate_module_block_decl(decl, rbs)
|
89
|
+
when AST::Annotations::ClassDecl
|
90
|
+
translate_class_block_decl(decl, rbs)
|
91
|
+
end
|
92
|
+
end
|
60
93
|
end
|
61
94
|
end
|
62
95
|
|
63
96
|
# @rbs decl: AST::Declarations::ClassDecl
|
64
|
-
# @rbs
|
65
|
-
|
97
|
+
# @rbs rbs: _Content
|
98
|
+
# @rbs return: void
|
99
|
+
def translate_class_decl(decl, rbs)
|
66
100
|
return unless decl.class_name
|
67
101
|
|
68
102
|
if decl.comments
|
69
|
-
comment = RBS::AST::Comment.new(string: decl.comments.content, location: nil)
|
103
|
+
comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
|
70
104
|
end
|
71
105
|
|
72
106
|
members = [] #: Array[RBS::AST::Members::t | RBS::AST::Declarations::t]
|
73
107
|
|
74
|
-
decl.members
|
75
|
-
if member.is_a?(AST::Members::Base)
|
76
|
-
if rbs_member = translate_member(member, decl)
|
77
|
-
members.concat rbs_member
|
78
|
-
end
|
79
|
-
end
|
108
|
+
translate_members(decl.members, nil, members)
|
80
109
|
|
81
|
-
|
82
|
-
members.concat translate_singleton_decl(member)
|
83
|
-
elsif member.is_a?(AST::Declarations::Base)
|
84
|
-
if rbs = translate_decl(member)
|
85
|
-
members << rbs
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
RBS::AST::Declarations::Class.new(
|
110
|
+
rbs << RBS::AST::Declarations::Class.new(
|
91
111
|
name: decl.class_name,
|
92
112
|
type_params: decl.type_params,
|
93
113
|
members: members,
|
@@ -98,36 +118,46 @@ module RBS
|
|
98
118
|
)
|
99
119
|
end
|
100
120
|
|
121
|
+
# @rbs members: Array[AST::Declarations::t | AST::Members::t]
|
122
|
+
# @rbs decl: AST::Declarations::SingletonClassDecl?
|
123
|
+
# @rbs rbs: _Content
|
124
|
+
# @rbs return: void
|
125
|
+
def translate_members(members, decl, rbs)
|
126
|
+
members.each do |member|
|
127
|
+
case member
|
128
|
+
when AST::Members::Base
|
129
|
+
translate_member(member, decl, rbs)
|
130
|
+
when AST::Declarations::SingletonClassDecl
|
131
|
+
translate_singleton_decl(member, rbs)
|
132
|
+
when AST::Declarations::BlockDecl
|
133
|
+
if member.module_class_annotation
|
134
|
+
translate_decl(member, rbs)
|
135
|
+
else
|
136
|
+
translate_members(member.members, decl, rbs)
|
137
|
+
end
|
138
|
+
when AST::Declarations::ClassDecl, AST::Declarations::ModuleDecl, AST::Declarations::ConstantDecl, AST::Declarations::DataAssignDecl, AST::Declarations::StructAssignDecl
|
139
|
+
translate_decl(member, rbs)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
101
144
|
# @rbs decl: AST::Declarations::ModuleDecl
|
102
|
-
# @rbs
|
103
|
-
|
145
|
+
# @rbs rbs: _Content
|
146
|
+
# @rbs return: void
|
147
|
+
def translate_module_decl(decl, rbs)
|
104
148
|
return unless decl.module_name
|
105
149
|
|
106
150
|
if decl.comments
|
107
|
-
comment = RBS::AST::Comment.new(string: decl.comments.content, location: nil)
|
151
|
+
comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
|
108
152
|
end
|
109
153
|
|
110
154
|
members = [] #: Array[RBS::AST::Members::t | RBS::AST::Declarations::t]
|
111
155
|
|
112
|
-
decl.members
|
113
|
-
if member.is_a?(AST::Members::Base)
|
114
|
-
if rbs_member = translate_member(member, decl)
|
115
|
-
members.concat rbs_member
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
if member.is_a?(AST::Declarations::SingletonClassDecl)
|
120
|
-
members.concat translate_singleton_decl(member)
|
121
|
-
elsif member.is_a?(AST::Declarations::Base)
|
122
|
-
if rbs = translate_decl(member)
|
123
|
-
members << rbs
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
156
|
+
translate_members(decl.members, nil, members)
|
127
157
|
|
128
158
|
self_types = decl.module_selfs.map { _1.constraint }.compact
|
129
159
|
|
130
|
-
RBS::AST::Declarations::Module.new(
|
160
|
+
rbs << RBS::AST::Declarations::Module.new(
|
131
161
|
name: decl.module_name,
|
132
162
|
type_params: decl.type_params,
|
133
163
|
members: members,
|
@@ -139,15 +169,16 @@ module RBS
|
|
139
169
|
end
|
140
170
|
|
141
171
|
# @rbs decl: AST::Declarations::ConstantDecl
|
142
|
-
# @rbs
|
143
|
-
|
172
|
+
# @rbs rbs: _Content
|
173
|
+
# @rbs return: void
|
174
|
+
def translate_constant_decl(decl, rbs)
|
144
175
|
return unless decl.constant_name
|
145
176
|
|
146
177
|
if decl.comments
|
147
|
-
comment = RBS::AST::Comment.new(string: decl.comments.content, location: nil)
|
178
|
+
comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
|
148
179
|
end
|
149
180
|
|
150
|
-
RBS::AST::Declarations::Constant.new(
|
181
|
+
rbs << RBS::AST::Declarations::Constant.new(
|
151
182
|
name: decl.constant_name,
|
152
183
|
type: decl.type,
|
153
184
|
comment: comment,
|
@@ -155,96 +186,284 @@ module RBS
|
|
155
186
|
)
|
156
187
|
end
|
157
188
|
|
158
|
-
# @rbs decl: AST::Declarations::
|
159
|
-
# @rbs
|
160
|
-
def
|
161
|
-
|
189
|
+
# @rbs decl: AST::Declarations::DataAssignDecl
|
190
|
+
# @rbs rbs: _Content
|
191
|
+
def translate_data_assign_decl(decl, rbs) #: void
|
192
|
+
return unless decl.constant_name
|
162
193
|
|
194
|
+
if decl.comments
|
195
|
+
comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
|
196
|
+
end
|
197
|
+
|
198
|
+
attributes = decl.each_attribute.map do |name, type|
|
199
|
+
RBS::AST::Members::AttrReader.new(
|
200
|
+
name: name,
|
201
|
+
type: type&.type || Types::Bases::Any.new(location: nil),
|
202
|
+
ivar_name: false,
|
203
|
+
comment: nil,
|
204
|
+
kind: :instance,
|
205
|
+
annotations: [],
|
206
|
+
visibility: nil,
|
207
|
+
location: nil
|
208
|
+
)
|
209
|
+
end
|
210
|
+
|
211
|
+
new = RBS::AST::Members::MethodDefinition.new(
|
212
|
+
name: :new,
|
213
|
+
kind: :singleton,
|
214
|
+
overloads: [
|
215
|
+
RBS::AST::Members::MethodDefinition::Overload.new(
|
216
|
+
method_type: RBS::MethodType.new(
|
217
|
+
type_params: [],
|
218
|
+
type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
|
219
|
+
required_positionals: decl.each_attribute.map do |name, attr|
|
220
|
+
RBS::Types::Function::Param.new(
|
221
|
+
type: attr&.type || Types::Bases::Any.new(location: nil),
|
222
|
+
name: name,
|
223
|
+
location: nil
|
224
|
+
)
|
225
|
+
end
|
226
|
+
),
|
227
|
+
block: nil,
|
228
|
+
location: nil
|
229
|
+
),
|
230
|
+
annotations: []
|
231
|
+
),
|
232
|
+
RBS::AST::Members::MethodDefinition::Overload.new(
|
233
|
+
method_type: RBS::MethodType.new(
|
234
|
+
type_params: [],
|
235
|
+
type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).update(
|
236
|
+
required_keywords: decl.each_attribute.map do |name, attr|
|
237
|
+
[
|
238
|
+
name,
|
239
|
+
RBS::Types::Function::Param.new(
|
240
|
+
type: attr&.type || Types::Bases::Any.new(location: nil),
|
241
|
+
name: nil,
|
242
|
+
location: nil
|
243
|
+
)
|
244
|
+
]
|
245
|
+
end.to_h
|
246
|
+
),
|
247
|
+
block: nil,
|
248
|
+
location: nil
|
249
|
+
),
|
250
|
+
annotations: []
|
251
|
+
)
|
252
|
+
],
|
253
|
+
annotations: [],
|
254
|
+
location: nil,
|
255
|
+
comment: nil,
|
256
|
+
overloading: false,
|
257
|
+
visibility: nil
|
258
|
+
)
|
259
|
+
|
260
|
+
rbs << RBS::AST::Declarations::Class.new(
|
261
|
+
name: decl.constant_name,
|
262
|
+
type_params: [],
|
263
|
+
members: [*attributes, new],
|
264
|
+
super_class: RBS::AST::Declarations::Class::Super.new(
|
265
|
+
name: RBS::TypeName.new(name: :Data, namespace: RBS::Namespace.empty),
|
266
|
+
args: [],
|
267
|
+
location: nil
|
268
|
+
),
|
269
|
+
annotations: decl.class_annotations,
|
270
|
+
location: nil,
|
271
|
+
comment: comment
|
272
|
+
)
|
273
|
+
end
|
274
|
+
|
275
|
+
# @rbs decl: AST::Declarations::StructAssignDecl
|
276
|
+
# @rbs rbs: _Content
|
277
|
+
def translate_struct_assign_decl(decl, rbs) #: void
|
278
|
+
return unless decl.constant_name
|
279
|
+
|
280
|
+
if decl.comments
|
281
|
+
comment = RBS::AST::Comment.new(string: decl.comments.content(trim: true), location: nil)
|
282
|
+
end
|
283
|
+
|
284
|
+
attributes = decl.each_attribute.map do |name, type|
|
285
|
+
if decl.readonly_attributes?
|
286
|
+
RBS::AST::Members::AttrReader.new(
|
287
|
+
name: name,
|
288
|
+
type: type&.type || Types::Bases::Any.new(location: nil),
|
289
|
+
ivar_name: false,
|
290
|
+
comment: nil,
|
291
|
+
kind: :instance,
|
292
|
+
annotations: [],
|
293
|
+
visibility: nil,
|
294
|
+
location: nil
|
295
|
+
)
|
296
|
+
else
|
297
|
+
RBS::AST::Members::AttrAccessor.new(
|
298
|
+
name: name,
|
299
|
+
type: type&.type || Types::Bases::Any.new(location: nil),
|
300
|
+
ivar_name: false,
|
301
|
+
comment: nil,
|
302
|
+
kind: :instance,
|
303
|
+
annotations: [],
|
304
|
+
visibility: nil,
|
305
|
+
location: nil
|
306
|
+
)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
new = RBS::AST::Members::MethodDefinition.new(
|
311
|
+
name: :new,
|
312
|
+
kind: :singleton,
|
313
|
+
overloads: [],
|
314
|
+
annotations: [],
|
315
|
+
location: nil,
|
316
|
+
comment: nil,
|
317
|
+
overloading: false,
|
318
|
+
visibility: nil
|
319
|
+
)
|
320
|
+
|
321
|
+
if decl.positional_init?
|
322
|
+
attr_params = decl.each_attribute.map do |name, attr|
|
323
|
+
RBS::Types::Function::Param.new(
|
324
|
+
type: attr&.type || Types::Bases::Any.new(location: nil),
|
325
|
+
name: name,
|
326
|
+
location: nil
|
327
|
+
)
|
328
|
+
end
|
329
|
+
|
330
|
+
method_type = Types::Function.empty(Types::Bases::Instance.new(location: nil))
|
331
|
+
if decl.required_new_args?
|
332
|
+
method_type = method_type.update(required_positionals: attr_params)
|
333
|
+
else
|
334
|
+
method_type = method_type.update(optional_positionals: attr_params)
|
335
|
+
end
|
336
|
+
|
337
|
+
new.overloads <<
|
338
|
+
RBS::AST::Members::MethodDefinition::Overload.new(
|
339
|
+
method_type: RBS::MethodType.new(type_params: [], type: method_type, block: nil, location: nil),
|
340
|
+
annotations: []
|
341
|
+
)
|
342
|
+
end
|
343
|
+
|
344
|
+
if decl.keyword_init?
|
345
|
+
attr_keywords = decl.each_attribute.map do |name, attr|
|
346
|
+
[
|
347
|
+
name,
|
348
|
+
RBS::Types::Function::Param.new(
|
349
|
+
type: attr&.type || Types::Bases::Any.new(location: nil),
|
350
|
+
name: nil,
|
351
|
+
location: nil
|
352
|
+
)
|
353
|
+
]
|
354
|
+
end.to_h #: Hash[Symbol, RBS::Types::Function::Param]
|
355
|
+
|
356
|
+
method_type = Types::Function.empty(Types::Bases::Instance.new(location: nil))
|
357
|
+
if decl.required_new_args?
|
358
|
+
method_type = method_type.update(required_keywords: attr_keywords)
|
359
|
+
else
|
360
|
+
method_type = method_type.update(optional_keywords: attr_keywords)
|
361
|
+
end
|
362
|
+
|
363
|
+
new.overloads <<
|
364
|
+
RBS::AST::Members::MethodDefinition::Overload.new(
|
365
|
+
method_type: RBS::MethodType.new(type_params: [], type: method_type, block: nil, location: nil),
|
366
|
+
annotations: []
|
367
|
+
)
|
368
|
+
end
|
369
|
+
|
370
|
+
rbs << RBS::AST::Declarations::Class.new(
|
371
|
+
name: decl.constant_name,
|
372
|
+
type_params: [],
|
373
|
+
members: [*attributes, new],
|
374
|
+
super_class: RBS::AST::Declarations::Class::Super.new(
|
375
|
+
name: RBS::TypeName.new(name: :Struct, namespace: RBS::Namespace.empty),
|
376
|
+
args: [RBS::Types::Bases::Any.new(location: nil)],
|
377
|
+
location: nil
|
378
|
+
),
|
379
|
+
annotations: decl.class_annotations,
|
380
|
+
location: nil,
|
381
|
+
comment: comment
|
382
|
+
)
|
383
|
+
end
|
384
|
+
|
385
|
+
# @rbs decl: AST::Declarations::SingletonClassDecl
|
386
|
+
# @rbs rbs: _Content
|
387
|
+
# @rbs return: void
|
388
|
+
def translate_singleton_decl(decl, rbs)
|
163
389
|
decl.members.each do |member|
|
164
390
|
if member.is_a?(AST::Members::Base)
|
165
|
-
|
166
|
-
members.concat rbs_member
|
167
|
-
end
|
391
|
+
translate_member(member, decl, rbs)
|
168
392
|
end
|
169
393
|
end
|
170
|
-
|
171
|
-
members
|
172
394
|
end
|
173
395
|
|
174
396
|
# @rbs member: AST::Members::t
|
175
|
-
# @rbs decl: AST::Declarations::
|
176
|
-
#
|
177
|
-
|
397
|
+
# @rbs decl: AST::Declarations::SingletonClassDecl? --
|
398
|
+
# The surrouding singleton class definition
|
399
|
+
# @rbs rbs: _Content
|
400
|
+
# @rbs return void
|
401
|
+
def translate_member(member, decl, rbs)
|
178
402
|
case member
|
179
403
|
when AST::Members::RubyDef
|
180
404
|
if member.comments
|
181
|
-
comment = RBS::AST::Comment.new(string: member.comments.content, location: nil)
|
405
|
+
comment = RBS::AST::Comment.new(string: member.comments.content(trim: true), location: nil)
|
182
406
|
end
|
183
407
|
|
184
408
|
kind = method_kind(member, decl)
|
185
409
|
|
186
410
|
if member.override_annotation
|
187
|
-
|
188
|
-
RBS::AST::Members::MethodDefinition.new(
|
189
|
-
name: member.method_name,
|
190
|
-
kind: kind,
|
191
|
-
overloads: [],
|
192
|
-
annotations: [],
|
193
|
-
location: nil,
|
194
|
-
comment: comment,
|
195
|
-
overloading: true,
|
196
|
-
visibility: member.visibility
|
197
|
-
)
|
198
|
-
]
|
199
|
-
end
|
200
|
-
|
201
|
-
[
|
202
|
-
RBS::AST::Members::MethodDefinition.new(
|
411
|
+
rbs << RBS::AST::Members::MethodDefinition.new(
|
203
412
|
name: member.method_name,
|
204
413
|
kind: kind,
|
205
|
-
overloads:
|
206
|
-
annotations:
|
414
|
+
overloads: [],
|
415
|
+
annotations: [],
|
207
416
|
location: nil,
|
208
417
|
comment: comment,
|
209
|
-
overloading:
|
418
|
+
overloading: true,
|
210
419
|
visibility: member.visibility
|
211
420
|
)
|
212
|
-
|
421
|
+
return
|
422
|
+
end
|
423
|
+
|
424
|
+
rbs << RBS::AST::Members::MethodDefinition.new(
|
425
|
+
name: member.method_name,
|
426
|
+
kind: kind,
|
427
|
+
overloads: member.method_overloads,
|
428
|
+
annotations: member.method_annotations,
|
429
|
+
location: nil,
|
430
|
+
comment: comment,
|
431
|
+
overloading: member.overloading?,
|
432
|
+
visibility: member.visibility
|
433
|
+
)
|
213
434
|
when AST::Members::RubyAlias
|
214
435
|
if member.comments
|
215
|
-
comment = RBS::AST::Comment.new(string: member.comments.content, location: nil)
|
436
|
+
comment = RBS::AST::Comment.new(string: member.comments.content(trim: true), location: nil)
|
216
437
|
end
|
217
438
|
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
)
|
227
|
-
]
|
439
|
+
rbs << RBS::AST::Members::Alias.new(
|
440
|
+
new_name: member.new_name,
|
441
|
+
old_name: member.old_name,
|
442
|
+
kind: :instance,
|
443
|
+
annotations: [],
|
444
|
+
location: nil,
|
445
|
+
comment: comment
|
446
|
+
)
|
228
447
|
when AST::Members::RubyMixin
|
229
|
-
|
448
|
+
if m = member.rbs
|
449
|
+
rbs << m
|
450
|
+
end
|
230
451
|
when AST::Members::RubyAttr
|
231
|
-
member.rbs
|
452
|
+
if m = member.rbs
|
453
|
+
rbs.concat m
|
454
|
+
end
|
232
455
|
when AST::Members::RubyPrivate
|
233
|
-
|
234
|
-
RBS::AST::Members::Private.new(location: nil)
|
235
|
-
]
|
456
|
+
rbs << RBS::AST::Members::Private.new(location: nil)
|
236
457
|
when AST::Members::RubyPublic
|
237
|
-
|
238
|
-
RBS::AST::Members::Public.new(location: nil)
|
239
|
-
]
|
458
|
+
rbs << RBS::AST::Members::Public.new(location: nil)
|
240
459
|
when AST::Members::RBSIvar
|
241
|
-
|
242
|
-
|
243
|
-
|
460
|
+
if m = member.rbs
|
461
|
+
rbs << m
|
462
|
+
end
|
244
463
|
when AST::Members::RBSEmbedded
|
245
464
|
case members = member.members
|
246
465
|
when Array
|
247
|
-
members
|
466
|
+
rbs.concat members
|
248
467
|
end
|
249
468
|
end
|
250
469
|
end
|
@@ -265,10 +484,10 @@ module RBS
|
|
265
484
|
# ```
|
266
485
|
#
|
267
486
|
# @rbs member: AST::Members::RubyDef
|
268
|
-
# @rbs decl: AST::Declarations::
|
269
|
-
# @rbs
|
487
|
+
# @rbs decl: AST::Declarations::SingletonClassDecl?
|
488
|
+
# @rbs return: RBS::AST::Members::MethodDefinition::kind
|
270
489
|
def method_kind(member, decl)
|
271
|
-
return :singleton if decl
|
490
|
+
return :singleton if decl
|
272
491
|
|
273
492
|
case member.node.receiver
|
274
493
|
when Prism::SelfNode
|
@@ -277,6 +496,64 @@ module RBS
|
|
277
496
|
:instance
|
278
497
|
end
|
279
498
|
end
|
499
|
+
|
500
|
+
# @rbs block: AST::Declarations::BlockDecl
|
501
|
+
# @rbs rbs: _Content
|
502
|
+
# @rbs return: void
|
503
|
+
def translate_module_block_decl(block, rbs)
|
504
|
+
annotation = block.module_class_annotation
|
505
|
+
annotation.is_a?(AST::Annotations::ModuleDecl) or raise
|
506
|
+
|
507
|
+
return unless annotation.name
|
508
|
+
|
509
|
+
if block.comments
|
510
|
+
comment = RBS::AST::Comment.new(string: block.comments.content(trim: true), location: nil)
|
511
|
+
end
|
512
|
+
|
513
|
+
members = [] #: Array[RBS::AST::Members::t | RBS::AST::Declarations::t]
|
514
|
+
|
515
|
+
translate_members(block.members, nil, members)
|
516
|
+
|
517
|
+
self_types = annotation.self_types
|
518
|
+
|
519
|
+
rbs << RBS::AST::Declarations::Module.new(
|
520
|
+
name: annotation.name,
|
521
|
+
type_params: annotation.type_params,
|
522
|
+
members: members,
|
523
|
+
self_types: self_types,
|
524
|
+
annotations: [],
|
525
|
+
location: nil,
|
526
|
+
comment: comment
|
527
|
+
)
|
528
|
+
end
|
529
|
+
|
530
|
+
# @rbs block: AST::Declarations::BlockDecl
|
531
|
+
# @rbs rbs: _Content
|
532
|
+
# @rbs return: void
|
533
|
+
def translate_class_block_decl(block, rbs)
|
534
|
+
annotation = block.module_class_annotation
|
535
|
+
annotation.is_a?(AST::Annotations::ClassDecl) or raise
|
536
|
+
|
537
|
+
return unless annotation.name
|
538
|
+
|
539
|
+
if block.comments
|
540
|
+
comment = RBS::AST::Comment.new(string: block.comments.content(trim: true), location: nil)
|
541
|
+
end
|
542
|
+
|
543
|
+
members = [] #: Array[RBS::AST::Members::t | RBS::AST::Declarations::t]
|
544
|
+
|
545
|
+
translate_members(block.members, nil, members)
|
546
|
+
|
547
|
+
rbs << RBS::AST::Declarations::Class.new(
|
548
|
+
name: annotation.name,
|
549
|
+
type_params: annotation.type_params,
|
550
|
+
members: members,
|
551
|
+
super_class: annotation.super_class,
|
552
|
+
annotations: [],
|
553
|
+
location: nil,
|
554
|
+
comment: comment
|
555
|
+
)
|
556
|
+
end
|
280
557
|
end
|
281
558
|
end
|
282
559
|
end
|
data/lib/rbs/inline.rb
CHANGED
data/rbs_collection.lock.yaml
CHANGED
@@ -42,11 +42,11 @@ gems:
|
|
42
42
|
source:
|
43
43
|
type: git
|
44
44
|
name: ruby/gem_rbs_collection
|
45
|
-
revision:
|
45
|
+
revision: 3670834268f4ea9c10aefeffae7e072b51256375
|
46
46
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
47
47
|
repo_dir: gems
|
48
48
|
- name: rbs
|
49
|
-
version: 3.5.
|
49
|
+
version: 3.5.2
|
50
50
|
source:
|
51
51
|
type: rubygems
|
52
52
|
- name: rdoc
|