rbi 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a2cb2f6b2287a3faed50161d70e0c863892c88c6eef5a3c798ccf8e16e0c441
4
- data.tar.gz: e851f3b85aa62534a3a1c867085add40aa7669df3b003f17e62eb81ce36c58ed
3
+ metadata.gz: 3adefb9fc887432fdab8f11a5800c58fe0c4b7a089c1170d67fc5fa6374c475d
4
+ data.tar.gz: 5259d5132a2b83761a22419c10fca4beff9bb95e2e60c779c3e7b5583230476d
5
5
  SHA512:
6
- metadata.gz: b566ecfc9c01ebf7524efb055302e3da780caf0e0cc3ab36bdca798ff8390cce5247bce1318c5373c8339fede498f3bc87ffd5071ace658880c0b3724a9f1d15
7
- data.tar.gz: d95c6b6ea53cf84c348b2426b9bf10ad8213282f48ec9364cb9b1512aef9dd4c896d18c09c1dac79abe40f136194ab550571ac141e960eab61e4026bdbf3c578
6
+ metadata.gz: cb345c63c449eb4610d826b3a9a2e6da4633ac7f29ceaf0b46af689f956d5a6758939d02b6234f676c6f7ce6f49ccf119e4a6237946e87cd9a7d13b57f014f82
7
+ data.tar.gz: 674a6fe4acf7b92ea718ed12c0906d5d1b8a1e1942869e0c163060fd107d227a65e0eb58460d694f22c48f3809c37739033a3b806551676ac136fedc360b0750
data/lib/rbi/loc.rb CHANGED
@@ -8,14 +8,14 @@ module RBI
8
8
  class << self
9
9
  extend T::Sig
10
10
 
11
- sig { params(file: String, yarp_location: YARP::Location).returns(Loc) }
12
- def from_yarp(file, yarp_location)
11
+ sig { params(file: String, prism_location: Prism::Location).returns(Loc) }
12
+ def from_prism(file, prism_location)
13
13
  new(
14
14
  file: file,
15
- begin_line: yarp_location.start_line,
16
- end_line: yarp_location.end_line,
17
- begin_column: yarp_location.start_column,
18
- end_column: yarp_location.end_column + 1, # TODO: Why is this off by one?
15
+ begin_line: prism_location.start_line,
16
+ end_line: prism_location.end_line,
17
+ begin_column: prism_location.start_column,
18
+ end_column: prism_location.end_column,
19
19
  )
20
20
  end
21
21
  end
@@ -45,7 +45,11 @@ module RBI
45
45
 
46
46
  sig { returns(String) }
47
47
  def to_s
48
- "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
48
+ if end_line && end_column
49
+ "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}"
50
+ else
51
+ "#{file}:#{begin_line}:#{begin_column}"
52
+ end
49
53
  end
50
54
 
51
55
  sig { returns(T.nilable(String)) }
data/lib/rbi/model.rb CHANGED
@@ -353,7 +353,7 @@ module RBI
353
353
  abstract!
354
354
 
355
355
  sig { returns(T::Array[Symbol]) }
356
- attr_accessor :names
356
+ attr_reader :names
357
357
 
358
358
  sig { returns(Visibility) }
359
359
  attr_accessor :visibility
@@ -774,7 +774,7 @@ module RBI
774
774
  abstract!
775
775
 
776
776
  sig { returns(T::Array[String]) }
777
- attr_accessor :names
777
+ attr_reader :names
778
778
 
779
779
  sig do
