rbs-inline 0.7.0 → 0.8.0

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: ae1ebe5ac15f3f5c12c3b162fbcdc754de5544867fbc2d455af7a2028bfc12c7
4
- data.tar.gz: aecd4c155a61ff168e9dea24d22cd9772566b26d973ffe9857e85f369e716a32
3
+ metadata.gz: d5a68634b62b49714735e0b84f748c4e2a646dc1f785644202b76dcbcb7a3937
4
+ data.tar.gz: 19d106b8ff48e0eab47f30751764611437fb13a1cf54bb382738e849217fb2fe
5
5
  SHA512:
6
- metadata.gz: ffb76bf31d5c65a4e50edc61bd5538214d15fca1c4bcf0be83a86c32fbb22f27f5947279bec2919aee94928c236605f3998395a9c4b8f2329f0fe933bdff4e87
7
- data.tar.gz: 7dd187fd1519420e823133a84abb6fc858ac6e8024b899b96a0e6cd6c581b42c332e161e9af67067224d9b95d939e32900eeeb5e61b3c5d405b94433e0c19d17
6
+ metadata.gz: b8f197fbd6ed4bbb17f3715aa314320405561ee2dd8fe61c7a1d61279e8f1c7d2ba166308cee7282114f004a195853f0bb1f736a932466e58000ced915f844d7
7
+ data.tar.gz: 7ae9e4c5a8ecbdc3c9935c698ed5964454c5d1b152e3f637457b96220f959e3489df7906c674f88a99f346879d9cd66768dd4ec7b4a39206030e41c880493344
@@ -754,7 +754,14 @@ module RBS
754
754
  tree = AST::Tree.new(:module_self)
755
755
 
756
756
  tokenizer.consume_token!(K_MODULE_SELF, tree: tree)
757
- tree << parse_type(tokenizer, tree)
757
+ while true
758
+ tree << parse_type(tokenizer, tree)
759
+ if tokenizer.type?(K_COMMA)
760
+ tokenizer.advance(tree, eat: true)
761
+ else
762
+ break
763
+ end
764
+ end
758
765
 
759
766
  tree << parse_optional(tokenizer, K_MINUS2, tree: tree) do
760
767
  parse_comment(tokenizer)
@@ -509,7 +509,7 @@ module RBS
509
509
 
510
510
  # `# @rbs module-self [MODULE_SELF]`
511
511
  class ModuleSelf < Base
512
- attr_reader :constraint #: RBS::AST::Declarations::Module::Self?
512
+ attr_reader :self_types #: Array[RBS::AST::Declarations::Module::Self]
513
513
 
514
514
  attr_reader :comment #: String?
515
515
 
@@ -517,20 +517,34 @@ module RBS
517
517
  def initialize(tree, source)
518
518
  @tree = tree
519
519
  @source = source
520
+ @self_types = []
520
521
 
521
522
  module_self = tree.nth_tree!(1)
522
- type = module_self.nth_type?(1)
523
+ self_trees = module_self.non_trivia_trees
524
+ self_trees.shift
523
525
 
524
- case type
525
- when Types::ClassInstance, Types::Interface
526
- @constraint = RBS::AST::Declarations::Module::Self.new(
527
- name: type.name,
528
- args: type.args,
529
- location: nil
530
- )
526
+ while true
527
+ type = self_trees.shift
528
+ case type
529
+ when Types::ClassInstance, Types::Interface
530
+ @self_types << RBS::AST::Declarations::Module::Self.new(
531
+ name: type.name,
532
+ args: type.args,
533
+ location: nil
534
+ )
535
+ end
536
+
537
+ break if self_trees.empty?
538
+
539
+ next_tree = self_trees.first
540
+ if next_tree.is_a?(Array) && next_tree[0] == :kCOMMA
541
+ self_trees.shift
542
+ else
543
+ break
544
+ end
531
545
  end
532
546
 
533
- if comment = module_self.nth_tree(2)
547
+ if comment = self_trees.first
534
548
  @comment = comment.to_s
535
549
  end
