rbs 0.3.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +39 -0
  5. data/COPYING +1 -1
  6. data/Gemfile +16 -2
  7. data/README.md +87 -48
  8. data/Rakefile +54 -22
  9. data/bin/rbs-prof +9 -0
  10. data/bin/run_in_md.rb +49 -0
  11. data/bin/test_runner.rb +0 -2
  12. data/docs/sigs.md +6 -6
  13. data/docs/stdlib.md +3 -5
  14. data/docs/syntax.md +6 -3
  15. data/goodcheck.yml +65 -0
  16. data/lib/rbs.rb +3 -0
  17. data/lib/rbs/ast/declarations.rb +115 -14
  18. data/lib/rbs/ast/members.rb +41 -17
  19. data/lib/rbs/cli.rb +315 -122
  20. data/lib/rbs/constant.rb +4 -4
  21. data/lib/rbs/constant_table.rb +51 -45
  22. data/lib/rbs/definition.rb +175 -59
  23. data/lib/rbs/definition_builder.rb +802 -604
  24. data/lib/rbs/environment.rb +352 -210
  25. data/lib/rbs/environment_walker.rb +14 -23
  26. data/lib/rbs/errors.rb +184 -3
  27. data/lib/rbs/factory.rb +14 -0
  28. data/lib/rbs/parser.y +95 -27
  29. data/lib/rbs/prototype/rb.rb +119 -117
  30. data/lib/rbs/prototype/rbi.rb +5 -3
  31. data/lib/rbs/prototype/runtime.rb +34 -7
  32. data/lib/rbs/substitution.rb +12 -1
  33. data/lib/rbs/test.rb +82 -3
  34. data/lib/rbs/test/errors.rb +5 -1
  35. data/lib/rbs/test/hook.rb +133 -259
  36. data/lib/rbs/test/observer.rb +17 -0
  37. data/lib/rbs/test/setup.rb +35 -19
  38. data/lib/rbs/test/setup_helper.rb +29 -0
  39. data/lib/rbs/test/spy.rb +0 -321
  40. data/lib/rbs/test/tester.rb +116 -0
  41. data/lib/rbs/test/type_check.rb +43 -7
  42. data/lib/rbs/type_name_resolver.rb +58 -0
  43. data/lib/rbs/types.rb +94 -2
  44. data/lib/rbs/validator.rb +51 -0
  45. data/lib/rbs/variance_calculator.rb +12 -2
  46. data/lib/rbs/version.rb +1 -1
  47. data/lib/rbs/writer.rb +127 -91
  48. data/rbs.gemspec +0 -9
  49. data/schema/annotation.json +14 -0
  50. data/schema/comment.json +26 -0
  51. data/schema/decls.json +353 -0
  52. data/schema/function.json +87 -0
  53. data/schema/location.json +56 -0
  54. data/schema/members.json +248 -0
  55. data/schema/methodType.json +44 -0
  56. data/schema/types.json +299 -0
  57. data/stdlib/benchmark/benchmark.rbs +151 -151
  58. data/stdlib/builtin/encoding.rbs +2 -0
  59. data/stdlib/builtin/enumerable.rbs +4 -4
  60. data/stdlib/builtin/enumerator.rbs +3 -1
  61. data/stdlib/builtin/fiber.rbs +5 -1
  62. data/stdlib/builtin/file.rbs +0 -3
  63. data/stdlib/builtin/io.rbs +4 -4
  64. data/stdlib/builtin/proc.rbs +1 -2
  65. data/stdlib/builtin/symbol.rbs +1 -1
  66. data/stdlib/builtin/thread.rbs +2 -2
  67. data/stdlib/csv/csv.rbs +4 -6
  68. data/stdlib/fiber/fiber.rbs +117 -0
  69. data/stdlib/json/json.rbs +1 -1
  70. data/stdlib/logger/formatter.rbs +23 -0
  71. data/stdlib/logger/log_device.rbs +39 -0
  72. data/stdlib/logger/logger.rbs +507 -0
  73. data/stdlib/logger/period.rbs +7 -0
  74. data/stdlib/logger/severity.rbs +8 -0
  75. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  76. data/stdlib/pathname/pathname.rbs +6 -6
  77. data/stdlib/prime/integer-extension.rbs +1 -1
  78. data/stdlib/prime/prime.rbs +44 -44
  79. data/stdlib/pty/pty.rbs +159 -0
  80. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  81. metadata +28 -116
  82. data/lib/rbs/test/test_helper.rb +0 -183
