steep 0.5.1 → 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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -1
  3. data/bin/smoke_runner.rb +1 -1
  4. data/lib/steep.rb +6 -4
  5. data/lib/steep/ast/builtin.rb +96 -0
  6. data/lib/steep/ast/location.rb +9 -5
  7. data/lib/steep/ast/namespace.rb +80 -0
  8. data/lib/steep/ast/signature/env.rb +37 -31
  9. data/lib/steep/ast/types/boolean.rb +2 -2
  10. data/lib/steep/ast/types/hash.rb +50 -0
  11. data/lib/steep/ast/types/literal.rb +12 -10
  12. data/lib/steep/ast/types/name.rb +135 -94
  13. data/lib/steep/ast/types/nil.rb +3 -1
  14. data/lib/steep/ast/types/proc.rb +3 -1
  15. data/lib/steep/drivers/check.rb +4 -4
  16. data/lib/steep/drivers/utils/validator.rb +11 -16
  17. data/lib/steep/interface/builder.rb +201 -146
  18. data/lib/steep/interface/instantiated.rb +8 -0
  19. data/lib/steep/names.rb +86 -0
  20. data/lib/steep/parser.y +1093 -668
  21. data/lib/steep/source.rb +2 -2
  22. data/lib/steep/subtyping/check.rb +199 -63
  23. data/lib/steep/subtyping/constraints.rb +2 -5
  24. data/lib/steep/subtyping/variable_variance.rb +2 -2
  25. data/lib/steep/type_construction.rb +194 -175
  26. data/lib/steep/type_inference/block_params.rb +9 -21
  27. data/lib/steep/type_inference/constant_env.rb +26 -30
  28. data/lib/steep/type_inference/send_args.rb +4 -7
  29. data/lib/steep/type_inference/type_env.rb +3 -3
  30. data/lib/steep/version.rb +1 -1
  31. data/smoke/alias/a.rb +1 -1
  32. data/smoke/alias/b.rb +1 -1
  33. data/smoke/class/i.rbi +1 -1
  34. data/smoke/hash/a.rbi +8 -0
  35. data/smoke/hash/c.rb +18 -0
  36. data/smoke/hash/d.rb +6 -0
  37. data/smoke/hello/hello.rb +2 -2
  38. data/smoke/interface/a.rb +14 -0
  39. data/smoke/interface/a.rbi +12 -0
  40. data/smoke/module/a.rb +1 -1
  41. data/smoke/module/a.rbi +3 -3
  42. data/smoke/module/b.rb +1 -1
  43. data/smoke/stdout/a.rb +2 -2
  44. data/stdlib/builtin.rbi +6 -7
  45. data/steep.gemspec +1 -1
  46. metadata +14 -7
  47. data/lib/steep/module_name.rb +0 -116
  48. data/lib/steep/type_name.rb +0 -93
@@ -19,6 +19,14 @@ module Steep
19
19
  other.is_a?(self.class) && other.type == type && other.params == params && other.methods == methods && other.ivars == ivars
20
20
  end
21
21
 
22
+ def subst(s)
23
+ self.class.new(
24
+ type: type,
25
+ methods: methods.transform_values {|type| type.subst(s) },
26
+ ivar_chains: ivar_chains.transform_values {|chain| chain.subst(s) }
27
+ )
28
+ end
29
+
22
30
  class InvalidMethodOverrideError < StandardError
23
31
  attr_reader :type
24
32
  attr_reader :current_method
@@ -0,0 +1,86 @@
1
+ module Steep
2
+ module Names
3
+ class Base
4
+ attr_reader :namespace
5
+ attr_reader :name
6
+ attr_reader :location
7
+
8
+ def initialize(namespace:, name:, location: nil)
9
+ @namespace = namespace
10
+ @name = name
11
+ @location = location
12
+ end
13
+
14
+ def absolute?
15
+ namespace.absolute?
16
+ end
17
+
18
+ def relative?
19
+ !absolute?
20
+ end
21
+
22
+ def ==(other)
23
+ other.is_a?(self.class) && other.name == name && other.namespace == namespace
24
+ end
25
+
26
+ def hash
27
+ self.class.hash ^ name.hash ^ @absolute.hash
28
+ end
29
+
30
+ alias eql? ==
31
+
32
+ def self.parse(string)
33
+ namespace = AST::Namespace.parse(string.to_s)
34
+ *_, name = namespace.path
35
+ new(namespace: namespace.parent, name: name)
36
+ end
37
+
38
+ def absolute!
39
+ self.class.new(namespace: namespace.absolute!,
40
+ name: name)
41
+ end
42
+
43
+ def in_namespace(namespace)
44
+ if absolute?
45
+ self
46
+ else
47
+ self.class.new(namespace: namespace + self.namespace, name: name)
48
+ end
49
+ end
50
+
51
+ def to_s
52
+ "#{namespace}#{name}"
53
+ end
54
+ end
55
+
56
+ class Module < Base
57
+ def self.from_node(node)
58
+ case node.type
59
+ when :const, :casgn
60
+ namespace = namespace_from_node(node.children[0]) or return
61
+ name = node.children[1]
62
+ new(namespace: namespace, name: name)
63
+ end
64
+ end
65
+
66
+ def self.namespace_from_node(node)
67
+ case node&.type
68
+ when nil
69
+ AST::Namespace.empty
70
+ when :cbase
71
+ AST::Namespace.root
72
+ when :const
73
+ namespace_from_node(node.children[0])&.yield_self do |parent|
74
+ parent.append(node.children[1])
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ class Interface < Base
81
+ end
82
+
83
+ class Alias < Base
84
+ end
85
+ end
86
+ end
data/lib/steep/parser.y CHANGED
@@ -1,602 +1,1013 @@
1
1
  class Steep::Parser
2
2
 
3
+ token kCLASS kMODULE kINTERFACE kDEF kEND kNIL kBOOL kANY kVOID kTYPE
4
+ kINCOMPATIBLE kAT_TYPE kAT_IMPLEMENTS kAT_DYNAMIC kCONST kVAR kRETURN
5
+ kBLOCK kBREAK kMETHOD kSELF kSELFQ kATTR_READER kATTR_ACCESSOR kINSTANCE
6
+ kINCLUDE kEXTEND kINSTANCE kIVAR kCONSTRUCTOR kNOCONSTRUCTOR kEXTENSION
7
+ tARROW tBANG tBAR tCOLON tCOMMA tDOT tEQ tGT tGVAR tHAT tINT
8
+ tINTERFACE_NAME tIVAR_NAME tLBRACE tLBRACKET tIDENT tLPAREN tLT tROCKET
9
+ tMINUS tOPERATOR tPERCENT tPLUS tQUESTION tRBRACE tRBRACKET
10
+ tRPAREN tSTAR tSTAR2 tSTRING tSYMBOL tUIDENT tUMINUS tVAR
11
+ type_METHOD type_SIGNATURE type_ANNOTATION type_TYPE
12
+ tQUALIFIED_MODULE_NAME tQUALIFIED_INTERFACE_NAME tQUALIFIED_ALIAS_NAME
13
+
3
14
  expect 1
4
15
 
5
16
  rule
6
17
 
