rbs 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +35 -0
  5. data/Gemfile +14 -0
  6. data/README.md +86 -47
  7. data/Rakefile +53 -21
  8. data/bin/rbs-prof +9 -0
  9. data/bin/run_in_md.rb +49 -0
  10. data/docs/stdlib.md +0 -2
  11. data/docs/syntax.md +6 -3
  12. data/goodcheck.yml +65 -0
  13. data/lib/rbs.rb +3 -0
  14. data/lib/rbs/ast/comment.rb +6 -0
  15. data/lib/rbs/ast/declarations.rb +106 -13
  16. data/lib/rbs/ast/members.rb +41 -17
  17. data/lib/rbs/cli.rb +317 -121
  18. data/lib/rbs/constant.rb +4 -4
  19. data/lib/rbs/constant_table.rb +51 -45
  20. data/lib/rbs/definition.rb +175 -59
  21. data/lib/rbs/definition_builder.rb +814 -604
  22. data/lib/rbs/environment.rb +352 -210
  23. data/lib/rbs/environment_walker.rb +14 -23
  24. data/lib/rbs/errors.rb +184 -3
  25. data/lib/rbs/factory.rb +14 -0
  26. data/lib/rbs/location.rb +15 -0
  27. data/lib/rbs/parser.y +100 -34
  28. data/lib/rbs/prototype/rb.rb +101 -113
  29. data/lib/rbs/prototype/rbi.rb +5 -3
  30. data/lib/rbs/prototype/runtime.rb +11 -7
  31. data/lib/rbs/substitution.rb +12 -1
  32. data/lib/rbs/test.rb +82 -3
  33. data/lib/rbs/test/errors.rb +5 -1
  34. data/lib/rbs/test/hook.rb +133 -259
  35. data/lib/rbs/test/observer.rb +17 -0
  36. data/lib/rbs/test/setup.rb +35 -19
  37. data/lib/rbs/test/setup_helper.rb +29 -0
  38. data/lib/rbs/test/spy.rb +0 -321
  39. data/lib/rbs/test/tester.rb +116 -0
  40. data/lib/rbs/test/type_check.rb +43 -7
  41. data/lib/rbs/type_name_resolver.rb +58 -0
  42. data/lib/rbs/types.rb +94 -2
  43. data/lib/rbs/validator.rb +55 -0
  44. data/lib/rbs/variance_calculator.rb +12 -2
  45. data/lib/rbs/version.rb +1 -1
  46. data/lib/rbs/writer.rb +127 -91
  47. data/rbs.gemspec +0 -10
  48. data/schema/decls.json +36 -10
  49. data/schema/members.json +3 -0
  50. data/stdlib/benchmark/benchmark.rbs +151 -151
  51. data/stdlib/builtin/enumerable.rbs +3 -3
  52. data/stdlib/builtin/file.rbs +0 -3
  53. data/stdlib/builtin/io.rbs +4 -4
  54. data/stdlib/builtin/proc.rbs +1 -2
  55. data/stdlib/builtin/thread.rbs +2 -2
  56. data/stdlib/csv/csv.rbs +4 -6
  57. data/stdlib/fiber/fiber.rbs +1 -1
  58. data/stdlib/json/json.rbs +7 -1
  59. data/stdlib/logger/formatter.rbs +23 -0
  60. data/stdlib/logger/log_device.rbs +39 -0
  61. data/stdlib/logger/logger.rbs +507 -0
  62. data/stdlib/logger/period.rbs +7 -0
  63. data/stdlib/logger/severity.rbs +8 -0
  64. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  65. data/stdlib/pathname/pathname.rbs +6 -6
  66. data/stdlib/prime/integer-extension.rbs +1 -1
  67. data/stdlib/prime/prime.rbs +44 -44
  68. data/stdlib/pty/pty.rbs +159 -0
  69. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  70. metadata +19 -130
  71. 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
@@ -77,6 +77,21 @@ module RBS
77
77
  locations.inject {|l1, l2| l1 + l2 }
78
78
  end
79
79
 