780
780
  params(
data/lib/rbi/parser.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require "yarp"
4
+ require "prism"
5
5
 
6
6
  module RBI
7
7
  class ParseError < StandardError
@@ -93,22 +93,23 @@ module RBI
93
93
 
94
94
  sig { params(source: String, file: String).returns(Tree) }
95
95
  def parse(source, file:)
96
- result = YARP.parse(source)
96
+ result = Prism.parse(source)
97
97
  unless result.success?
98
- raise ParseError.new(result.errors.map(&:message).join(" "), Loc.from_yarp(file, result.errors.first.location))
98
+ message = result.errors.map { |e| "#{e.message}." }.join(" ")
99
+ error = result.errors.first
100
+ location = Loc.new(file: file, begin_line: error.location.start_line, begin_column: error.location.start_column)
101
+ raise ParseError.new(message, location)
99
102
  end
100
103
 
101
104
  visitor = TreeBuilder.new(source, comments: result.comments, file: file)
102
105
  visitor.visit(result.value)
103
106
  visitor.tree
104
- rescue YARP::ParseError => e
105
- raise ParseError.new(e.message, Loc.from_yarp(file, e.location))
106
107
  rescue ParseError => e
107
108
  raise e
108
109
  rescue => e
109
110
  last_node = visitor&.last_node
110
111
  last_location = if last_node
111
- Loc.from_yarp(file, last_node.location)
112
+ Loc.from_prism(file, last_node.location)
112
113
  else
113
114
  Loc.new(file: file)
114
115
  end
@@ -118,7 +119,7 @@ module RBI
118
119
  raise exception
119
120
  end
120
121
 
121
- class Visitor < YARP::Visitor
122
+ class Visitor < Prism::Visitor
122
123
  extend T::Sig
123
124
 
124
125
  sig { params(source: String, file: String).void }
@@ -131,19 +132,19 @@ module RBI
131
132
 
132
133
  private
133
134
 
134
- sig { params(node: YARP::Node).returns(Loc) }
135
+ sig { params(node: Prism::Node).returns(Loc) }
135
136
  def node_loc(node)
136
- Loc.from_yarp(@file, node.location)
137
+ Loc.from_prism(@file, node.location)
137
138
  end
138
139
 
139
- sig { params(node: T.nilable(YARP::Node)).returns(T.nilable(String)) }
140
+ sig { params(node: T.nilable(Prism::Node)).returns(T.nilable(String)) }
140
141
  def node_string(node)
141
142
  return unless node
142
143
 
143
144
  node.slice
144
145
  end
145
146
 
146
- sig { params(node: YARP::Node).returns(String) }
147
+ sig { params(node: Prism::Node).returns(String) }
147
148
  def node_string!(node)
148
149
  T.must(node_string(node))
149
150
  end
@@ -155,32 +156,25 @@ module RBI
155
156
  sig { returns(Tree) }
156
157
  attr_reader :tree
157
158
 
158
- sig { returns(T.nilable(YARP::Node)) }
159
+ sig { returns(T.nilable(Prism::Node)) }
159
160
  attr_reader :last_node
160
161
 
161
- sig { params(source: String, comments: T::Array[YARP::Comment], file: String).void }
162
+ sig { params(source: String, comments: T::Array[Prism::Comment], file: String).void }
162
163
  def initialize(source, comments:, file:)
163
164
  super(source, file: file)
164
165
 
165
- @comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer, YARP::Comment])
166
+ @comments_by_line = T.let(comments.to_h { |c| [c.location.start_line, c] }, T::Hash[Integer, Prism::Comment])
166
167
  @tree = T.let(Tree.new, Tree)
167
168
 
168
169
  @scopes_stack = T.let([@tree], T::Array[Tree])
169
- @last_node = T.let(nil, T.nilable(YARP::Node))
170
+ @last_node = T.let(nil, T.nilable(Prism::Node))
170
171
  @last_sigs = T.let([], T::Array[RBI::Sig])
171
172
  @last_sigs_comments = T.let([], T::Array[Comment])
172
173
  end
173
174
 
174
- sig { override.params(node: T.nilable(YARP::Node)).void }
175
- def visit(node)
176
- return unless node
177
-
178
- @last_node = node
179
- super
180
- end
181
-
182
- sig { override.params(node: YARP::ClassNode).void }
175
+ sig { override.params(node: Prism::ClassNode).void }
183
176
  def visit_class_node(node)