7
- target: type_METHOD method_type { result = val[1] }
8
- | type_SIGNATURE signatures { result = val[1] }
9
- | type_ANNOTATION annotation { result = val[1] }
10
- | type_TYPE type { result = val[1] }
11
-
12
- method_type:
13
- type_params params block_opt ARROW return_type {
14
- result = AST::MethodType.new(location: AST::Location.concat(*val.compact.map(&:location)),
15
- type_params: val[0],
16
- params: val[1]&.value,
17
- block: val[2],
18
- return_type: val[4])
19
- }
20
-
21
- return_type: paren_type
22
-
23
- params: { result = nil }
24
- | LPAREN params0 RPAREN { result = LocatedValue.new(location: val[0].location + val[2].location,
25
- value: val[1]) }
26
- | simple_type { result = LocatedValue.new(location: val[0].location,
27
- value: AST::MethodType::Params::Required.new(location: val[0].location, type: val[0])) }
28
-
29
- params0: required_param { result = AST::MethodType::Params::Required.new(location: val[0].location, type: val[0]) }
30
- | required_param COMMA params0 {
31
- location = val[0].location
32
- result = AST::MethodType::Params::Required.new(location: location,
33
- type: val[0],
34
- next_params: val[2])
35
- }
36
- | params1 { result = val[0] }
37
-
38
- params1: optional_param { result = AST::MethodType::Params::Optional.new(location: val[0].first, type: val[0].last) }
39
- | optional_param COMMA params1 {
40
- location = val[0].first
41
- result = AST::MethodType::Params::Optional.new(type: val[0].last, location: location, next_params: val[2])
42
- }
43
- | params2 { result = val[0] }
44
-
45
- params2: rest_param { result = AST::MethodType::Params::Rest.new(location: val[0].first, type: val[0].last) }
46
- | rest_param COMMA params3 {
47
- loc = val[0].first
48
- result = AST::MethodType::Params::Rest.new(location: loc, type: val[0].last, next_params: val[2])
49
- }
50
- | params3 { result = val[0] }
51
-
52
- params3: required_keyword {
53
- location, name, type = val[0]
54
- result = AST::MethodType::Params::RequiredKeyword.new(location: location, name: name, type: type)
55
- }
56
- | optional_keyword {
57
- location, name, type = val[0]
58
- result = AST::MethodType::Params::OptionalKeyword.new(location: location, name: name, type: type)
59
- }
60
- | required_keyword COMMA params3 {
61
- location, name, type = val[0]
62
- result = AST::MethodType::Params::RequiredKeyword.new(location: location,
63
- name: name,
64
- type: type,
65
- next_params: val[2])
66
- }
67
- | optional_keyword COMMA params3 {
68
- location, name, type = val[0]
69
- result = AST::MethodType::Params::OptionalKeyword.new(location: location,
70
- name: name,
71
- type: type,
72
- next_params: val[2])
73
- }
74
- | params4 { result = val[0] }
75
-
76
- params4: { result = nil }
77
- | STAR2 type {
78
- result = AST::MethodType::Params::RestKeyword.new(location: val[0].location + val[1].location,
79
- type: val[1])
80
- }
81
-
82
- required_param: type { result = val[0] }
83
- optional_param: QUESTION type { result = [val[0].location + val[1].location,
84
- val[1]] }
85
- rest_param: STAR type { result = [val[0].location + val[1].location,
86
- val[1]] }
87
- required_keyword: keyword COLON type { result = [val[0].location + val[2].location,
88
- val[0].value,
89
- val[2]] }
90
- optional_keyword: QUESTION keyword COLON type { result = [val[0].location + val[3].location,
91
- val[1].value,
92
- val[3]] }
93
-
94
- block_opt: { result = nil }
95
- | block_optional LBRACE RBRACE {
96
- result = AST::MethodType::Block.new(params: nil,
97
- return_type: nil,
98
- location: (val[0] || val[1]).location + val[2].location,
99
- optional: val[0]&.value || false)
100
- }
101
- | block_optional LBRACE block_params ARROW type RBRACE {
102
- result = AST::MethodType::Block.new(params: val[2],
103
- return_type: val[4],
104
- location: (val[0] || val[1]).location + val[5].location,
105
- optional: val[0]&.value || false)
106
- }
107
-
108
- block_optional: { result = nil }
109
- | QUESTION { result = LocatedValue.new(location: val[0].location, value: true) }
110
-
111
- block_params: { result = nil }
112
- | LPAREN block_params0 RPAREN {
113
- result = val[1]
114
- }
115
-
116
- block_params0: required_param {
117
- result = AST::MethodType::Params::Required.new(location: val[0].location,
118
- type: val[0])
119
- }
120
- | required_param COMMA block_params0 {
121
- result = AST::MethodType::Params::Required.new(location: val[0].location,
122
- type: val[0],
123
- next_params: val[2])
124
- }
125
- | block_params1 { result = val[0] }
126
-
127
- block_params1: optional_param {
128
- result = AST::MethodType::Params::Optional.new(location: val[0].first,
129
- type: val[0].last)
130
- }
131
- | optional_param COMMA block_params1 {
132
- loc = val.first[0] + (val[2] || val[1]).location
133
- type = val.first[1]
134
- next_params = val[2]
135
- result = AST::MethodType::Params::Optional.new(location: loc, type: type, next_params: next_params)
136
- }
137
- | block_params2 { result = val[0] }
138
-
139
- block_params2: { result = nil }
140
- | rest_param {
141
- result = AST::MethodType::Params::Rest.new(location: val[0].first, type: val[0].last)
142
- }
143
-
144
- simple_type: type_name {
145
- result = AST::Types::Name.new(name: val[0].value, location: val[0].location, args: [])
146
- }
147
- | application_type_name LT type_seq GT {
148
- loc = val[0].location + val[3].location
149
- name = val[0].value
150
- args = val[2]
151
- result = AST::Types::Name.new(location: loc, name: name, args: args)
152
- }
153
- | ANY { result = AST::Types::Any.new(location: val[0].location) }
154
- | TVAR { result = AST::Types::Var.new(location: val[0].location, name: val[0].value) }
155
- | CLASS { result = AST::Types::Class.new(location: val[0].location) }
156
- | MODULE { result = AST::Types::Class.new(location: val[0].location) }
157
- | INSTANCE { result = AST::Types::Instance.new(location: val[0].location) }
158
- | SELF { result = AST::Types::Self.new(location: val[0].location) }
159
- | VOID { result = AST::Types::Void.new(location: val[0].location) }
160
- | NIL { result = AST::Types::Nil.new(location: val[0].location) }
161
- | BOOL { result = AST::Types::Boolean.new(location: val[0].location) }
162
- | simple_type QUESTION {
163
- type = val[0]
164
- nil_type = AST::Types::Nil.new(location: val[1].location)
165
- result = AST::Types::Union.build(types: [type, nil_type], location: val[0].location + val[1].location)
166
- }
167
- | SELFQ {
168
- type = AST::Types::Self.new(location: val[0].location)
169
- nil_type = AST::Types::Nil.new(location: val[0].location)
170
- result = AST::Types::Union.build(types: [type, nil_type], location: val[0].location)
171
- }
172
- | INT { result = AST::Types::Literal.new(value: val[0].value, location: val[0].location) }
173
- | STRING { result = AST::Types::Literal.new(value: val[0].value, location: val[0].location) }
174
- | SYMBOL { result = AST::Types::Literal.new(value: val[0].value, location: val[0].location) }
175
- | LBRACKET type_seq RBRACKET {
176
- loc = val[0].location + val[2].location
177
- result = AST::Types::Tuple.new(types: val[1], location: loc)
178
- }
179
-
180
- paren_type: LPAREN type RPAREN { result = val[1].with_location(val[0].location + val[2].location) }
181
- | simple_type
182
-
183
- application_type_name: module_name {
184
- result = LocatedValue.new(value: TypeName::Instance.new(name: val[0].value),
185
- location: val[0].location)
186
- }
187
- | INTERFACE_NAME {
188
- result = LocatedValue.new(value: TypeName::Interface.new(name: val[0].value),
189
- location: val[0].location)
190
- }
191
- | LIDENT {
192
- result = LocatedValue.new(value: TypeName::Alias.new(name: val[0].value),
193
- location: val[0].location)
194
- }
195
-
196
- type_name: application_type_name
197
- | module_name DOT CLASS constructor {
198
- loc = val[0].location + (val[3] || val[2]).location
199
- result = LocatedValue.new(value: TypeName::Class.new(name: val[0].value, constructor: val[3]&.value),
200
- location: loc)
201
- }
202
- | module_name DOT MODULE {
203
- loc = val[0].location + val.last.location
204
- result = LocatedValue.new(value: TypeName::Module.new(name: val[0].value),
205
- location: loc)
206
- }
207
-
208
- constructor: { result = nil }
209
- | CONSTRUCTOR { result = LocatedValue.new(location: val[0].location, value: true) }
210
- | NOCONSTRUCTOR { result = LocatedValue.new(location: val[0].location, value: false) }
211
-
212
- type: paren_type
213
- | union_seq {
214
- loc = val[0].first.location + val[0].last.location
215
- result = AST::Types::Union.build(types: val[0], location: loc)
216
- }
217
- | HAT LPAREN lambda_params RPAREN ARROW paren_type {
218
- loc = val[0].location + val[5].location
219
- result = AST::Types::Proc.new(params: val[2], return_type: val[5], location: loc)
220
- }
221
-
222
- lambda_params: lambda_params1
223
- | paren_type { result = Interface::Params.empty.update(required: [val[0]]) }
224
- | paren_type COMMA lambda_params {
225
- result = val[2].update(required: [val[0]] + val[2].required)
226
- }
227
-
228
- lambda_params1: { result = Interface::Params.empty }
229
- | STAR paren_type { result = Interface::Params.empty.update(rest: val[1]) }
230
- | QUESTION paren_type { result = Interface::Params.empty.update(optional: [val[1]]) }
231
- | QUESTION paren_type COMMA lambda_params1 { result = val[3].update(optional: [val[1]] + val[3].optional) }
232
-
233
-
234
- type_seq: type { result = [val[0]] }
235
- | type COMMA type_seq { result = [val[0]] + val[2] }
236
-
237
- union_seq: simple_type BAR simple_type { result = [val[0], val[2]] }
238
- | simple_type BAR union_seq { result = [val[0]] + val[2] }
239
-
240
- keyword: LIDENT
241
- | MODULE_NAME
242
- | INTERFACE_NAME
243
- | ANY
244
- | CLASS
245
- | MODULE
246
- | INSTANCE
247
- | BLOCK
248
- | INCLUDE
249
- | IVAR
250
- | SELF
251
- | TYPE
252
-
253
- signatures: { result = [] }
254
- | interface signatures { result = [val[0]] + val[1] }
255
- | class_decl signatures { result = [val[0]] + val[1] }
256
- | module_decl signatures { result = [val[0]] + val[1] }
257
- | extension_decl signatures { result = [val[0]] + val[1] }
258
- | const_decl signatures { result = [val[0]] + val[1] }
259
- | gvar_decl signatures { result = [val[0]] + val[1] }
260
- | alias_decl signatures { result = [val[0]] + val[1] }
261
-
262
- gvar_decl: GVAR COLON type {
263
- loc = val.first.location + val.last.location
264
- result = AST::Signature::Gvar.new(
265
- location: loc,
266
- name: val[0].value,
267
- type: val[2]
268
- )
269
- }
270
-
271
- const_decl: module_name COLON type {
272
- loc = val.first.location + val.last.location
273
- result = AST::Signature::Const.new(
274
- location: loc,
275
- name: val[0].value,
276
- type: val[2]
277
- )
278
- }
279
-
280
- interface: INTERFACE interface_name type_params interface_members END {
281
- loc = val.first.location + val.last.location
282
- result = AST::Signature::Interface.new(
283
- location: loc,
284
- name: val[1].value,
285
- params: val[2],
286
- methods: val[3]
287
- )
288
- }
289
-
290
- class_decl: CLASS module_name type_params super_opt class_members END {
291
- loc = val.first.location + val.last.location
292
- result = AST::Signature::Class.new(name: val[1].value.absolute!,
293
- params: val[2],
294
- super_class: val[3],
295
- members: val[4],
296
- location: loc)
297
- }
298
- module_decl: MODULE module_name type_params self_type_opt class_members END {
299
- loc = val.first.location + val.last.location
300
- result = AST::Signature::Module.new(name: val[1].value.absolute!,
301
- location: loc,
302
- params: val[2],
303
- self_type: val[3],
304
- members: val[4])
305
- }
306
- extension_decl: EXTENSION module_name type_params LPAREN UIDENT RPAREN class_members END {
307
- loc = val.first.location + val.last.location
308
- result = AST::Signature::Extension.new(module_name: val[1].value.absolute!,
309
- name: val[4].value,
310
- location: loc,
311
- params: val[2],
312
- members: val[6])
313
- }
314
-
315
- alias_decl: TYPE LIDENT type_params EQ type {
316
- loc = val[0].location + val[4].location
317
- result = AST::Signature::Alias.new(location: loc,
318
- name: val[1].value,
319
- params: val[2],
320
- type: val[4])
321
- }
322
-
323
- self_type_opt: { result = nil }
324
- | COLON type { result = val[1] }
325
-
326
- interface_name: INTERFACE_NAME
327
-
328
- module_name: module_name0
329
- | COLON2 module_name0 {
330
- loc = val.first.location + val.last.location
331
- result = LocatedValue.new(location: loc, value: val[1].value.absolute!)
332
- }
333
-
334
- module_name0: UIDENT {
335
- result = LocatedValue.new(location: val[0].location, value: ModuleName.parse(val[0].value))
336
- }
337
- | UIDENT COLON2 module_name0 {
338
- location = val[0].location + val.last.location
339
- name = ModuleName.parse(val[0].value) + val.last.value
340
- result = LocatedValue.new(location: location, value: name)
341
- }
342
-
343
- class_members: { result = [] }
344
- | class_member class_members { result = [val[0]] + val[1] }
345
-
346
- class_member: instance_method_member
347
- | module_method_member
348
- | module_instance_method_member
349
- | include_member
350
- | extend_member
351
- | ivar_member
352
- | attr_reader_member
353
- | attr_accessor_member
354
-
355
- ivar_member: IVAR_NAME COLON type {
356
- loc = val.first.location + val.last.location
357
- result = AST::Signature::Members::Ivar.new(
358
- location: loc,
359
- name: val[0].value,
360
- type: val[2]
361
- )
362
- }
363
-
364
- instance_method_member: DEF method_annotations method_name COLON method_type_union {
365
- loc = val.first.location + val.last.last.location
366
- result = AST::Signature::Members::Method.new(
367
- name: val[2].value,
368
- types: val[4],
369
- kind: :instance,
370
- location: loc,
371
- attributes: val[1] || []
372
- )
373
- }
374
- module_method_member: DEF method_annotations SELF DOT method_name COLON method_type_union {
375
- loc = val.first.location + val.last.last.location
376
- result = AST::Signature::Members::Method.new(
377
- name: val[4].value,
378
- types: val[6],
379
- kind: :module,
380
- location: loc,
381
- attributes: val[1] || []
382
- )
383
- }
384
- module_instance_method_member: DEF method_annotations SELFQ DOT method_name COLON method_type_union {
385
- loc = val.first.location + val.last.last.location
386
- result = AST::Signature::Members::Method.new(
387
- name: val[4].value,
388
- types: val[6],
389
- kind: :module_instance,
390
- location: loc,
391
- attributes: val[1] || []
392
- )
393
- }
394
- include_member: INCLUDE module_name {
395
- loc = val.first.location + val.last.location
396
- name = val[1].value
397
- result = AST::Signature::Members::Include.new(name: name, location: loc, args: [])
398
- }
399
- | INCLUDE module_name LT type_seq GT {
400
- loc = val.first.location + val.last.location
401
- name = val[1].value
402
- result = AST::Signature::Members::Include.new(name: name, location: loc, args: val[3])
403
- }
404
- extend_member: EXTEND module_name {
405
- loc = val.first.location + val.last.location
406
- name = val[1].value
407
- result = AST::Signature::Members::Extend.new(name: name, location: loc, args: [])
408
- }
409
- | EXTEND module_name LT type_seq GT {
410
- loc = val.first.location + val.last.location
411
- name = val[1].value
412
- result = AST::Signature::Members::Extend.new(name: name, location: loc, args: val[3])
413
- }
414
- attr_reader_member: ATTR_READER method_name attr_ivar_opt COLON type {
415
- loc = val.first.location + val.last.location
416
- result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :reader, ivar: val[2], type: val[4])
417
- }
418
- attr_accessor_member: ATTR_ACCESSOR method_name attr_ivar_opt COLON type {
419
- loc = val.first.location + val.last.location
420
- result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :accessor, ivar: val[2], type: val[4])
421
- }
422
-
423
- attr_ivar_opt: { result = nil }
424
- | LPAREN RPAREN { result = false }
425
- | LPAREN IVAR_NAME RPAREN { result = val[1].value }
426
-
427
- method_annotations: { result = nil }
428
- | LPAREN method_annotation_seq RPAREN { result = val[1] }
429
-
430
- method_annotation_seq: method_annotation_keyword { result = [val[0]] }
431
- | method_annotation_keyword COMMA method_annotation_seq { result = [val[0]] + val[2] }
432
-
433
- method_annotation_keyword: CONSTRUCTOR { result = val[0].value }
434
- | INCOMPATIBLE { result = val[0].value }
435
-
436
- super_opt: { result = nil }
437
- | LTCOLON super_class { result = val[1] }
438
-
439
- super_class: module_name {
440
- result = AST::Signature::SuperClass.new(location: val[0].location, name: val[0].value, args: [])
441
- }
442
- | module_name LT type_seq GT {
443
- loc = val[0].location + val[3].location
444
- name = val[0].value
445
- result = AST::Signature::SuperClass.new(location: loc, name: name, args: val[2])
446
- }
447
-
448
- type_params: { result = nil }
449
- | LT type_param_seq GT {
450
- location = val[0].location + val[2].location
451
- result = AST::TypeParams.new(location: location, variables: val[1])
452
- }
453
-
454
- type_param_seq: TVAR { result = [val[0].value] }
455
- | TVAR COMMA type_param_seq { result = [val[0].value] + val[2] }
456
-
457
- interface_members: { result = [] }
458
- | interface_method interface_members { result = val[1].unshift(val[0]) }
459
-
460
- interface_method: DEF method_name COLON method_type_union {
461
- loc = val[0].location + val[3].last.location
462
- result = AST::Signature::Interface::Method.new(location: loc, name: val[1].value, types: val[3])
463
- }
464
-
465
- method_type_union: method_type { result = [val[0]] }
466
- | method_type BAR method_type_union { result = [val[0]] + val[2] }
467
-
468
- method_name: method_name0
469
- | STAR | STAR2
470
- | PERCENT | MINUS
471
- | LT | GT
472
- | UMINUS
473
- | BAR { result = LocatedValue.new(location: val[0].location, value: :|) }
474
- | method_name0 EQ {
475
- raise ParseError, "\nunexpected method name #{val[0].to_s} =" unless val[0].location.pred?(val[1].location)
476
- result = LocatedValue.new(location: val[0].location + val[1].location,
477
- value: :"#{val[0].value}=")
478
- }
479
- | method_name0 QUESTION {
480
- raise ParseError, "\nunexpected method name #{val[0].to_s} ?" unless val[0].location.pred?(val[1].location)
481
- result = LocatedValue.new(location: val[0].location + val[1].location,
482
- value: :"#{val[0].value}?")
483
- }
484
- | method_name0 BANG {
485
- raise ParseError, "\nunexpected method name #{val[0].to_s} !" unless val[0].location.pred?(val[1].location)
486
- result = LocatedValue.new(location: val[0].location + val[1].location,
487
- value: :"#{val[0].value}!")
488
- }
489
- | GT GT {
490
- raise ParseError, "\nunexpected method name > >" unless val[0].location.pred?(val[1].location)
491
- result = LocatedValue.new(location: val[0].location + val[1].location, value: :>>)
492
- }
493
- | NIL QUESTION {
494
- raise ParseError, "\nunexpected method name #{val[0].to_s} ?" unless val[0].location.pred?(val[1].location)
495
- result = LocatedValue.new(location: val[0].location + val[1].location,
496
- value: :"nil?")
497
- }
498
-
499
- method_name0: LIDENT
500
- | UIDENT
501
- | MODULE_NAME
502
- | INTERFACE_NAME
503
- | ANY | VOID
504
- | INTERFACE
505
- | END
506
- | PLUS
507
- | CLASS
508
- | MODULE
509
- | INSTANCE
510
- | EXTEND
511
- | INCLUDE
512
- | OPERATOR
513
- | HAT
514
- | BANG
515
- | BLOCK
516
- | BREAK
517
- | METHOD
518
- | BOOL
519
- | TYPE
520
- | CONSTRUCTOR { result = LocatedValue.new(location: val[0].location, value: :constructor) }
521
- | NOCONSTRUCTOR { result = LocatedValue.new(location: val[0].location, value: :noconstructor) }
522
- | ATTR_READER
523
- | ATTR_ACCESSOR
524
- | INCOMPATIBLE
525
-
526
- annotation: AT_TYPE VAR subject COLON type {
527
- loc = val.first.location + val.last.location
528
- result = AST::Annotation::VarType.new(location: loc,
529
- name: val[2].value,
530
- type: val[4])
531
- }
532
- | AT_TYPE METHOD subject COLON method_type {
533
- loc = val.first.location + val.last.location
534
- result = AST::Annotation::MethodType.new(location: loc,
535
- name: val[2].value,
536
- type: val[4])
537
- }
538
- | AT_TYPE RETURN COLON type {
539
- loc = val.first.location + val.last.location
540
- result = AST::Annotation::ReturnType.new(type: val[3], location: loc)
541
- }
542
- | AT_TYPE BLOCK COLON type {
543
- loc = val.first.location + val.last.location
544
- result = AST::Annotation::BlockType.new(type: val[3], location: loc)
545
- }
546
- | AT_TYPE SELF COLON type {
547
- loc = val.first.location + val.last.location
548
- result = AST::Annotation::SelfType.new(type: val[3], location: loc)
549
- }
550
- | AT_TYPE CONST module_name COLON type {
551
- loc = val.first.location + val.last.location
552
- result = AST::Annotation::ConstType.new(name: val[2].value,
553
- type: val[4],
554
- location: loc)
555
- }
556
- | AT_TYPE INSTANCE COLON type {
557
- loc = val.first.location + val.last.location
558
- result = AST::Annotation::InstanceType.new(type: val[3], location: loc)
559
- }
560
- | AT_TYPE MODULE COLON type {
561
- loc = val.first.location + val.last.location
562
- result = AST::Annotation::ModuleType.new(type: val[3], location: loc)
563
- }
564
- | AT_TYPE IVAR IVAR_NAME COLON type {
565
- loc = val.first.location + val.last.location
566
- result = AST::Annotation::IvarType.new(name: val[2].value, type: val[4], location: loc)
567
- }
568
- | AT_IMPLEMENTS module_name type_params {
569
- loc = val[0].location + (val[2]&.location || val[1].location)
570
- args = val[2]&.variables || []
571
- name = AST::Annotation::Implements::Module.new(name: val[1].value, args: args)
572
- result = AST::Annotation::Implements.new(name: name, location: loc)
573
- }
574
- | AT_DYNAMIC dynamic_names {
575
- loc = val[0].location + val[1].last.location
576
- result = AST::Annotation::Dynamic.new(names: val[1], location: loc)
577
- }
578
- | AT_TYPE BREAK COLON type {
579
- loc = val.first.location + val.last.location
580
- result = AST::Annotation::BreakType.new(type: val[3], location: loc)
581
- }
582
-
583
- dynamic_names: dynamic_name COMMA dynamic_names { result = [val[0]] + val[2] }
584
- | dynamic_name { result = val }
585
-
586
- dynamic_name: method_name {
587
- result = AST::Annotation::Dynamic::Name.new(name: val[0].value, location: val[0].location, kind: :instance)
588
- }
589
- | SELF DOT method_name {
590
- loc = val.first.location + val.last.location
591
- result = AST::Annotation::Dynamic::Name.new(name: val[2].value, location: loc, kind: :module)
592
- }
593
- | SELFQ DOT method_name {
594
- loc = val.first.location + val.last.location
595
- result = AST::Annotation::Dynamic::Name.new(name: val[2].value, location: loc, kind: :module_instance)
596
- }
597
-
598
- subject: LIDENT { result = val[0] }
599
-
18
+ target: type_METHOD method_type
19
+ {
20
+ result = val[1]
21
+ }
22
+ | type_SIGNATURE signatures
23
+ {
24
+ result = val[1]
25
+ }
26
+ | type_ANNOTATION annotation
27
+ {
28
+ result = val[1]
29
+ }
30
+ | type_TYPE type
31
+ {
32
+ result = val[1]
33
+ }
34
+
35
+ method_type: type_params params block_opt tARROW return_type
36
+ {
37
+ result = AST::MethodType.new(location: AST::Location.concat(*val.compact.map(&:location)),
38
+ type_params: val[0],
39
+ params: val[1]&.value,
40
+ block: val[2],
41
+ return_type: val[4])
42
+ }
43
+
44
+ return_type: paren_type
45
+
46
+ params: # nothing
47
+ {
48
+ result = nil
49
+ }
50
+ | tLPAREN params0 tRPAREN
51
+ {
52
+ result = LocatedValue.new(location: val[0].location + val[2].location,
53
+ value: val[1])
54
+ }
55
+ | simple_type
56
+ {
57
+ result = LocatedValue.new(location: val[0].location,
58
+ value: AST::MethodType::Params::Required.new(location: val[0].location, type: val[0]))
59
+ }
60
+
61
+ params0: required_param
62
+ {
63
+ result = AST::MethodType::Params::Required.new(location: val[0].location, type: val[0])
64
+ }
65
+ | required_param tCOMMA params0
66
+ {
67
+ location = val[0].location
68
+ result = AST::MethodType::Params::Required.new(location: location,
69
+ type: val[0],
70
+ next_params: val[2])
71
+ }
72
+ | params1
73
+ {
74
+ result = val[0]
75
+ }
76
+
77
+ params1: optional_param
78
+ {
79
+ result = AST::MethodType::Params::Optional.new(location: val[0].first, type: val[0].last)
80
+ }
81
+ | optional_param tCOMMA params1
82
+ {
83
+ location = val[0].first
84
+ result = AST::MethodType::Params::Optional.new(type: val[0].last, location: location, next_params: val[2])
85
+ }
86
+ | params2
87
+ {
88
+ result = val[0]
89
+ }
90
+
91
+ params2: rest_param
92
+ {
93
+ result = AST::MethodType::Params::Rest.new(location: val[0].first, type: val[0].last)
94
+ }
95
+ | rest_param tCOMMA params3
96
+ {
97
+ loc = val[0].first
98
+ result = AST::MethodType::Params::Rest.new(location: loc, type: val[0].last, next_params: val[2])
99
+ }
100
+ | params3
101
+ {
102
+ result = val[0]
103
+ }
104
+
105
+ params3: required_keyword
106
+ {
107
+ location, name, type = val[0]
108
+ result = AST::MethodType::Params::RequiredKeyword.new(location: location, name: name, type: type)
109
+ }
110
+ | optional_keyword
111
+ {
112
+ location, name, type = val[0]
113
+ result = AST::MethodType::Params::OptionalKeyword.new(location: location, name: name, type: type)
114
+ }
115
+ | required_keyword tCOMMA params3
116
+ {
117
+ location, name, type = val[0]
118
+ result = AST::MethodType::Params::RequiredKeyword.new(location: location,
119
+ name: name,
120
+ type: type,
121
+ next_params: val[2])
122
+ }
123
+ | optional_keyword tCOMMA params3
124
+ {
125
+ location, name, type = val[0]
126
+ result = AST::MethodType::Params::OptionalKeyword.new(location: location,
127
+ name: name,
128
+ type: type,
129
+ next_params: val[2])
130
+ }
131
+ | params4
132
+ {
133
+ result = val[0]
134
+ }
135
+
136
+ params4: # nothing
137
+ {
138
+ result = nil
139
+ }
140
+ | tSTAR2 type
141
+ {
142
+ result = AST::MethodType::Params::RestKeyword.new(location: val[0].location + val[1].location,
143
+ type: val[1])
144
+ }
145
+
146
+ required_param: type
147
+ {
148
+ result = val[0]
149
+ }
150
+
151
+ optional_param: tQUESTION type
152
+ {
153
+ result = [
154
+ val[0].location + val[1].location,
155
+ val[1]
156
+ ]
157
+ }
158
+
159
+ rest_param: tSTAR type
160
+ {
161
+ result = [
162
+ val[0].location + val[1].location,
163
+ val[1]
164
+ ]
165
+ }
166
+
167
+ required_keyword: keyword tCOLON type
168
+ {
169
+ result = [
170
+ val[0].location + val[2].location,
171
+ val[0].value,
172
+ val[2]
173
+ ]
174
+ }
175
+
176
+ optional_keyword: tQUESTION keyword tCOLON type
177
+ {
178
+ result = [
179
+ val[0].location + val[3].location,
180
+ val[1].value,
181
+ val[3]
182
+ ]
183
+ }
184
+
185
+ block_opt: # nothing
186
+ {
187
+ result = nil
188
+ }
189
+ | block_optional tLBRACE tRBRACE
190
+ {
191
+ result = AST::MethodType::Block.new(params: nil,
192
+ return_type: nil,
193
+ location: (val[0] || val[1]).location + val[2].location,
194
+ optional: val[0]&.value || false)
195
+ }
196
+ | block_optional tLBRACE block_params tARROW type tRBRACE
197
+ {
198
+ result = AST::MethodType::Block.new(params: val[2],
199
+ return_type: val[4],
200
+ location: (val[0] || val[1]).location + val[5].location,
201
+ optional: val[0]&.value || false)
202
+ }
203
+
204
+ block_optional: # nothing
205
+ {
206
+ result = nil
207
+ }
208
+ | tQUESTION
209
+ {
210
+ result = LocatedValue.new(location: val[0].location, value: true)
211
+ }
212
+
213
+ block_params: # nothing
214
+ {
215
+ result = nil
216
+ }
217
+ | tLPAREN block_params0 tRPAREN
218
+ {
219
+ result = val[1]
220
+ }
221
+
222
+ block_params0: required_param
223
+ {
224
+ result = AST::MethodType::Params::Required.new(location: val[0].location,
225
+ type: val[0])
226
+ }
227
+ | required_param tCOMMA block_params0 {
228
+ result = AST::MethodType::Params::Required.new(location: val[0].location,
229
+ type: val[0],
230
+ next_params: val[2])
231
+ }
232
+ | block_params1
233
+ {
234
+ result = val[0]
235
+ }
236
+
237
+ block_params1: optional_param
238
+ {
239
+ result = AST::MethodType::Params::Optional.new(location: val[0].first,
240
+ type: val[0].last)
241
+ }
242
+ | optional_param tCOMMA block_params1
243
+ {
244
+ loc = val.first[0] + (val[2] || val[1]).location
245
+ type = val.first[1]
246
+ next_params = val[2]
247
+ result = AST::MethodType::Params::Optional.new(location: loc, type: type, next_params: next_params)
248
+ }
249
+ | block_params2
250
+ {
251
+ result = val[0]
252
+ }
253
+
254
+ block_params2: # nothing
255
+ {
256
+ result = nil
257
+ }
258
+ | rest_param
259
+ {
260
+ result = AST::MethodType::Params::Rest.new(location: val[0].first, type: val[0].last)
261
+ }
262
+
263
+ application_args: # nothing
264
+ {
265
+ result = nil
266
+ }
267
+ | tLT type_seq tGT
268
+ {
269
+ result = LocatedValue.new(location: val[0].location + val[2].location,
270
+ value: val[1])
271
+ }
272
+
273
+ simple_type: module_name tDOT kCLASS constructor
274
+ {
275
+ loc = val[0].location + (val[3] || val[2]).location
276
+ result = AST::Types::Name::Class.new(name: val[0].value,
277
+ constructor: val[3]&.value,
278
+ location: loc)
279
+ }
280
+ | module_name tDOT kMODULE
281
+ {
282
+ loc = val[0].location + val[2].location
283
+ result = AST::Types::Name::Module.new(name: val[0].value, location: loc)
284
+ }
285
+ | module_name application_args
286
+ {
287
+ loc = val[0].location + val[1]&.location
288
+ result = AST::Types::Name::Instance.new(name: val[0].value,
289
+ location: loc,
290
+ args: val[1]&.value || [])
291
+ }
292
+ | interface_name application_args
293
+ {
294
+ loc = val[0].location + val[1]&.location
295
+ result = AST::Types::Name::Interface.new(name: val[0].value,
296
+ location: loc,
297
+ args: val[1]&.value || [])
298
+ }
299
+ | alias_name application_args
300
+ {
301
+ loc = val[0].location + val[1]&.location
302
+ result = AST::Types::Name::Alias.new(name: val[0].value,
303
+ location: loc,
304
+ args: val[1]&.value || [])
305
+ }
306
+ | kANY
307
+ {
308
+ result = AST::Types::Any.new(location: val[0].location)
309
+ }
310
+ | tVAR
311
+ {
312
+ result = AST::Types::Var.new(location: val[0].location, name: val[0].value)
313
+ }
314
+ | kCLASS
315
+ {
316
+ result = AST::Types::Class.new(location: val[0].location)
317
+ }
318
+ | kMODULE
319
+ {
320
+ result = AST::Types::Class.new(location: val[0].location)
321
+ }
322
+ | kINSTANCE
323
+ {
324
+ result = AST::Types::Instance.new(location: val[0].location)
325
+ }
326
+ | kSELF
327
+ {
328
+ result = AST::Types::Self.new(location: val[0].location)
329
+ }
330
+ | kVOID
331
+ {
332
+ result = AST::Types::Void.new(location: val[0].location)
333
+ }
334
+ | kNIL
335
+ {
336
+ result = AST::Types::Nil.new(location: val[0].location)
337
+ }
338
+ | kBOOL
339
+ {
340
+ result = AST::Types::Boolean.new(location: val[0].location)
341
+ }
342
+ | simple_type tQUESTION
343
+ {
344
+ type = val[0]
345
+ nil_type = AST::Types::Nil.new(location: val[1].location)
346
+ result = AST::Types::Union.build(types: [type, nil_type], location: val[0].location + val[1].location)
347
+ }
348
+ | kSELFQ
349
+ {
350
+ type = AST::Types::Self.new(location: val[0].location)
351
+ nil_type = AST::Types::Nil.new(location: val[0].location)
352
+ result = AST::Types::Union.build(types: [type, nil_type], location: val[0].location)
353
+ }
354
+ | tINT
355
+ {
356
+ result = AST::Types::Literal.new(value: val[0].value, location: val[0].location)
357
+ }
358
+ | tSTRING
359
+ {
360
+ result = AST::Types::Literal.new(value: val[0].value, location: val[0].location)
361
+ }
362
+ | tSYMBOL
363
+ {
364
+ result = AST::Types::Literal.new(value: val[0].value, location: val[0].location)
365
+ }
366
+ | tLBRACKET type_seq tRBRACKET
367
+ {
368
+ loc = val[0].location + val[2].location
369
+ result = AST::Types::Tuple.new(types: val[1], location: loc)
370
+ }
371
+
372
+ hash_elements: # nothing
373
+ {
374
+ result = {}
375
+ }
376
+ | hash_element tCOMMA hash_elements
377
+ {
378
+ result = val[0].merge(val[2])
379
+ }
380
+ | hash_element
381
+ hash_element: tINT tROCKET type
382
+ {
383
+ result = { val[0].value => val[2] }
384
+ }
385
+ | tSTRING tROCKET type
386
+ {
387
+ result = { val[0].value => val[2] }
388
+ }
389
+ | tSYMBOL tROCKET type
390
+ {
391
+ result = { val[0].value => val[2] }
392
+ }
393
+ | keyword tCOLON type
394
+ {
395
+ result = { val[0].value => val[2] }
396
+ }
397
+
398
+ paren_type: tLPAREN type tRPAREN
399
+ {
400
+ result = val[1].with_location(val[0].location + val[2].location)
401
+ }
402
+ | tLBRACE hash_elements tRBRACE
403
+ {
404
+ location = val[0].location + val[2].location
405
+ result = AST::Types::Hash.new(elements: val[1], location: location)
406
+ }
407
+ | simple_type
408
+
409
+ constructor: # nothing
410
+ {
411
+ result = nil
412
+ }
413
+ | kCONSTRUCTOR
414
+ {
415
+ result = LocatedValue.new(location: val[0].location, value: true)
416
+ }
417
+ | kNOCONSTRUCTOR
418
+ {
419
+ result = LocatedValue.new(location: val[0].location, value: false)
420
+ }
421
+
422
+ type: paren_type
423
+ | union_seq
424
+ {
425
+ loc = val[0].first.location + val[0].last.location
426
+ result = AST::Types::Union.build(types: val[0], location: loc)
427
+ }
428
+ | tHAT tLPAREN lambda_params tRPAREN tARROW paren_type
429
+ {
430
+ loc = val[0].location + val[5].location
431
+ result = AST::Types::Proc.new(params: val[2], return_type: val[5], location: loc)
432
+ }
433
+
434
+ lambda_params: lambda_params1
435
+ | paren_type
436
+ {
437
+ result = Interface::Params.empty.update(required: [val[0]])
438
+ }
439
+ | paren_type tCOMMA lambda_params
440
+ {
441
+ result = val[2].update(required: [val[0]] + val[2].required)
442
+ }
443
+
444
+ lambda_params1: # nothing
445
+ {
446
+ result = Interface::Params.empty
447
+ }
448
+ | tSTAR paren_type
449
+ {
450
+ result = Interface::Params.empty.update(rest: val[1])
451
+ }
452
+ | tQUESTION paren_type
453
+ {
454
+ result = Interface::Params.empty.update(optional: [val[1]])
455
+ }
456
+ | tQUESTION paren_type tCOMMA lambda_params1
457
+ {
458
+ result = val[3].update(optional: [val[1]] + val[3].optional)
459
+ }
460
+
461
+
462
+ type_seq: type
463
+ {
464
+ result = [val[0]]
465
+ }
466
+ | type tCOMMA type_seq
467
+ {
468
+ result = [val[0]] + val[2]
469
+ }
470
+
471
+ union_seq: simple_type tBAR simple_type
472
+ {
473
+ result = [val[0], val[2]]
474
+ }
475
+ | simple_type tBAR union_seq
476
+ {
477
+ result = [val[0]] + val[2]
478
+ }
479
+
480
+ keyword: tIDENT
481
+ | tINTERFACE_NAME
482
+ | kANY
483
+ | kCLASS
484
+ | kMODULE
485
+ | kINSTANCE
486
+ | kBLOCK
487
+ | kINCLUDE
488
+ | kIVAR
489
+ | kSELF
490
+ | kTYPE
491
+
492
+ signatures: # nothing
493
+ {
494
+ result = []
495
+ }
496
+ | interface signatures
497
+ {
498
+ result = [val[0]] + val[1]
499
+ }
500
+ | class_decl signatures
501
+ {
502
+ result = [val[0]] + val[1]
503
+ }
504
+ | module_decl signatures
505
+ {
506
+ result = [val[0]] + val[1]
507
+ }
508
+ | extension_decl signatures
509
+ {
510
+ result = [val[0]] + val[1]
511
+ }
512
+ | const_decl signatures
513
+ {
514
+ result = [val[0]] + val[1]
515
+ }
516
+ | gvar_decl signatures
517
+ {
518
+ result = [val[0]] + val[1]
519
+ }
520
+ | alias_decl signatures
521
+ {
522
+ result = [val[0]] + val[1]
523
+ }
524
+
525
+ gvar_decl: tGVAR tCOLON type
526
+ {
527
+ loc = val.first.location + val.last.location
528
+ result = AST::Signature::Gvar.new(
529
+ location: loc,
530
+ name: val[0].value,
531
+ type: val[2]
532
+ )
533
+ }
534
+
535
+ const_decl: module_name tCOLON type
536
+ {
537
+ loc = val.first.location + val.last.location
538
+ result = AST::Signature::Const.new(
539
+ location: loc,
540
+ name: val[0].value.absolute!,
541
+ type: val[2]
542
+ )
543
+ }
544
+
545
+ interface: kINTERFACE interface_name type_params interface_members kEND
546
+ {
547
+ loc = val.first.location + val.last.location
548
+ result = AST::Signature::Interface.new(
549
+ location: loc,
550
+ name: val[1].value.absolute!,
551
+ params: val[2],
552
+ methods: val[3]
553
+ )
554
+ }
555
+
556
+ class_decl: kCLASS module_name class_params_super class_members kEND
557
+ {
558
+ loc = val.first.location + val.last.location
559
+ result = AST::Signature::Class.new(name: val[1].value.absolute!,
560
+ params: val[2][0],
561
+ super_class: val[2][1],
562
+ members: val[3],
563
+ location: loc)
564
+ }
565
+
566
+ class_params_super: # nothing
567
+ {
568
+ result = [nil, nil]
569
+ }
570
+ | tLT super_class
571
+ {
572
+ result = [nil, val[1]]
573
+ }
574
+ | tLT type_param_seq tGT
575
+ {
576
+ location = val[0].location + val[2].location
577
+ params = AST::TypeParams.new(location: location, variables: val[1])
578
+ result = [params, nil]
579
+ }
580
+ | tLT type_param_seq tGT tLT super_class
581
+ {
582
+ location = val[0].location + val[2].location
583
+ params = AST::TypeParams.new(location: location, variables: val[1])
584
+ result = [params, val[4]]
585
+ }
586
+
587
+ module_decl: kMODULE module_name type_params self_type_opt class_members kEND
588
+ {
589
+ loc = val.first.location + val.last.location
590
+ result = AST::Signature::Module.new(name: val[1].value.absolute!,
591
+ location: loc,
592
+ params: val[2],
593
+ self_type: val[3],
594
+ members: val[4])
595
+ }
596
+
597
+ extension_decl: kEXTENSION module_name type_params tLPAREN tUIDENT tRPAREN class_members kEND
598
+ {
599
+ loc = val.first.location + val.last.location
600
+ result = AST::Signature::Extension.new(module_name: val[1].value.absolute!,
601
+ name: val[4].value,
602
+ location: loc,
603
+ params: val[2],
604
+ members: val[6])
605
+ }
606
+
607
+ alias_decl: kTYPE alias_name type_params tEQ type
608
+ {
609
+ loc = val[0].location + val[4].location
610
+ result = AST::Signature::Alias.new(location: loc,
611
+ name: val[1].value.absolute!,
612
+ params: val[2],
613
+ type: val[4])
614
+ }
615
+
616
+ self_type_opt: # nothing
617
+ {
618
+ result = nil
619
+ }
620
+ | tCOLON type
621
+ {
622
+ result = val[1]
623
+ }
624
+
625
+ interface_name: tQUALIFIED_INTERFACE_NAME
626
+ | tINTERFACE_NAME {
627
+ name = Names::Interface.new(name: val[0].value, namespace: AST::Namespace.empty)
628
+ result = LocatedValue.new(location: val[0].location, value: name)
629
+ }
630
+
631
+ module_name: tQUALIFIED_MODULE_NAME
632
+ | tUIDENT {
633
+ name = Names::Module.new(name: val[0].value, namespace: AST::Namespace.empty)
634
+ result = LocatedValue.new(location: val[0].location, value: name)
635
+ }
636
+
637
+ alias_name: tQUALIFIED_ALIAS_NAME
638
+ | tIDENT {
639
+ name = Names::Alias.new(name: val[0].value, namespace: AST::Namespace.empty)
640
+ result = LocatedValue.new(location: val[0].location, value: name)
641
+ }
642
+
643
+ class_members: # nothing
644
+ {
645
+ result = []
646
+ }
647
+ | class_member class_members
648
+ {
649
+ result = [val[0]] + val[1]
650
+ }
651
+
652
+ class_member: instance_method_member
653
+ | module_method_member
654
+ | module_instance_method_member
655
+ | include_member
656
+ | extend_member
657
+ | ivar_member
658
+ | attr_reader_member
659
+ | attr_accessor_member
660
+
661
+ ivar_member: tIVAR_NAME tCOLON type
662
+ {
663
+ loc = val.first.location + val.last.location
664
+ result = AST::Signature::Members::Ivar.new(
665
+ location: loc,
666
+ name: val[0].value,
667
+ type: val[2]
668
+ )
669
+ }
670
+
671
+ instance_method_member: kDEF method_annotations method_name tCOLON method_type_union
672
+ {
673
+ loc = val.first.location + val.last.last.location
674
+ result = AST::Signature::Members::Method.new(
675
+ name: val[2].value,
676
+ types: val[4],
677
+ kind: :instance,
678
+ location: loc,
679
+ attributes: val[1] || []
680
+ )
681
+ }
682
+
683
+ module_method_member: kDEF method_annotations kSELF tDOT method_name tCOLON method_type_union
684
+ {
685
+ loc = val.first.location + val.last.last.location
686
+ result = AST::Signature::Members::Method.new(
687
+ name: val[4].value,
688
+ types: val[6],
689
+ kind: :module,
690
+ location: loc,
691
+ attributes: val[1] || []
692
+ )
693
+ }
694
+
695
+ module_instance_method_member: kDEF method_annotations kSELFQ tDOT method_name tCOLON method_type_union
696
+ {
697
+ loc = val.first.location + val.last.last.location
698
+ result = AST::Signature::Members::Method.new(
699
+ name: val[4].value,
700
+ types: val[6],
701
+ kind: :module_instance,
702
+ location: loc,
703
+ attributes: val[1] || []
704
+ )
705
+ }
706
+
707
+ include_member: kINCLUDE module_name
708
+ {
709
+ loc = val[0].location + val[1].location
710
+ name = val[1].value
711
+ result = AST::Signature::Members::Include.new(name: name, location: loc, args: [])
712
+ }
713
+ | kINCLUDE module_name tLT type_seq tGT
714
+ {
715
+ loc = val[0].location + val[4].location
716
+ name = val[1].value
717
+ result = AST::Signature::Members::Include.new(name: name, location: loc, args: val[3])
718
+ }
719
+
720
+ extend_member: kEXTEND module_name
721
+ {
722
+ loc = val[0].location + val[1].location
723
+ name = val[1].value
724
+ result = AST::Signature::Members::Extend.new(name: name, location: loc, args: [])
725
+ }
726
+ | kEXTEND module_name tLT type_seq tGT
727
+ {
728
+ loc = val[0].location + val[4].location
729
+ name = val[1].value
730
+ result = AST::Signature::Members::Extend.new(name: name, location: loc, args: val[3])
731
+ }
732
+
733
+ attr_reader_member: kATTR_READER method_name attr_ivar_opt tCOLON type
734
+ {
735
+ loc = val.first.location + val.last.location
736
+ result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :reader, ivar: val[2], type: val[4])
737
+ }
738
+
739
+ attr_accessor_member: kATTR_ACCESSOR method_name attr_ivar_opt tCOLON type
740
+ {
741
+ loc = val.first.location + val.last.location
742
+ result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :accessor, ivar: val[2], type: val[4])
743
+ }
744
+
745
+ attr_ivar_opt: # nothing
746
+ {
747
+ result = nil
748
+ }
749
+ | tLPAREN tRPAREN
750
+ {
751
+ result = false
752
+ }
753
+ | tLPAREN tIVAR_NAME tRPAREN
754
+ {
755
+ result = val[1].value
756
+ }
757
+
758
+ method_annotations: # nothing
759
+ {
760
+ result = nil
761
+ }
762
+ | tLPAREN method_annotation_seq tRPAREN
763
+ {
764
+ result = val[1]
765
+ }
766
+
767
+ method_annotation_seq: method_annotation_keyword
768
+ {
769
+ result = [val[0]]
770
+ }
771
+ | method_annotation_keyword tCOMMA method_annotation_seq
772
+ {
773
+ result = [val[0]] + val[2]
774
+ }
775
+
776
+ method_annotation_keyword: kCONSTRUCTOR
777
+ {
778
+ result = val[0].value
779
+ }
780
+ | kINCOMPATIBLE
781
+ {
782
+ result = val[0].value
783
+ }
784
+
785
+ super_class: module_name
786
+ {
787
+ result = AST::Signature::SuperClass.new(location: val[0].location, name: val[0].value, args: [])
788
+ }
789
+ | module_name tLT type_seq tGT
790
+ {
791
+ loc = val[0].location + val[3].location
792
+ name = val[0].value
793
+ result = AST::Signature::SuperClass.new(location: loc, name: name, args: val[2])
794
+ }
795
+
796
+ type_params: # nothing
797
+ {
798
+ result = nil
799
+ }
800
+ | tLT type_param_seq tGT
801
+ {
802
+ location = val[0].location + val[2].location
803
+ result = AST::TypeParams.new(location: location, variables: val[1])
804
+ }
805
+
806
+ type_param_seq: tVAR
807
+ {
808
+ result = [val[0].value]
809
+ }
810
+ | tVAR tCOMMA type_param_seq
811
+ {
812
+ result = [val[0].value] + val[2]
813
+ }
814
+
815
+ interface_members: # nothing
816
+ {
817
+ result = []
818
+ }
819
+ | interface_method interface_members
820
+ {
821
+ result = val[1].unshift(val[0])
822
+ }
823
+
824
+ interface_method: kDEF method_name tCOLON method_type_union
825
+ {
826
+ loc = val[0].location + val[3].last.location
827
+ result = AST::Signature::Interface::Method.new(location: loc, name: val[1].value, types: val[3])
828
+ }
829
+
830
+ method_type_union: method_type
831
+ {
832
+ result = [val[0]]
833
+ }
834
+ | method_type tBAR method_type_union
835
+ {
836
+ result = [val[0]] + val[2]
837
+ }
838
+
839
+ method_name: method_name0
840
+ | tSTAR
841
+ | tSTAR2
842
+ | tPERCENT
843
+ | tMINUS
844
+ | tLT
845
+ | tGT
846
+ | tUMINUS
847
+ | tBAR
848
+ {
849
+ result = LocatedValue.new(location: val[0].location, value: :|)
850
+ }
851
+ | method_name0 tEQ
852
+ {
853
+ raise ParseError, "\nunexpected method name #{val[0].to_s} =" unless val[0].location.pred?(val[1].location)
854
+ result = LocatedValue.new(location: val[0].location + val[1].location,
855
+ value: :"#{val[0].value}=")
856
+ }
857
+ | method_name0 tQUESTION
858
+ {
859
+ raise ParseError, "\nunexpected method name #{val[0].to_s} ?" unless val[0].location.pred?(val[1].location)
860
+ result = LocatedValue.new(location: val[0].location + val[1].location,
861
+ value: :"#{val[0].value}?")
862
+ }
863
+ | method_name0 tBANG
864
+ {
865
+ raise ParseError, "\nunexpected method name #{val[0].to_s} !" unless val[0].location.pred?(val[1].location)
866
+ result = LocatedValue.new(location: val[0].location + val[1].location,
867
+ value: :"#{val[0].value}!")
868
+ }
869
+ | tGT tGT
870
+ {
871
+ raise ParseError, "\nunexpected method name > >" unless val[0].location.pred?(val[1].location)
872
+ result = LocatedValue.new(location: val[0].location + val[1].location, value: :>>)
873
+ }
874
+ | kNIL tQUESTION
875
+ {
876
+ raise ParseError, "\nunexpected method name #{val[0].to_s} ?" unless val[0].location.pred?(val[1].location)
877
+ result = LocatedValue.new(location: val[0].location + val[1].location,
878
+ value: :"nil?")
879
+ }
880
+
881
+ method_name0: tIDENT
882
+ | tUIDENT
883
+ | tINTERFACE_NAME
884
+ | kANY
885
+ | kVOID
886
+ | kINTERFACE
887
+ | kEND
888
+ | tPLUS
889
+ | kCLASS
890
+ | kMODULE
891
+ | kINSTANCE
892
+ | kEXTEND
893
+ | kINCLUDE
894
+ | tOPERATOR
895
+ | tHAT
896
+ | tBANG
897
+ | kBLOCK
898
+ | kBREAK
899
+ | kMETHOD
900
+ | kBOOL
901
+ | kTYPE
902
+ | kCONSTRUCTOR
903
+ {
904
+ result = LocatedValue.new(location: val[0].location, value: :constructor)
905
+ }
906
+ | kNOCONSTRUCTOR
907
+ {
908
+ result = LocatedValue.new(location: val[0].location, value: :noconstructor)
909
+ }
910
+ | kATTR_READER
911
+ | kATTR_ACCESSOR
912
+ | kINCOMPATIBLE
913
+
914
+ annotation: kAT_TYPE kVAR subject tCOLON type
915
+ {
916
+ loc = val.first.location + val.last.location
917
+ result = AST::Annotation::VarType.new(location: loc,
918
+ name: val[2].value,
919
+ type: val[4])
920
+ }
921
+ | kAT_TYPE kMETHOD subject tCOLON method_type
922
+ {
923
+ loc = val.first.location + val.last.location
924
+ result = AST::Annotation::MethodType.new(location: loc,
925
+ name: val[2].value,
926
+ type: val[4])
927
+ }
928
+ | kAT_TYPE kRETURN tCOLON type
929
+ {
930
+ loc = val.first.location + val.last.location
931
+ result = AST::Annotation::ReturnType.new(type: val[3], location: loc)
932
+ }
933
+ | kAT_TYPE kBLOCK tCOLON type
934
+ {
935
+ loc = val.first.location + val.last.location
936
+ result = AST::Annotation::BlockType.new(type: val[3], location: loc)
937
+ }
938
+ | kAT_TYPE kSELF tCOLON type
939
+ {
940
+ loc = val.first.location + val.last.location
941
+ result = AST::Annotation::SelfType.new(type: val[3], location: loc)
942
+ }
943
+ | kAT_TYPE kCONST module_name tCOLON type
944
+ {
945
+ loc = val[0].location + val[4].location
946
+ result = AST::Annotation::ConstType.new(name: val[2].value,
947
+ type: val[4],
948
+ location: loc)
949
+ }
950
+ | kAT_TYPE kINSTANCE tCOLON type
951
+ {
952
+ loc = val.first.location + val.last.location
953
+ result = AST::Annotation::InstanceType.new(type: val[3], location: loc)
954
+ }
955
+ | kAT_TYPE kMODULE tCOLON type
956
+ {
957
+ loc = val.first.location + val.last.location
958
+ result = AST::Annotation::ModuleType.new(type: val[3], location: loc)
959
+ }
960
+ | kAT_TYPE kIVAR tIVAR_NAME tCOLON type
961
+ {
962
+ loc = val.first.location + val.last.location
963
+ result = AST::Annotation::IvarType.new(name: val[2].value, type: val[4], location: loc)
964
+ }
965
+ | kAT_IMPLEMENTS module_name type_params
966
+ {
967
+ loc = val[0].location + (val[2]&.location || val[1].location)
968
+ args = val[2]&.variables || []
969
+ name = AST::Annotation::Implements::Module.new(name: val[1].value, args: args)
970
+ result = AST::Annotation::Implements.new(name: name, location: loc)
971
+ }
972
+ | kAT_DYNAMIC dynamic_names
973
+ {
974
+ loc = val[0].location + val[1].last.location
975
+ result = AST::Annotation::Dynamic.new(names: val[1], location: loc)
976
+ }
977
+ | kAT_TYPE kBREAK tCOLON type
978
+ {
979
+ loc = val.first.location + val.last.location
980
+ result = AST::Annotation::BreakType.new(type: val[3], location: loc)
981
+ }
982
+
983
+ dynamic_names: dynamic_name tCOMMA dynamic_names
984
+ {
985
+ result = [val[0]] + val[2]
986
+ }
987
+ | dynamic_name
988
+ {
989
+ result = val
990
+ }
991
+
992
+ dynamic_name: method_name
993
+ {
994
+ result = AST::Annotation::Dynamic::Name.new(name: val[0].value, location: val[0].location, kind: :instance)
995
+ }
996
+ | kSELF tDOT method_name
997
+ {
998
+ loc = val.first.location + val.last.location
999
+ result = AST::Annotation::Dynamic::Name.new(name: val[2].value, location: loc, kind: :module)
1000
+ }
1001
+ | kSELFQ tDOT method_name
1002
+ {
1003
+ loc = val.first.location + val.last.location
1004
+ result = AST::Annotation::Dynamic::Name.new(name: val[2].value, location: loc, kind: :module_instance)
1005
+ }
1006
+
1007
+ subject: tIDENT
1008
+ {
1009
+ result = val[0]
1010
+ }
600
1011
  end