@@ -23,13 +23,9 @@ module RBS
23
23
  include TSort
24
24
 
25
25
  def tsort_each_node(&block)
26
- env.each_decl do |name|
27
- yield name.absolute!
28
- end
29
-
30
- env.each_alias do |name, _|
31
- yield name.absolute!
32
- end
26
+ env.class_decls.each_key(&block)
27
+ env.interface_decls.each_key(&block)
28
+ env.alias_decls.each_key(&block)
33
29
  end
34
30
 
35
31
  def tsort_each_child(name, &block)
@@ -46,31 +42,26 @@ module RBS
46
42
  definitions << builder.build_instance(name)
47
43
  definitions << builder.build_singleton(name)
48
44
  when name.interface?
49
- definitions << builder.build_interface(name, env.find_class(name))
45
+ definitions << builder.build_interface(name)
50
46
  end
51
47
 
52
48
  definitions.each do |definition|
53
- definition.ancestors.each do |ancestor|
54
- yield ancestor.name
49
+ if ancestors = definition.ancestors
50
+ ancestors.ancestors.each do |ancestor|
51
+ yield ancestor.name
55
52
 
56
- case ancestor
57
- when Definition::Ancestor::Instance, Definition::Ancestor::ExtensionInstance
58
- ancestor.args.each do |type|
59
- each_type_name type, &block
53
+ case ancestor
54
+ when Definition::Ancestor::Instance
55
+ ancestor.args.each do |type|
56
+ each_type_name type, &block
57
+ end
60
58
  end
61
59
  end
62
60
  end
63
61
 
64
62
  unless only_ancestors?
65
- definition.methods.each do |_, method|
66
- method.method_types.each do |method_type|
67
- method_type.type.each_type do |type|
68
- each_type_name type, &block
69
- end
70
- method_type.block&.type&.each_type do |type|
71
- each_type_name type, &block
72
- end
73
- end
63
+ definition.each_type do |type|
64
+ each_type_name type, &block
74
65
  end
75
66
  end
76
67
  end
@@ -1,4 +1,19 @@
1
1
  module RBS
2
+ module MethodNameHelper
3
+ def method_name_string()
4
+ separator = case kind
5
+ when :instance
6
+ "#"
7
+ when :singleton
8
+ "."
9
+ else
10
+ raise
11
+ end
12
+
13
+ "#{type_name}#{separator}#{method_name}"
14
+ end
15
+ end
16
+
2
17
  class InvalidTypeApplicationError < StandardError
3
18
  attr_reader :type_name
4
19
  attr_reader :args
@@ -10,7 +25,7 @@ module RBS
10
25
  @args = args
11
26
  @params = params
12
27
  @location = location
13
- super "#{Location.to_string location}: #{type_name} expects parameters [#{params.each.map(&:name).join(", ")}], but given args [#{args.join(", ")}]"
28
+ super "#{Location.to_string location}: #{type_name} expects parameters [#{params.join(", ")}], but given args [#{args.join(", ")}]"
14
29
  end
15
30
 
16
31
  def self.check!(type_name:, args:, params:, location:)
@@ -93,13 +108,91 @@ module RBS
93
108
  end
94
109
 
95
110
  def self.check!(type_name, env:, location:)
96
- env.find_type_decl(type_name) or
97
- raise new(type_name: type_name, location: location)
111
+ dic = case
112
+ when type_name.class?
113
+ env.class_decls
114
+ when type_name.alias?
115
+ env.alias_decls
116
+ when type_name.interface?
117
+ env.interface_decls
118
+ else
119
+ raise
120
+ end
121
+
122
+ dic.key?(type_name) or raise new(type_name: type_name, location: location)
98
123
 
99
124
  type_name
100
125
  end
101
126
  end
102
127
 