177
+ @last_node = node
184
178
  scope = Class.new(
185
179
  node_string!(node.constant_path),
186
180
  superclass_name: node_string(node.superclass),
@@ -193,19 +187,24 @@ module RBI
193
187
  visit(node.body)
194
188
  collect_dangling_comments(node)
195
189
  @scopes_stack.pop
190
+ @last_node = nil
196
191
  end
197
192
 
198
- sig { override.params(node: YARP::ConstantWriteNode).void }
193
+ sig { override.params(node: Prism::ConstantWriteNode).void }
199
194
  def visit_constant_write_node(node)
195
+ @last_node = node
200
196
  visit_constant_assign(node)
197
+ @last_node = nil
201
198
  end
202
199
 
203
- sig { override.params(node: YARP::ConstantPathWriteNode).void }
200
+ sig { override.params(node: Prism::ConstantPathWriteNode).void }
204
201
  def visit_constant_path_write_node(node)
202
+ @last_node = node
205
203
  visit_constant_assign(node)
204
+ @last_node = nil
206
205
  end
207
206
 
208
- sig { params(node: T.any(YARP::ConstantWriteNode, YARP::ConstantPathWriteNode)).void }
207
+ sig { params(node: T.any(Prism::ConstantWriteNode, Prism::ConstantPathWriteNode)).void }
209
208
  def visit_constant_assign(node)
210
209
  struct = parse_struct(node)
211
210
 
@@ -214,9 +213,9 @@ module RBI
214
213
  elsif type_variable_definition?(node.value)
215
214
  TypeMember.new(
216
215
  case node
217
- when YARP::ConstantWriteNode
218
- node.name
219
- when YARP::ConstantPathWriteNode
216
+ when Prism::ConstantWriteNode
217
+ node.name.to_s
218
+ when Prism::ConstantPathWriteNode
220
219
  node_string!(node.target)
221
220
  end,
222
221
  node_string!(node.value),
@@ -226,9 +225,9 @@ module RBI
226
225
  else
227
226
  Const.new(
228
227
  case node
229
- when YARP::ConstantWriteNode
230
- node.name
231
- when YARP::ConstantPathWriteNode
228
+ when Prism::ConstantWriteNode
229
+ node.name.to_s
230
+ when Prism::ConstantPathWriteNode
232
231
  node_string!(node.target)
233
232
  end,
234
233
  node_string!(node.value),
@@ -238,20 +237,23 @@ module RBI
238
237
  end
239
238
  end
240
239
 
241
- sig { override.params(node: YARP::DefNode).void }
240
+ sig { override.params(node: Prism::DefNode).void }
242
241
  def visit_def_node(node)
242
+ @last_node = node
243
243
  current_scope << Method.new(
244
- node.name,
244
+ node.name.to_s,
245
245
  params: parse_params(node.parameters),
246
246
  sigs: current_sigs,
247
247
  loc: node_loc(node),
248
248
  comments: current_sigs_comments + node_comments(node),
249
249
  is_singleton: !!node.receiver,
250
250
  )
251
+ @last_node = nil
251
252
  end
252
253
 
253
- sig { override.params(node: YARP::ModuleNode).void }
254
+ sig { override.params(node: Prism::ModuleNode).void }
254
255
  def visit_module_node(node)
256
+ @last_node = node
255
257
  scope = Module.new(
256
258
  node_string!(node.constant_path),
257
259
  loc: node_loc(node),
@@ -263,19 +265,23 @@ module RBI
263
265
  visit(node.body)
264
266
  collect_dangling_comments(node)
265
267
  @scopes_stack.pop
268
+ @last_node = nil
266
269
  end
267
270
 
268
- sig { override.params(node: YARP::ProgramNode).void }
271
+ sig { override.params(node: Prism::ProgramNode).void }
269
272
  def visit_program_node(node)
273
+ @last_node = node
270
274
  super
271
275
 
272
276
  collect_orphan_comments
273
277
  separate_header_comments
274
278
  set_root_tree_loc
279
+ @last_node = nil
275
280
  end
276
281
 
277
- sig { override.params(node: YARP::SingletonClassNode).void }
282
+ sig { override.params(node: Prism::SingletonClassNode).void }
278
283
  def visit_singleton_class_node(node)
284
+ @last_node = node
279
285
  scope = SingletonClass.new(
280
286
  loc: node_loc(node),
281
287
  comments: node_comments(node),
@@ -286,11 +292,13 @@ module RBI
286
292
  visit(node.body)
287
293
  collect_dangling_comments(node)
288
294
  @scopes_stack.pop
295
+ @last_node = nil
289
296
  end
290
297
 
291
- sig { params(node: YARP::CallNode).void }
298
+ sig { params(node: Prism::CallNode).void }
292
299
  def visit_call_node(node)
293
- message = node.name
300
+ @last_node = node
301
+ message = node.name.to_s
294
302
  case message
295
303
  when "abstract!", "sealed!", "interface!"
296
304
  current_scope << Helper.new(
@@ -300,7 +308,11 @@ module RBI
300
308
  )
301
309
  when "attr_reader"
302
310
  args = node.arguments
303
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
311
+
312
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
313
+ @last_node = nil
314
+ return
315
+ end
304
316
 
305
317
  current_scope << AttrReader.new(
306
318
  *T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
@@ -310,7 +322,11 @@ module RBI
310
322
  )
311
323
  when "attr_writer"
312
324
  args = node.arguments
313
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
325
+
326
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
327
+ @last_node = nil
328
+ return
329
+ end
314
330
 
315
331
  current_scope << AttrWriter.new(
316
332
  *T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
@@ -320,7 +336,11 @@ module RBI
320
336
  )
321
337
  when "attr_accessor"
322
338
  args = node.arguments
323
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
339
+
340
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
341
+ @last_node = nil
342
+ return
343
+ end
324
344
 
325
345
  current_scope << AttrAccessor.new(
326
346
  *T.unsafe(args.arguments.map { |arg| node_string!(arg).delete_prefix(":").to_sym }),
@@ -330,19 +350,31 @@ module RBI
330
350
  )
331
351
  when "enums"
332
352
  block = node.block
333
- return unless block.is_a?(YARP::BlockNode)
353
+
354
+ unless block.is_a?(Prism::BlockNode)
355
+ @last_node = nil
356
+ return
357
+ end
334
358
 
335
359
  body = block.body
336
- return unless body.is_a?(YARP::StatementsNode)
360
+
361
+ unless body.is_a?(Prism::StatementsNode)
362
+ @last_node = nil
363
+ return
364
+ end
337
365
 
338
366
  current_scope << TEnumBlock.new(
339
- body.body.map { |stmt| T.cast(stmt, YARP::ConstantWriteNode).name },
367
+ body.body.map { |stmt| T.cast(stmt, Prism::ConstantWriteNode).name.to_s },
340
368
  loc: node_loc(node),
341
369
  comments: node_comments(node),
342
370
  )
343
371
  when "extend"
344
372
  args = node.arguments
345
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
373
+
374
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
375
+ @last_node = nil
376
+ return
377
+ end
346
378
 
347
379
  current_scope << Extend.new(
348
380
  *T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
@@ -351,7 +383,11 @@ module RBI
351
383
  )
352
384
  when "include"
353
385
  args = node.arguments
354
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
386
+
387
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
388
+ @last_node = nil
389
+ return
390
+ end
355
391
 
356
392
  current_scope << Include.new(
357
393
  *T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
@@ -360,7 +396,11 @@ module RBI
360
396
  )
361
397
  when "mixes_in_class_methods"
362
398
  args = node.arguments
363
- return unless args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
399
+
400
+ unless args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
401
+ @last_node = nil
402
+ return
403
+ end
364
404
 
365
405
  current_scope << MixesInClassMethods.new(
366
406
  *T.unsafe(args.arguments.map { |arg| node_string!(arg) }),
@@ -369,12 +409,12 @@ module RBI
369
409
  )
370
410
  when "private", "protected", "public"
371
411
  args = node.arguments
372
- if args.is_a?(YARP::ArgumentsNode) && args.arguments.any?
412
+ if args.is_a?(Prism::ArgumentsNode) && args.arguments.any?
373
413
  visit(node.arguments)
374
414
  last_node = @scopes_stack.last&.nodes&.last
375
415
  case last_node
376
416
  when Method, Attr
377
- last_node.visibility = parse_visibility(node.name, node)
417
+ last_node.visibility = parse_visibility(node.name.to_s, node)
378
418
  else
379
419
  raise ParseError.new(
380
420
  "Unexpected token `#{node.message}` before `#{last_node&.string&.strip}`",
@@ -382,16 +422,24 @@ module RBI
382
422
  )
383
423
  end
384
424
  else
385
- current_scope << parse_visibility(node.name, node)
425
+ current_scope << parse_visibility(node.name.to_s, node)
386
426
  end
387
427
  when "prop", "const"
388
428
  parse_tstruct_field(node)
389
429
  when "requires_ancestor"
390
430
  block = node.block
391
- return unless block.is_a?(YARP::BlockNode)
431
+
432
+ unless block.is_a?(Prism::BlockNode)
433
+ @last_node = nil
434
+ return
435
+ end
392
436
 
393
437
  body = block.body
394
- return unless body.is_a?(YARP::StatementsNode)
438
+
439
+ unless body.is_a?(Prism::StatementsNode)
440
+ @last_node = nil
441
+ return
442
+ end
395
443
 
396
444
  current_scope << RequiresAncestor.new(
397
445
  node_string!(body),
@@ -408,12 +456,14 @@ module RBI
408
456
  comments: node_comments(node),
409
457
  )
410
458
  end
459
+
460
+ @last_node = nil
411
461
  end
412
462
 
413
463
  private
414
464
 
415
465
  # Collect all the remaining comments within a node
416
- sig { params(node: YARP::Node).void }
466
+ sig { params(node: Prism::Node).void }
417
467
  def collect_dangling_comments(node)
418
468
  first_line = node.location.start_line
419
469
  last_line = node.location.end_line
@@ -446,7 +496,7 @@ module RBI
446
496
 
447
497
  # Preserve blank lines in comments
448
498
  if last_line && line > last_line + 1
449
- recv << BlankLine.new(loc: Loc.from_yarp(@file, comment.location))
499
+ recv << BlankLine.new(loc: Loc.from_prism(@file, comment.location))
450
500
  end
451
501
 
452
502
  recv << parse_comment(comment)
@@ -473,7 +523,7 @@ module RBI
473
523
  comments
474
524
  end
475
525
 
476
- sig { params(node: YARP::Node).returns(T::Array[Comment]) }
526
+ sig { params(node: Prism::Node).returns(T::Array[Comment]) }
477
527
  def node_comments(node)
478
528
  comments = []
479
529
 
@@ -491,21 +541,21 @@ module RBI
491
541
  comments
492
542
  end
493
543
 
494
- sig { params(node: YARP::Comment).returns(Comment) }
544
+ sig { params(node: Prism::Comment).returns(Comment) }
495
545
  def parse_comment(node)
496
- Comment.new(node.location.slice.gsub(/^# ?/, "").rstrip, loc: Loc.from_yarp(@file, node.location))
546
+ Comment.new(node.location.slice.gsub(/^# ?/, "").rstrip, loc: Loc.from_prism(@file, node.location))
497
547
  end
498
548
 
499
- sig { params(node: T.nilable(YARP::Node)).returns(T::Array[Arg]) }
549
+ sig { params(node: T.nilable(Prism::Node)).returns(T::Array[Arg]) }
500
550
  def parse_send_args(node)
501
551
  args = T.let([], T::Array[Arg])
502
- return args unless node.is_a?(YARP::ArgumentsNode)
552
+ return args unless node.is_a?(Prism::ArgumentsNode)
503
553
 
504
554
  node.arguments.each do |arg|
505
555
  case arg
506
- when YARP::KeywordHashNode
556
+ when Prism::KeywordHashNode
507
557
  arg.elements.each do |assoc|
508
- next unless assoc.is_a?(YARP::AssocNode)
558
+ next unless assoc.is_a?(Prism::AssocNode)
509
559
 
510
560
  args << KwArg.new(
511
561
  node_string!(assoc.key).delete_suffix(":"),
@@ -520,13 +570,13 @@ module RBI
520
570
  args
521
571
  end
522
572
 
523
- sig { params(node: T.nilable(YARP::Node)).returns(T::Array[Param]) }
573
+ sig { params(node: T.nilable(Prism::Node)).returns(T::Array[Param]) }
524
574
  def parse_params(node)
525
575
  params = []
526
- return params unless node.is_a?(YARP::ParametersNode)
576
+ return params unless node.is_a?(Prism::ParametersNode)
527
577
 
528
578
  node.requireds.each do |param|
529
- next unless param.is_a?(YARP::RequiredParameterNode)
579
+ next unless param.is_a?(Prism::RequiredParameterNode)
530
580
 
531
581
  params << ReqParam.new(
532
582
  param.name.to_s,
@@ -536,7 +586,7 @@ module RBI
536
586
  end
537
587
 
538
588
  node.optionals.each do |param|
539
- next unless param.is_a?(YARP::OptionalParameterNode)
589
+ next unless param.is_a?(Prism::OptionalParameterNode)
540
590
 
541
591
  params << OptParam.new(
542
592
  param.name.to_s,
@@ -547,28 +597,28 @@ module RBI
547
597
  end
548
598
 
549
599
  rest = node.rest
550
- if rest.is_a?(YARP::RestParameterNode)
600
+ if rest.is_a?(Prism::RestParameterNode)
551
601
  params << RestParam.new(
552
- rest.name || "*args",
602
+ rest.name&.to_s || "*args",
553
603
  loc: node_loc(rest),
554
604
  comments: node_comments(rest),
555
605
  )
556
606
  end
557
607
 
558
608
  node.keywords.each do |param|
559
- next unless param.is_a?(YARP::KeywordParameterNode)
609
+ next unless param.is_a?(Prism::KeywordParameterNode)
560
610
 
561
611
  value = param.value
562
612
  params << if value
563
613
  KwOptParam.new(
564
- param.name.delete_suffix(":"),
614
+ param.name.to_s.delete_suffix(":"),
565
615
  node_string!(value),
566
616
  loc: node_loc(param),
567
617
  comments: node_comments(param),
568
618
  )
569
619
  else
570
620
  KwParam.new(
571
- param.name.delete_suffix(":"),
621
+ param.name.to_s.delete_suffix(":"),
572
622
  loc: node_loc(param),
573
623
  comments: node_comments(param),
574
624
  )
@@ -576,18 +626,18 @@ module RBI
576
626
  end
577
627
 
578
628
  rest_kw = node.keyword_rest
579
- if rest_kw.is_a?(YARP::KeywordRestParameterNode)
629
+ if rest_kw.is_a?(Prism::KeywordRestParameterNode)
580
630
  params << KwRestParam.new(
581
- rest_kw.name || "**kwargs",
631
+ rest_kw.name&.to_s || "**kwargs",
582
632
  loc: node_loc(rest_kw),
583
633
  comments: node_comments(rest_kw),
584
634
  )
585
635
  end
586
636
 
587
637
  block = node.block
588
- if block.is_a?(YARP::BlockParameterNode)
638
+ if block.is_a?(Prism::BlockParameterNode)
589
639
  params << BlockParam.new(
590
- block.name || "&block",
640
+ block.name&.to_s || "&block",
591
641
  loc: node_loc(block),
592
642
  comments: node_comments(block),
593
643
  )
@@ -596,7 +646,7 @@ module RBI
596
646
  params
597
647
  end
598
648
 
599
- sig { params(node: YARP::CallNode).returns(Sig) }
649
+ sig { params(node: Prism::CallNode).returns(Sig) }
600
650
  def parse_sig(node)
601
651
  @last_sigs_comments = node_comments(node)
602
652
 
@@ -606,10 +656,10 @@ module RBI
606
656
  builder.current
607
657
  end
608
658
 
609
- sig { params(node: T.any(YARP::ConstantWriteNode, YARP::ConstantPathWriteNode)).returns(T.nilable(Struct)) }
659
+ sig { params(node: T.any(Prism::ConstantWriteNode, Prism::ConstantPathWriteNode)).returns(T.nilable(Struct)) }
610
660
  def parse_struct(node)
611
661
  send = node.value
612
- return unless send.is_a?(YARP::CallNode)
662
+ return unless send.is_a?(Prism::CallNode)
613
663
  return unless send.message == "new"
614
664
 
615
665
  recv = send.receiver
@@ -620,14 +670,14 @@ module RBI
620
670
  keyword_init = T.let(false, T::Boolean)
621
671
 
622
672
  args = send.arguments
623
- if args.is_a?(YARP::ArgumentsNode)
673
+ if args.is_a?(Prism::ArgumentsNode)
624
674
  args.arguments.each do |arg|
625
675
  case arg
626
- when YARP::SymbolNode
676
+ when Prism::SymbolNode
627
677
  members << arg.value
628
- when YARP::KeywordHashNode
678
+ when Prism::KeywordHashNode
629
679
  arg.elements.each do |assoc|
630
- next unless assoc.is_a?(YARP::AssocNode)
680
+ next unless assoc.is_a?(Prism::AssocNode)
631
681
 
632
682
  key = node_string!(assoc.key)
633
683
  val = node_string(assoc.value)
@@ -641,9 +691,9 @@ module RBI
641
691
  end
642
692
 
643
693
  name = case node
644
- when YARP::ConstantWriteNode
645
- node.name
646
- when YARP::ConstantPathWriteNode
694
+ when Prism::ConstantWriteNode
695
+ node.name.to_s
696
+ when Prism::ConstantPathWriteNode
647
697
  node_string!(node.target)
648
698
  end
649
699
 
@@ -656,10 +706,10 @@ module RBI
656
706
  struct
657
707
  end
658
708
 
659
- sig { params(send: YARP::CallNode).void }
709
+ sig { params(send: Prism::CallNode).void }
660
710
  def parse_tstruct_field(send)
661
711
  args = send.arguments
662
- return unless args.is_a?(YARP::ArgumentsNode)
712
+ return unless args.is_a?(Prism::ArgumentsNode)
663
713
 
664
714
  name_arg, type_arg, *rest = args.arguments
665
715
  return unless name_arg
@@ -672,10 +722,10 @@ module RBI
672
722
  default_value = T.let(nil, T.nilable(String))
673
723
 
674
724
  rest&.each do |arg|
675
- next unless arg.is_a?(YARP::KeywordHashNode)
725
+ next unless arg.is_a?(Prism::KeywordHashNode)
676
726
 
677
727
  arg.elements.each do |assoc|
678
- next unless assoc.is_a?(YARP::AssocNode)
728
+ next unless assoc.is_a?(Prism::AssocNode)
679
729
 
680
730
  if node_string(assoc.key) == "default:"
681
731
  default_value = node_string(assoc.value)
@@ -693,7 +743,7 @@ module RBI
693
743
  end
694
744
  end
695
745
 
696
- sig { params(name: String, node: YARP::Node).returns(Visibility) }
746
+ sig { params(name: String, node: Prism::Node).returns(Visibility) }
697
747
  def parse_visibility(name, node)
698
748
  case name
699
749
  when "public"
@@ -731,9 +781,9 @@ module RBI
731
781
  )
732
782
  end
733
783
 
734
- sig { params(node: T.nilable(YARP::Node)).returns(T::Boolean) }
784
+ sig { params(node: T.nilable(Prism::Node)).returns(T::Boolean) }
735
785
  def type_variable_definition?(node)
736
- return false unless node.is_a?(YARP::CallNode)
786
+ return false unless node.is_a?(Prism::CallNode)
737
787
  return false unless node.block
738
788
 
739
789
  node.message == "type_member" || node.message == "type_template"
@@ -744,7 +794,7 @@ module RBI
744
794
  extend T::Sig
745
795
 
746
796
  sig { returns(Sig) }
747
- attr_accessor :current
797
+ attr_reader :current
748
798
 
749
799
  sig { params(content: String, file: String).void }
750
800
  def initialize(content, file:)
@@ -753,12 +803,12 @@ module RBI
753
803
  @current = T.let(Sig.new, Sig)
754
804
  end
755
805
 
756
- sig { override.params(node: YARP::CallNode).void }
806
+ sig { override.params(node: Prism::CallNode).void }
757
807
  def visit_call_node(node)
758
808
  case node.message
759
809
  when "sig"
760
810
  args = node.arguments
761
- if args.is_a?(YARP::ArgumentsNode)
811
+ if args.is_a?(Prism::ArgumentsNode)
762
812
  args.arguments.each do |arg|
763
813
  @current.is_final = node_string(arg) == ":final"
764
814
  end
@@ -767,7 +817,7 @@ module RBI
767
817
  @current.is_abstract = true
768
818
  when "checked"
769
819
  args = node.arguments
770
- if args.is_a?(YARP::ArgumentsNode)
820
+ if args.is_a?(Prism::ArgumentsNode)
771
821
  arg = node_string(args.arguments.first)
772
822
  @current.checked = arg&.delete_prefix(":")&.to_sym
773
823
  end
@@ -779,13 +829,13 @@ module RBI
779
829
  visit(node.arguments)
780
830
  when "returns"
781
831
  args = node.arguments
782
- if args.is_a?(YARP::ArgumentsNode)
832
+ if args.is_a?(Prism::ArgumentsNode)
783
833
  first = args.arguments.first
784
834
  @current.return_type = node_string!(first) if first
785
835
  end
786
836
  when "type_parameters"
787
837
  args = node.arguments
788
- if args.is_a?(YARP::ArgumentsNode)
838
+ if args.is_a?(Prism::ArgumentsNode)
789
839
  args.arguments.each do |arg|
790
840
  @current.type_params << node_string!(arg).delete_prefix(":")
791
841
  end
@@ -798,7 +848,7 @@ module RBI
798
848
  visit(node.block)
799
849
  end
800
850
 
801
- sig { override.params(node: YARP::AssocNode).void }
851
+ sig { override.params(node: Prism::AssocNode).void }
802
852
  def visit_assoc_node(node)
803
853
  @current.params << SigParam.new(
804
854
  node_string!(node.key).delete_suffix(":"),
data/lib/rbi/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RBI
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-07 00:00:00.000000000 Z
11
+ date: 2023-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sorbet-runtime
14
+ name: prism
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.9204
19
+ version: 0.15.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.9204
26
+ version: 0.15.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: yarp
28
+ name: sorbet-runtime
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.0
33
+ version: 0.5.9204
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.0
40
+ version: 0.5.9204
41
41
  description:
42
42
  email:
43
43
  - ruby@shopify.com
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.4.19
89
+ rubygems_version: 3.4.21
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: RBI generation framework