601
1012
 
602
1013
  ---- inner
@@ -670,148 +1081,162 @@ def next_token
670
1081
  when input.eos?
671
1082
  [false, false]
672
1083
  when input.scan(/->/)
673
- new_token(:ARROW)
1084
+ new_token(:tARROW)
674
1085
  when input.scan(/\?/)
675
- new_token(:QUESTION)
1086
+ new_token(:tQUESTION)
676
1087
  when input.scan(/!/)
677
- new_token(:BANG, :!)
1088
+ new_token(:tBANG, :!)
678
1089
  when input.scan(/\(/)
679
- new_token(:LPAREN, nil)
1090
+ new_token(:tLPAREN, nil)
680
1091
  when input.scan(/\)/)
681
- new_token(:RPAREN, nil)
1092
+ new_token(:tRPAREN, nil)
682
1093
  when input.scan(/{/)
683
- new_token(:LBRACE, nil)
1094
+ new_token(:tLBRACE, nil)
684
1095
  when input.scan(/}/)
685
- new_token(:RBRACE, nil)
1096
+ new_token(:tRBRACE, nil)
686
1097
  when input.scan(/,/)
687
- new_token(:COMMA, nil)
1098
+ new_token(:tCOMMA, nil)
688
1099
  when input.scan(/:\w+/)