128
+ class NoSuperclassFoundError < StandardError
129
+ attr_reader :type_name
130
+ attr_reader :location
131
+
132
+ def initialize(type_name:, location:)
133
+ @type_name = type_name
134
+ @location = location
135
+
136
+ super "#{Location.to_string location}: Could not find super class: #{type_name}"
137
+ end
138
+
139
+ def self.check!(type_name, env:, location:)
140
+ env.class_decls.key?(type_name) or raise new(type_name: type_name, location: location)
141
+ end
142
+ end
143
+
144
+ class NoSelfTypeFoundError < StandardError
145
+ attr_reader :type_name
146
+ attr_reader :location
147
+
148
+ def initialize(type_name:, location:)
149
+ @type_name = type_name
150
+ @location = location
151
+
152
+ super "#{Location.to_string location}: Could not find self type: #{type_name}"
153
+ end
154
+
155
+ def self.check!(self_type, env:)
156
+ type_name = self_type.name
157
+
158
+ dic = case
159
+ when type_name.class?
160
+ env.class_decls
161
+ when type_name.interface?
162
+ env.interface_decls
163
+ end
164
+
165
+ dic.key?(type_name) or raise new(type_name: type_name, location: self_type.location)
166
+ end
167
+ end
168
+
169
+ class NoMixinFoundError < StandardError
170
+ attr_reader :type_name
171
+ attr_reader :member
172
+
173
+ def initialize(type_name:, member:)
174
+ @type_name = type_name
175
+ @member = member
176
+
177
+ super "#{Location.to_string location}: Could not find mixin: #{type_name}"
178
+ end
179
+
180
+ def location
181
+ member.location
182
+ end
183
+
184
+ def self.check!(type_name, env:, member:)
185
+ dic = case
186
+ when type_name.class?
187
+ env.class_decls
188
+ when type_name.interface?
189
+ env.interface_decls
190
+ end
191
+
192
+ dic.key?(type_name) or raise new(type_name: type_name, member: member)
193
+ end
194
+ end
195
+
103
196
  class DuplicatedMethodDefinitionError < StandardError
104
197
  attr_reader :decl
105
198
  attr_reader :location
@@ -122,6 +215,26 @@ module RBS
122
215
  end
123
216
  end
124
217
 
218
+ class MethodDefinitionConflictWithInterfaceMixinError < StandardError
219
+ include MethodNameHelper
220
+
221
+ attr_reader :type_name
222
+ attr_reader :method_name
223
+ attr_reader :kind
224
+ attr_reader :mixin_member
225
+ attr_reader :entries
226
+
227
+ def initialize(type_name:, method_name:, kind:, mixin_member:, entries:)
228
+ @type_name = type_name
229
+ @method_name = method_name
230
+ @kind = kind
231
+ @mixin_member = mixin_member
232
+ @entries = entries
233
+
234
+ super "#{entries[0].decl.location}: Duplicated method with interface mixin: #{method_name_string}"
235
+ end
236
+ end
237
+
125
238
  class UnknownMethodAliasError < StandardError
126
239
  attr_reader :original_name
127
240
  attr_reader :aliased_name
@@ -142,6 +255,74 @@ module RBS
142
255
  end
143
256
  end
144
257
 
258
+ class SuperclassMismatchError < StandardError
259
+ attr_reader :name
260
+ attr_reader :entry
261
+
262
+ def initialize(name:, super_classes:, entry:)
263
+ @name = name
264
+ @entry = entry
265
+ super "#{Location.to_string entry.primary.decl.location}: Superclass mismatch: #{name}"
266
+ end
267
+ end
268
+
269
+ class InconsistentMethodVisibilityError < StandardError
270
+ attr_reader :type_name
271
+ attr_reader :method_name
272
+ attr_reader :kind
273
+ attr_reader :member_pairs
274
+
275
+ def initialize(type_name:, method_name:, kind:, member_pairs:)
276
+ @type_name = type_name
277
+ @method_name = method_name
278
+ @kind = kind
279
+ @member_pairs = member_pairs
280
+
281
+ delimiter = case kind
282
+ when :instance
283
+ "#"
284
+ when :singleton
285
+ "."
286
+ end
287
+
288
+ super "#{Location.to_string member_pairs[0][0].location}: Inconsistent method visibility: #{type_name}#{delimiter}#{method_name}"
289
+ end
290
+ end
291
+
292
+ class InvalidOverloadMethodError < StandardError
293
+ attr_reader :type_name
294
+ attr_reader :method_name
295
+ attr_reader :kind
296
+ attr_reader :members
297
+
298
+ def initialize(type_name:, method_name:, kind:, members:)
299
+ @type_name = type_name
300
+ @method_name = method_name
301
+ @kind = kind
302
+ @members = members
303
+
304
+ delimiter = case kind
305
+ when :instance
306
+ "#"
307
+ when :singleton
308
+ "."
309
+ end
310
+
311
+ super "#{Location.to_string members[0].location}: Invalid method overloading: #{type_name}#{delimiter}#{method_name}"
312
+ end
313
+ end
314
+
315
+ class GenericParameterMismatchError < StandardError
316
+ attr_reader :name
317
+ attr_reader :decl
318
+
319
+ def initialize(name:, decl:)
320
+ @name = name
321
+ @decl = decl
322
+ super "#{Location.to_string decl.location}: Generic parameters mismatch: #{name}"
323
+ end
324
+ end
325
+
145
326
  class DuplicatedDeclarationError < StandardError