536
550
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RBS
4
4
  module Inline
5
- VERSION = "0.7.0"
5
+ VERSION = "0.8.0"
6
6
  end
7
7
  end
@@ -155,7 +155,7 @@ module RBS
155
155
 
156
156
  translate_members(decl.members, nil, members)
157
157
 
158
- self_types = decl.module_selfs.map { _1.constraint }.compact
158
+ self_types = decl.module_selfs.flat_map { _1.self_types }.compact
159
159
 
160
160
  rbs << RBS::AST::Declarations::Module.new(
161
161
  name: decl.module_name,
@@ -257,10 +257,40 @@ module RBS
257
257
  visibility: nil
258
258
  )
259
259
 
260
+ members = [:singleton, :instance].map do |kind|
261
+ RBS::AST::Members::MethodDefinition.new(
262
+ name: :members,
263
+ kind: kind, #: RBS::AST::MethodDefinition::Kind
264
+ overloads: [
265
+ RBS::AST::Members::MethodDefinition::Overload.new(
266
+ method_type: RBS::MethodType.new(
267
+ type_params: [],
268
+ type: Types::Function.empty(
269
+ Types::Tuple.new(
270
+ types: decl.each_attribute.map do |name, _|
271
+ Types::Literal.new(literal: name, location: nil)
272
+ end,
273
+ location: nil
274
+ )
275
+ ),
276
+ block: nil,
277
+ location: nil
278
+ ),
279
+ annotations: []
280
+ )
281
+ ],
282
+ annotations: [],
283
+ location: nil,
284
+ comment: nil,
285
+ overloading: false,
286
+ visibility: nil
287
+ )
288
+ end
289
+
260
290
  rbs << RBS::AST::Declarations::Class.new(
261
291
  name: decl.constant_name,
262
292
  type_params: [],
263
- members: [*attributes, new],
293
+ members: [*attributes, new, *members],
264
294
  super_class: RBS::AST::Declarations::Class::Super.new(
265
295
  name: RBS::TypeName.new(name: :Data, namespace: RBS::Namespace.empty),
266
296
  args: [],
@@ -365,6 +395,29 @@ module RBS
365
395
  method_type: RBS::MethodType.new(type_params: [], type: method_type, block: nil, location: nil),
366
396
  annotations: []
367
397
  )
398
+
399
+ unless decl.positional_init?
400
+ new.overloads <<
401
+ RBS::AST::Members::MethodDefinition::Overload.new(
402
+ method_type: RBS::MethodType.new(
403
+ type_params: [],
404
+ type: Types::Function.empty(Types::Bases::Instance.new(location: nil)).then do |t|
405
+ t.update(required_positionals: [
406
+ RBS::Types::Function::Param.new(
407
+ type: RBS::Types::Record.new(all_fields: decl.each_attribute.map do |name, attr|
408
+ [name, attr&.type || Types::Bases::Any.new(location: nil)]
409
+ end.to_h, location: nil),
410
+ name: nil,
411
+ location: nil
412
+ )
413
+ ])
414
+ end,
415
+ block: nil,
416
+ location: nil
417
+ ),
418
+ annotations:[]
419
+ )
420
+ end
368
421
  end
369
422
 
370
423
  rbs << RBS::AST::Declarations::Class.new(
@@ -195,7 +195,7 @@ module RBS
195
195
 
196
196
  # `# @rbs module-self [MODULE_SELF]`
197
197
  class ModuleSelf < Base
198
- attr_reader constraint: RBS::AST::Declarations::Module::Self?
198
+ attr_reader self_types: Array[RBS::AST::Declarations::Module::Self]
199
199
 
200
200
  attr_reader comment: String?
201
201
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs-inline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-29 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prism
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.29'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.31'
22
+ version: '1.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.29'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.31'
32
+ version: '1.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rbs
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -103,14 +103,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="
105
105
  - !ruby/object:Gem::Version
106
- version: 3.3.0
106
+ version: 3.1.0
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.5.17
113
+ rubygems_version: 3.5.11
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Inline RBS type declaration.