689
- new_token(:SYMBOL, input.matched[1..-1].to_sym)
690
- when input.scan(/::/)
691
- new_token(:COLON2)
692
- when input.scan(/:/)
693
- new_token(:COLON)
1100
+ new_token(:tSYMBOL, input.matched[1..-1].to_sym)
694
1101
  when input.scan(/\*\*/)
695
- new_token(:STAR2, :**)
1102
+ new_token(:tSTAR2, :**)
696
1103
  when input.scan(/\*/)
697
- new_token(:STAR, :*)
1104
+ new_token(:tSTAR, :*)
698
1105
  when input.scan(/\+/)
699
- new_token(:PLUS, :+)
1106
+ new_token(:tPLUS, :+)
700
1107
  when input.scan(/\./)
701
- new_token(:DOT)
702
- when input.scan(/<:/)
703
- new_token(:LTCOLON)
1108
+ new_token(:tDOT)
1109
+ when input.scan(/<:(?!:)/)
1110
+ loc = new_token("<:")[1].location
1111
+ Steep.logger.warn("`<:` syntax for super class is deprecated. Use `<` instead. (#{loc.buffer.name}:#{loc})")
1112
+ new_token(:tLT)
704
1113
  when input.scan(/\^/)
705
- new_token(:HAT, :"^")
1114
+ new_token(:tHAT, :"^")
1115
+ when input.scan(/=>/)
1116
+ new_token(:tROCKET, :"=>")
706
1117
  when input.scan(/(\[\]=)|(\[\])|===|==|!=|<<|=~/)