146
327
  attr_reader :name
147
328
  attr_reader :decls
@@ -0,0 +1,14 @@
1
+ module RBS
2
+ class Factory
3
+ def type_name(string)
4
+ absolute = string.start_with?("::")
5
+
6
+ *path, name = string.delete_prefix("::").split("::").map(&:to_sym)
7
+
8
+ TypeName.new(
9
+ name: name,
10
+ namespace: Namespace.new(path: path, absolute: absolute)
11
+ )
12
+ end
13
+ end
14
+ end
@@ -4,13 +4,13 @@ class RBS::Parser
4
4
  tANNOTATION
5
5
  tSTRING tSYMBOL tINTEGER tWRITE_ATTR
6
6
  kLPAREN kRPAREN kLBRACKET kRBRACKET kLBRACE kRBRACE
7
- kVOID kNIL kTRUE kFALSE kANY kUNTYPED kTOP kBOT kSELF kSELFQ kINSTANCE kCLASS kBOOL kSINGLETON kTYPE kDEF kMODULE kSUPER
7
+ kVOID kNIL kTRUE kFALSE kANY kUNTYPED kTOP kBOT kSELF kSELFQ kINSTANCE kCLASS kBOOL kSINGLETON kTYPE kDEF kMODULE
8
8
  kPRIVATE kPUBLIC kALIAS
9
- kCOLON kCOLON2 kCOMMA kBAR kAMP kHAT kARROW kQUESTION kEXCLAMATION kSTAR kSTAR2 kFATARROW kEQ kDOT kLT
9
+ kCOLON kCOLON2 kCOMMA kBAR kAMP kHAT kARROW kQUESTION kEXCLAMATION kSTAR kSTAR2 kFATARROW kEQ kDOT kDOT3 kLT
10
10
  kINTERFACE kEND kINCLUDE kEXTEND kATTRREADER kATTRWRITER kATTRACCESSOR tOPERATOR tQUOTEDMETHOD tQUOTEDIDENT
11
11
  kPREPEND kEXTENSION kINCOMPATIBLE
12
12
  type_TYPE type_SIGNATURE type_METHODTYPE tEOF
13
- kOUT kIN kUNCHECKED
13
+ kOUT kIN kUNCHECKED kOVERLOAD
14
14
 
15
15
  prechigh
16
16
  nonassoc kQUESTION
@@ -106,28 +106,28 @@ rule
106
106
  }
107
107
 
108
108
  module_decl:
109
- annotations kMODULE start_new_scope class_name module_type_params module_self_type class_members kEND {
109
+ annotations kMODULE start_new_scope class_name module_type_params colon_module_self_types class_members kEND {
110
110
  reset_variable_scope
111
111
 
112
112
  location = val[1].location + val[7].location
113
113
  result = Declarations::Module.new(
114
114
  name: val[3].value,
115
115
  type_params: val[4]&.value || Declarations::ModuleTypeParams.empty,
116
- self_type: val[5],
116
+ self_types: val[5],
117
117
  members: val[6],
118
118
  annotations: val[0],
119
119
  location: location,
120
120
  comment: leading_comment(val[0].first&.location || location)
121
121
  )
122
122
  }
123
- | annotations kMODULE start_new_scope tUKEYWORD type class_members kEND {
123
+ | annotations kMODULE start_new_scope tUKEYWORD module_self_types class_members kEND {
124
124
  reset_variable_scope
125
125
 
126
126
  location = val[1].location + val[6].location
127
127
  result = Declarations::Module.new(
128
128
  name: val[3].value,
129
129
  type_params: Declarations::ModuleTypeParams.empty,
130
- self_type: val[4],
130
+ self_types: val[4],
131
131
  members: val[5],
132
132
  annotations: val[0],
133
133
  location: location,
@@ -135,12 +135,50 @@ rule
135
135
  )
136
136
  }
137
137
 
138
- module_self_type:
139
- { result = nil }
140
- | kCOLON type {
138
+ colon_module_self_types:
139
+ { result = [] }
140
+ | kCOLON module_self_types {
141
141
  result = val[1]
142
142
  }
143
143
 
144
+ module_self_types:
145
+ module_self_type {
146
+ result = [val[0]]
147
+ }
148
+ | module_self_types kCOMMA module_self_type {
149
+ result = val[0].push(val[2])
150
+ }
151
+
152
+ module_self_type:
153
+ qualified_name kLBRACKET type_list kRBRACKET {
154
+ name = val[0].value
155
+ args = val[2]
156
+ location = val[0].location + val[3].location
157
+
158
+ case
159
+ when name.class?
160
+ result = Declarations::Module::Self.new(name: name, args: args, location: location)
161
+ when name.interface?
162
+ result = Declarations::Module::Self.new(name: name, args: args, location: location)
163
+ else
164
+ raise SemanticsError.new("Module self type should be instance or interface", subject: val[0], location: val[0].location)
165
+ end
166
+ }
167
+ | qualified_name {
168
+ name = val[0].value
169
+ args = []
170
+ location = val[0].location
171
+
172
+ case
173
+ when name.class?
174
+ result = Declarations::Module::Self.new(name: name, args: args, location: location)
175
+ when name.interface?
176
+ result = Declarations::Module::Self.new(name: name, args: args, location: location)
177
+ else
178
+ raise SemanticsError.new("Module self type should be instance or interface", subject: val[0], location: val[0].location)
179
+ end
180
+ }
181
+
144
182
  class_members:
145
183
  { result = [] }
146
184
  | class_members class_member {
@@ -161,6 +199,7 @@ rule
161
199
  result = Members::Private.new(location: val[0].location)
162
200
  }
163
201
  | alias_member
202
+ | signature
164
203
 
165
204
  attribute_member:
166
205
  annotations kATTRREADER keyword type {
@@ -386,10 +425,17 @@ rule
386
425
  comment: leading_comment(val[0].first&.location || location))
387
426
  }
388
427
 
428
+ overload:
429
+ { result = nil }
430
+ | kOVERLOAD {
431
+ RBS.logger.warn "`overload def` syntax is deprecated. Use `...` syntax instead."
432
+ result = val[0]
433
+ }
434
+
389
435
  method_member:
390
- annotations attributes kDEF method_kind def_name method_types {
391
- location = val[2].location + val[5].last.location
392
- types = val[5].map do |type|
436
+ annotations attributes overload kDEF method_kind def_name method_types {
437
+ location = val[3].location + val[6].last.location
438
+ types = val[6].map do |type|
393
439
  case type
394
440
  when LocatedValue
395
441
  type.value
@@ -397,14 +443,24 @@ rule
397
443
  type
398
444
  end
399
445
  end
446
+
447
+ last_type = val[6].last
448
+ if last_type.is_a?(LocatedValue) && last_type.value == :dot3
449
+ overload = true
450
+ val[6].pop
451
+ else
452
+ overload = false
453
+ end
454
+
400
455
  result = Members::MethodDefinition.new(
401
- name: val[4].value,
402
- kind: val[3],
403
- types: types,
456
+ name: val[5].value,
457
+ kind: val[4],
458
+ types: val[6],
404
459
  annotations: val[0],
405
460
  location: location,
406
- comment: leading_comment(val[0].first&.location || val[1].first&.location || val[2].location),
407
- attributes: val[1].map(&:value)
461
+ comment: leading_comment(val[0].first&.location || val[1].first&.location || val[2]&.location || val[3].location),
462
+ attributes: val[1].map(&:value),
463
+ overload: overload || !!val[2]
408
464
  )
409
465
  }
410
466
 
@@ -421,7 +477,7 @@ rule
421
477
 
422
478
  method_types:
423
479
  method_type { result = [val[0]] }
424
- | kSUPER { result = [LocatedValue.new(value: :super, location: val[0].location)] }
480
+ | kDOT3 { result = [LocatedValue.new(value: :dot3, location: val[0].location)] }
425
481
  | method_type kBAR method_types {
426
482
  result = val[2].unshift(val[0])
427
483
  }
@@ -478,7 +534,7 @@ rule
478
534
 
479
535
  method_name:
480
536
  tOPERATOR
481
- | kAMP | kHAT | kSTAR | kLT | kEXCLAMATION | kSTAR2 | kBAR | kOUT | kIN
537
+ | kAMP | kHAT | kSTAR | kLT | kEXCLAMATION | kSTAR2 | kBAR
482
538
  | method_name0
483
539
  | method_name0 kQUESTION {
484
540
  unless val[0].location.pred?(val[1].location)
@@ -500,13 +556,13 @@ rule
500
556
  | tQUOTEDIDENT
501
557
  | tWRITE_ATTR
502
558
 
503
- method_name0: tUIDENT | tLIDENT | identifier_keywords
559
+ method_name0: tUIDENT | tLIDENT | tINTERFACEIDENT | identifier_keywords
504
560
 
505
561
  identifier_keywords:
506
562
  kCLASS | kVOID | kNIL | kTRUE | kFALSE | kANY | kUNTYPED | kTOP | kBOT | kINSTANCE | kBOOL | kSINGLETON
507
563
  | kTYPE | kMODULE | kPRIVATE | kPUBLIC | kEND | kINCLUDE | kEXTEND | kPREPEND
508
564
  | kATTRREADER | kATTRACCESSOR | kATTRWRITER | kDEF | kEXTENSION | kSELF | kINCOMPATIBLE
509
- | kUNCHECKED
565
+ | kUNCHECKED | kINTERFACE | kALIAS | kOUT | kIN | kOVERLOAD
510
566
 
511
567
  module_type_params:
512
568
  { result = nil }
@@ -1026,6 +1082,7 @@ def initialize(type, buffer:, eof_re:)
1026
1082
  @eof = false
1027
1083
  @bound_variables_stack = []
1028
1084
  @comments = {}
1085
+ @ascii_only = buffer.content.ascii_only?
1029
1086
  end
1030
1087
 
1031
1088
  def start_merged_variables_scope
@@ -1119,8 +1176,9 @@ def push_comment(string, location)
1119
1176
  end
1120
1177
 
1121
1178
  def new_token(type, value = input.matched)
1122
- start_index = input.charpos - input.matched.size
1123
- end_index = input.charpos
1179
+ charpos = charpos(input)
1180
+ start_index = charpos - input.matched.size
1181
+ end_index = charpos
1124
1182
 
1125
1183
  location = RBS::Location.new(buffer: buffer,
1126
1184
  start_pos: start_index,
@@ -1129,6 +1187,14 @@ def new_token(type, value = input.matched)
1129
1187
  [type, LocatedValue.new(location: location, value: value)]
1130
1188
  end
1131
1189
 
1190
+ def charpos(scanner)
1191
+ if @ascii_only
1192
+ scanner.pos
1193
+ else
1194
+ scanner.charpos
1195
+ end
1196
+ end
1197
+
1132
1198
  def empty_params_result
1133
1199
  [
1134
1200
  [],
@@ -1166,13 +1232,13 @@ KEYWORDS = {
1166
1232
  "attr_reader" => :kATTRREADER,
1167
1233
  "attr_writer" => :kATTRWRITER,
1168
1234
  "attr_accessor" => :kATTRACCESSOR,
1169
- "super" => :kSUPER,
1170
1235
  "public" => :kPUBLIC,
1171
1236
  "private" => :kPRIVATE,
1172
1237
  "alias" => :kALIAS,
1173
1238
  "extension" => :kEXTENSION,
1174
1239
  "incompatible" => :kINCOMPATIBLE,
1175
1240
  "unchecked" => :kUNCHECKED,
1241
+ "overload" => :kOVERLOAD,
1176
1242
  "out" => :kOUT,
1177
1243
  "in" => :kIN,
1178
1244
  }
@@ -1214,6 +1280,7 @@ PUNCTS = {
1214
1280
  "!" => :kEXCLAMATION,
1215
1281
  "**" => :kSTAR2,
1216
1282
  "*" => :kSTAR,
1283
+ "..." => :kDOT3,
1217
1284
  "." => :kDOT,
1218
1285
  "<" => :kLT,
1219
1286
  "-@" => :tOPERATOR,
@@ -1245,8 +1312,9 @@ def next_token
1245
1312
  when input.scan(/\s+/)
1246
1313
  # skip
1247
1314
  when input.scan(/#(( *)|( ?(?<string>.*)))\n/)
1248
- start_index = input.charpos - input.matched.size
1249
- end_index = input.charpos-1
1315
+ charpos = charpos(input)
1316
+ start_index = charpos - input.matched.size
1317
+ end_index = charpos-1
1250
1318
 
1251
1319
  location = RBS::Location.new(buffer: buffer,
1252
1320
  start_pos: start_index,