80
+ def concat(*others)
81
+ others.each { |other| self << other }
82
+ self
83
+ end
84
+
85
+ def <<(other)
86
+ if other
87
+ raise "Invalid concat: buffer=#{buffer.name}, other.buffer=#{other.buffer.name}" unless other.buffer == buffer
88
+ @end_pos = other.end_pos
89
+ @source = nil
90
+ @end_loc = nil
91
+ end
92
+ self
93
+ end
94
+
80
95
  def pred?(loc)
81
96
  loc.is_a?(Location) &&
82
97
  loc.name == name &&
@@ -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)
@@ -506,7 +562,7 @@ rule
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 | kINTERFACE | kSUPER | kALIAS | kOUT | kIN
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
@@ -1107,20 +1164,19 @@ def leading_comment(location)
1107
1164
  end
1108
1165
 
1109
1166
  def push_comment(string, location)
1110
- new_comment = AST::Comment.new(string: string+"\n", location: location)
1111
-
1112
- if (prev_comment = leading_comment(location)) && prev_comment.location.start_column == location.start_column
1113
- @comments.delete prev_comment.location.end_line
1114
- new_comment = AST::Comment.new(string: prev_comment.string + new_comment.string,
1115
- location: prev_comment.location + new_comment.location)
1167
+ if (comment = leading_comment(location)) && comment.location.start_column == location.start_column
1168
+ comment.concat(string: "#{string}\n", location: location)
1169
+ @comments[comment.location.end_line] = comment
1170
+ else
1171
+ new_comment = AST::Comment.new(string: "#{string}\n", location: location)
1172
+ @comments[new_comment.location.end_line] = new_comment
1116
1173
  end
1117
-
1118
- @comments[new_comment.location.end_line] = new_comment
1119
1174
  end
1120
1175
 
1121
1176
  def new_token(type, value = input.matched)
1122
- start_index = input.charpos - input.matched.size
1123
- end_index = input.charpos
1177
+ charpos = charpos(input)
1178
+ start_index = charpos - input.matched.size
1179
+ end_index = charpos
1124
1180
 
1125
1181
  location = RBS::Location.new(buffer: buffer,
1126
1182
  start_pos: start_index,
@@ -1129,6 +1185,14 @@ def new_token(type, value = input.matched)
1129
1185
  [type, LocatedValue.new(location: location, value: value)]
1130
1186
  end
1131
1187
 
1188
+ def charpos(scanner)
1189
+ if @ascii_only
1190
+ scanner.pos
1191
+ else
1192
+ scanner.charpos
1193
+ end
1194
+ end
1195
+
1132
1196
  def empty_params_result
1133
1197
  [
1134
1198
  [],
@@ -1166,13 +1230,13 @@ KEYWORDS = {
1166
1230
  "attr_reader" => :kATTRREADER,
1167
1231
  "attr_writer" => :kATTRWRITER,
1168
1232
  "attr_accessor" => :kATTRACCESSOR,
1169
- "super" => :kSUPER,
1170
1233
  "public" => :kPUBLIC,
1171
1234
  "private" => :kPRIVATE,
1172
1235
  "alias" => :kALIAS,
1173
1236
  "extension" => :kEXTENSION,
1174
1237
  "incompatible" => :kINCOMPATIBLE,
1175
1238
  "unchecked" => :kUNCHECKED,
1239
+ "overload" => :kOVERLOAD,
1176
1240
  "out" => :kOUT,
1177
1241
  "in" => :kIN,
1178
1242
  }
@@ -1214,6 +1278,7 @@ PUNCTS = {
1214
1278
  "!" => :kEXCLAMATION,
1215
1279
  "**" => :kSTAR2,
1216
1280
  "*" => :kSTAR,
1281
+ "..." => :kDOT3,
1217
1282
  "." => :kDOT,
1218
1283
  "<" => :kLT,
1219
1284
  "-@" => :tOPERATOR,
@@ -1245,8 +1310,9 @@ def next_token
1245
1310
  when input.scan(/\s+/)
1246
1311
  # skip
1247
1312
  when input.scan(/#(( *)|( ?(?<string>.*)))\n/)
1248
- start_index = input.charpos - input.matched.size
1249
- end_index = input.charpos-1
1313
+ charpos = charpos(input)
1314
+ start_index = charpos - input.matched.size
1315
+ end_index = charpos-1
1250
1316
 
1251
1317
  location = RBS::Location.new(buffer: buffer,
1252
1318
  start_pos: start_index,