707
- new_token(:OPERATOR, input.matched.to_sym)
1118
+ new_token(:tOPERATOR, input.matched.to_sym)
708
1119
  when input.scan(/\[/)
709
- new_token(:LBRACKET, nil)
1120
+ new_token(:tLBRACKET, nil)
710
1121
  when input.scan(/\]/)
711
- new_token(:RBRACKET, nil)
1122
+ new_token(:tRBRACKET, nil)
712
1123
  when input.scan(/<=/)
713
- new_token(:OPERATOR, :<=)
1124
+ new_token(:tOPERATOR, :<=)
714
1125
  when input.scan(/>=/)
715
- new_token(:OPERATOR, :>=)
1126
+ new_token(:tOPERATOR, :>=)
716
1127
  when input.scan(/=/)
717
- new_token(:EQ, :"=")
1128
+ new_token(:tEQ, :"=")
718
1129
  when input.scan(/</)
719
- new_token(:LT, :<)
1130
+ new_token(:tLT, :<)
720
1131
  when input.scan(/>/)
721
- new_token(:GT, :>)
1132
+ new_token(:tGT, :>)
722
1133
  when input.scan(/nil\b/)
723
- new_token(:NIL, :nil)
1134
+ new_token(:kNIL, :nil)
724
1135
  when input.scan(/bool\b/)
725
- new_token(:BOOL, :bool)
1136
+ new_token(:kBOOL, :bool)
726
1137
  when input.scan(/any\b/)
727
- new_token(:ANY, :any)
1138
+ new_token(:kANY, :any)
728
1139
  when input.scan(/void\b/)
729
- new_token(:VOID, :void)
1140
+ new_token(:kVOID, :void)
730
1141
  when input.scan(/type\b/)
731
- new_token(:TYPE, :type)
1142
+ new_token(:kTYPE, :type)
732
1143
  when input.scan(/interface\b/)
733
- new_token(:INTERFACE, :interface)
1144
+ new_token(:kINTERFACE, :interface)
734
1145
  when input.scan(/incompatible\b/)
735
- new_token(:INCOMPATIBLE, :incompatible)
1146
+ new_token(:kINCOMPATIBLE, :incompatible)
736
1147
  when input.scan(/end\b/)
737
- new_token(:END, :end)
1148
+ new_token(:kEND, :end)
738
1149
  when input.scan(/\|/)
739
- new_token(:BAR, :bar)
1150
+ new_token(:tBAR, :bar)
740
1151
  when input.scan(/-@/)
741
- new_token(:UMINUS, :"-@")
1152
+ new_token(:tUMINUS, :"-@")
742
1153
  when input.scan(/def\b/)
743
- new_token(:DEF)
1154
+ new_token(:kDEF)
744
1155
  when input.scan(/@type\b/)
745
- new_token(:AT_TYPE)
1156
+ new_token(:kAT_TYPE)
746
1157
  when input.scan(/@implements\b/)
747
- new_token(:AT_IMPLEMENTS)
1158
+ new_token(:kAT_IMPLEMENTS)
748
1159
  when input.scan(/@dynamic\b/)
749
- new_token(:AT_DYNAMIC)
1160
+ new_token(:kAT_DYNAMIC)
750
1161
  when input.scan(/const\b/)
751
- new_token(:CONST, :const)
1162
+ new_token(:kCONST, :const)
752
1163
  when input.scan(/var\b/)
753
- new_token(:VAR, :var)
1164
+ new_token(:kVAR, :var)
754
1165
  when input.scan(/return\b/)
755
- new_token(:RETURN)
1166
+ new_token(:kRETURN)
756
1167
  when input.scan(/block\b/)
757
- new_token(:BLOCK, :block)
1168
+ new_token(:kBLOCK, :block)
758
1169
  when input.scan(/break\b/)
759
- new_token(:BREAK, :break)
1170
+ new_token(:kBREAK, :break)
760
1171
  when input.scan(/method\b/)
761
- new_token(:METHOD, :method)
1172
+ new_token(:kMETHOD, :method)
762
1173
  when input.scan(/self\?/)
763
- new_token(:SELFQ)
1174
+ new_token(:kSELFQ)
764
1175
  when input.scan(/self\b/)
765
- new_token(:SELF, :self)
1176
+ new_token(:kSELF, :self)
766
1177
  when input.scan(/'\w+/)
767
- new_token(:TVAR, input.matched.gsub(/\A'/, '').to_sym)
1178
+ new_token(:tVAR, input.matched.gsub(/\A'/, '').to_sym)
768
1179
  when input.scan(/attr_reader\b/)
769
- new_token(:ATTR_READER, :attr_reader)
1180
+ new_token(:kATTR_READER, :attr_reader)
770
1181
  when input.scan(/attr_accessor\b/)
771
- new_token(:ATTR_ACCESSOR, :attr_accessor)
1182
+ new_token(:kATTR_ACCESSOR, :attr_accessor)
772
1183
  when input.scan(/instance\b/)
773
- new_token(:INSTANCE, :instance)
1184
+ new_token(:kINSTANCE, :instance)
774
1185
  when input.scan(/class\b/)
775
- new_token(:CLASS, :class)
1186
+ new_token(:kCLASS, :class)
776
1187
  when input.scan(/module\b/)
777
- new_token(:MODULE, :module)
1188
+ new_token(:kMODULE, :module)
778
1189
  when input.scan(/include\b/)
779
- new_token(:INCLUDE, :include)
1190
+ new_token(:kINCLUDE, :include)
780
1191
  when input.scan(/extend\b/)
781
- new_token(:EXTEND, :extend)
1192
+ new_token(:kEXTEND, :extend)
782
1193
  when input.scan(/instance\b/)
783
- new_token(:INSTANCE, :instance)
1194
+ new_token(:kINSTANCE, :instance)
784
1195
  when input.scan(/ivar\b/)
785
- new_token(:IVAR, :ivar)
1196
+ new_token(:kIVAR, :ivar)
786
1197
  when input.scan(/%/)
787
- new_token(:PERCENT, :%)
1198
+ new_token(:tPERCENT, :%)
788
1199
  when input.scan(/-/)
789
- new_token(:MINUS, :-)
1200
+ new_token(:tMINUS, :-)
790
1201
  when input.scan(/&/)
791
- new_token(:OPERATOR, :&)
1202
+ new_token(:tOPERATOR, :&)
792
1203
  when input.scan(/~/)
793
- new_token(:OPERATOR, :~)
1204
+ new_token(:tOPERATOR, :~)
794
1205
  when input.scan(/\//)
795
- new_token(:OPERATOR, :/)
1206
+ new_token(:tOPERATOR, :/)
796
1207
  when input.scan(/extension\b/)
797
- new_token(:EXTENSION, :extension)
1208
+ new_token(:kEXTENSION, :extension)
798
1209
  when input.scan(/constructor\b/)
799
- new_token(:CONSTRUCTOR, :constructor)
1210
+ new_token(:kCONSTRUCTOR, :constructor)
800
1211
  when input.scan(/noconstructor\b/)
801
- new_token(:NOCONSTRUCTOR, :noconstructor)
1212
+ new_token(:kNOCONSTRUCTOR, :noconstructor)
802
1213
  when input.scan(/\$\w+\b/)
803
- new_token(:GVAR, input.matched.to_sym)
1214
+ new_token(:tGVAR, input.matched.to_sym)
1215
+ when input.scan(/::([A-Z]\w*::)*[A-Z]\w*/)
1216
+ new_token(:tQUALIFIED_MODULE_NAME, Names::Module.parse(input.matched))
1217
+ when input.scan(/([A-Z]\w*::)+[A-Z]\w*/)
1218
+ new_token(:tQUALIFIED_MODULE_NAME, Names::Module.parse(input.matched))
1219
+ when input.scan(/::([A-Z]\w*::)*_\w+/)
1220
+ new_token(:tQUALIFIED_INTERFACE_NAME, Names::Interface.parse(input.matched))
1221
+ when input.scan(/([A-Z]\w*::)+_\w+/)
1222
+ new_token(:tQUALIFIED_INTERFACE_NAME, Names::Interface.parse(input.matched))
1223
+ when input.scan(/::([A-Z]\w*::)*[a-z]\w*/)
1224
+ new_token(:tQUALIFIED_ALIAS_NAME, Names::Alias.parse(input.matched))
1225
+ when input.scan(/([A-Z]\w*::)+[a-z]\w*/)
1226
+ new_token(:tQUALIFIED_ALIAS_NAME, Names::Alias.parse(input.matched))
804
1227
  when input.scan(/[A-Z]\w*/)
805
- new_token(:UIDENT, input.matched.to_sym)
1228
+ new_token(:tUIDENT, input.matched.to_sym)
806
1229
  when input.scan(/_\w+/)
807
- new_token(:INTERFACE_NAME, input.matched.to_sym)
1230
+ new_token(:tINTERFACE_NAME, input.matched.to_sym)
808
1231
  when input.scan(/@\w+/)
809
- new_token(:IVAR_NAME, input.matched.to_sym)
1232
+ new_token(:tIVAR_NAME, input.matched.to_sym)
810
1233
  when input.scan(/\d+/)
811
- new_token(:INT, input.matched.to_i)
1234
+ new_token(:tINT, input.matched.to_i)
812
1235
  when input.scan(/\"[^\"]*\"/)
813
- new_token(:STRING, input.matched[1...-1])
1236
+ new_token(:tSTRING, input.matched[1...-1])
814
1237
  when input.scan(/[a-z]\w*/)
815
- new_token(:LIDENT, input.matched.to_sym)
1238
+ new_token(:tIDENT, input.matched.to_sym)
1239
+ when input.scan(/:/)
1240
+ new_token(:tCOLON)
816
1241
  end
817
1242
  end