steep 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +27 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +48 -90
- data/Rakefile +10 -6
- data/Steepfile +1 -0
- data/bin/setup +1 -0
- data/bin/smoke_runner.rb +9 -14
- data/exe/rbs +3 -0
- data/exe/ruby-signature +3 -0
- data/exe/steep +1 -0
- data/lib/steep.rb +32 -26
- data/lib/steep/annotation_parser.rb +167 -0
- data/lib/steep/ast/annotation/collection.rb +7 -7
- data/lib/steep/ast/types.rb +60 -0
- data/lib/steep/ast/types/any.rb +1 -1
- data/lib/steep/ast/types/factory.rb +535 -0
- data/lib/steep/ast/types/name.rb +3 -3
- data/lib/steep/ast/types/var.rb +1 -1
- data/lib/steep/cli.rb +56 -240
- data/lib/steep/drivers/annotations.rb +36 -19
- data/lib/steep/drivers/check.rb +55 -91
- data/lib/steep/drivers/init.rb +54 -0
- data/lib/steep/drivers/langserver.rb +241 -150
- data/lib/steep/drivers/print_project.rb +56 -0
- data/lib/steep/drivers/signature_error_printer.rb +25 -0
- data/lib/steep/drivers/trace_printer.rb +25 -0
- data/lib/steep/drivers/utils/driver_helper.rb +26 -0
- data/lib/steep/drivers/validate.rb +18 -38
- data/lib/steep/drivers/vendor.rb +46 -0
- data/lib/steep/drivers/watch.rb +78 -140
- data/lib/steep/errors.rb +22 -13
- data/lib/steep/interface/interface.rb +91 -0
- data/lib/steep/interface/method.rb +0 -4
- data/lib/steep/interface/method_type.rb +362 -2
- data/lib/steep/interface/substitution.rb +22 -0
- data/lib/steep/project.rb +25 -233
- data/lib/steep/project/dsl.rb +132 -0
- data/lib/steep/project/file.rb +93 -76
- data/lib/steep/project/file_loader.rb +63 -0
- data/lib/steep/project/options.rb +7 -0
- data/lib/steep/project/target.rb +190 -0
- data/lib/steep/signature/errors.rb +25 -77
- data/lib/steep/signature/validator.rb +122 -0
- data/lib/steep/source.rb +12 -7
- data/lib/steep/subtyping/check.rb +357 -633
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/subtyping/trace.rb +23 -0
- data/lib/steep/type_construction.rb +509 -455
- data/lib/steep/type_inference/constant_env.rb +16 -24
- data/lib/steep/type_inference/type_env.rb +26 -18
- data/lib/steep/version.rb +1 -1
- data/sample/Steepfile +6 -0
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +6 -0
- data/smoke/alias/Steepfile +4 -0
- data/smoke/alias/a.rb +2 -2
- data/smoke/alias/{a.rbi → a.rbs} +1 -1
- data/smoke/and/Steepfile +4 -0
- data/smoke/array/Steepfile +4 -0
- data/smoke/array/a.rb +2 -2
- data/smoke/array/b.rb +4 -4
- data/smoke/array/c.rb +2 -2
- data/smoke/block/Steepfile +5 -0
- data/smoke/block/{a.rbi → a.rbs} +1 -1
- data/smoke/block/{c.rbi → c.rbs} +0 -0
- data/smoke/block/d.rb +6 -6
- data/smoke/case/Steepfile +4 -0
- data/smoke/case/a.rb +4 -3
- data/smoke/class/Steepfile +4 -0
- data/smoke/class/a.rb +1 -4
- data/smoke/class/a.rbs +24 -0
- data/smoke/class/h.rb +6 -2
- data/smoke/class/{h.rbi → h.rbs} +1 -2
- data/smoke/class/i.rb +1 -2
- data/smoke/class/i.rbs +9 -0
- data/smoke/const/Steepfile +4 -0
- data/smoke/dstr/Steepfile +4 -0
- data/smoke/ensure/Steepfile +4 -0
- data/smoke/ensure/a.rb +1 -1
- data/smoke/enumerator/Steepfile +4 -0
- data/smoke/enumerator/a.rb +7 -7
- data/smoke/enumerator/b.rb +6 -6
- data/smoke/extension/Steepfile +4 -0
- data/smoke/extension/{a.rbi → a.rbs} +2 -2
- data/smoke/extension/{e.rbi → e.rbs} +2 -2
- data/smoke/hash/Steepfile +4 -0
- data/smoke/hash/{a.rbi → a.rbs} +0 -0
- data/smoke/hash/b.rb +2 -2
- data/smoke/hash/c.rb +1 -1
- data/smoke/hash/e.rbs +3 -0
- data/smoke/hash/f.rb +1 -1
- data/smoke/hello/Steepfile +4 -0
- data/smoke/hello/hello.rbs +7 -0
- data/smoke/if/Steepfile +4 -0
- data/smoke/implements/Steepfile +4 -0
- data/smoke/implements/a.rbs +6 -0
- data/smoke/initialize/Steepfile +4 -0
- data/smoke/initialize/a.rbs +3 -0
- data/smoke/integer/Steepfile +4 -0
- data/smoke/integer/a.rb +5 -3
- data/smoke/interface/Steepfile +4 -0
- data/smoke/interface/{a.rbi → a.rbs} +0 -0
- data/smoke/kwbegin/Steepfile +4 -0
- data/smoke/lambda/Steepfile +4 -0
- data/smoke/lambda/a.rb +9 -2
- data/smoke/literal/Steepfile +4 -0
- data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
- data/smoke/map/Steepfile +4 -0
- data/smoke/map/a.rb +1 -1
- data/smoke/method/Steepfile +4 -0
- data/smoke/method/{a.rbi → a.rbs} +0 -0
- data/smoke/method/b.rb +1 -4
- data/smoke/method/d.rb +1 -0
- data/smoke/method/d.rbs +3 -0
- data/smoke/module/Steepfile +4 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbs +16 -0
- data/smoke/module/c.rb +1 -1
- data/smoke/regexp/Steepfile +4 -0
- data/smoke/regexp/a.rb +2 -2
- data/smoke/regexp/b.rb +16 -16
- data/smoke/regression/Steepfile +5 -0
- data/smoke/regression/array.rb +2 -2
- data/smoke/regression/hash.rb +2 -2
- data/smoke/regression/poly_new.rb +2 -0
- data/smoke/regression/poly_new.rbs +4 -0
- data/smoke/regression/set_divide.rb +2 -2
- data/smoke/rescue/Steepfile +4 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +4 -0
- data/smoke/self/a.rbs +4 -0
- data/smoke/skip/Steepfile +4 -0
- data/smoke/stdout/Steepfile +4 -0
- data/smoke/stdout/{a.rbi → a.rbs} +1 -1
- data/smoke/super/Steepfile +4 -0
- data/smoke/super/a.rbs +10 -0
- data/smoke/type_case/Steepfile +4 -0
- data/smoke/type_case/a.rb +1 -1
- data/smoke/yield/Steepfile +4 -0
- data/smoke/yield/a.rb +2 -2
- data/steep.gemspec +14 -7
- data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
- data/vendor/ruby-signature/.gitignore +12 -0
- data/vendor/ruby-signature/.rubocop.yml +15 -0
- data/vendor/ruby-signature/BSDL +22 -0
- data/vendor/ruby-signature/COPYING +56 -0
- data/vendor/ruby-signature/Gemfile +6 -0
- data/vendor/ruby-signature/README.md +93 -0
- data/vendor/ruby-signature/Rakefile +66 -0
- data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
- data/vendor/ruby-signature/bin/console +14 -0
- data/vendor/ruby-signature/bin/query-rdoc +103 -0
- data/vendor/ruby-signature/bin/setup +10 -0
- data/vendor/ruby-signature/bin/sort +88 -0
- data/vendor/ruby-signature/bin/test_runner.rb +17 -0
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
- data/vendor/ruby-signature/docs/sigs.md +148 -0
- data/vendor/ruby-signature/docs/stdlib.md +152 -0
- data/vendor/ruby-signature/docs/syntax.md +528 -0
- data/vendor/ruby-signature/exe/rbs +3 -0
- data/vendor/ruby-signature/exe/ruby-signature +7 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
- data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
- data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
- data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +244 -54
- data/.travis.yml +0 -7
- data/lib/steep/ast/signature/alias.rb +0 -19
- data/lib/steep/ast/signature/class.rb +0 -33
- data/lib/steep/ast/signature/const.rb +0 -17
- data/lib/steep/ast/signature/env.rb +0 -138
- data/lib/steep/ast/signature/extension.rb +0 -21
- data/lib/steep/ast/signature/gvar.rb +0 -17
- data/lib/steep/ast/signature/interface.rb +0 -31
- data/lib/steep/ast/signature/members.rb +0 -115
- data/lib/steep/ast/signature/module.rb +0 -21
- data/lib/steep/drivers/print_interface.rb +0 -94
- data/lib/steep/drivers/scaffold.rb +0 -321
- data/lib/steep/drivers/utils/each_signature.rb +0 -31
- data/lib/steep/interface/abstract.rb +0 -68
- data/lib/steep/interface/builder.rb +0 -637
- data/lib/steep/interface/instantiated.rb +0 -163
- data/lib/steep/interface/ivar_chain.rb +0 -26
- data/lib/steep/parser.y +0 -1278
- data/lib/steep/project/listener.rb +0 -53
- data/smoke/class/a.rbi +0 -24
- data/smoke/class/d.rb +0 -9
- data/smoke/class/e.rb +0 -12
- data/smoke/class/i.rbi +0 -9
- data/smoke/hash/e.rbi +0 -3
- data/smoke/hello/hello.rbi +0 -7
- data/smoke/implements/a.rbi +0 -6
- data/smoke/initialize/a.rbi +0 -3
- data/smoke/module/a.rbi +0 -16
- data/smoke/self/a.rbi +0 -4
- data/smoke/super/a.rbi +0 -10
- data/stdlib/builtin.rbi +0 -787
@@ -1,163 +0,0 @@
|
|
1
|
-
module Steep
|
2
|
-
module Interface
|
3
|
-
class Instantiated
|
4
|
-
attr_reader :type
|
5
|
-
attr_reader :methods
|
6
|
-
attr_reader :ivar_chains
|
7
|
-
|
8
|
-
def initialize(type:, methods:, ivar_chains:)
|
9
|
-
@type = type
|
10
|
-
@methods = methods
|
11
|
-
@ivar_chains = ivar_chains
|
12
|
-
end
|
13
|
-
|
14
|
-
def ivars
|
15
|
-
@ivars ||= ivar_chains.transform_values(&:type)
|
16
|
-
end
|
17
|
-
|
18
|
-
def ==(other)
|
19
|
-
other.is_a?(self.class) && other.type == type && other.params == params && other.methods == methods && other.ivars == ivars
|
20
|
-
end
|
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
|
-
|
30
|
-
class InvalidMethodOverrideError < StandardError
|
31
|
-
attr_reader :type
|
32
|
-
attr_reader :current_method
|
33
|
-
attr_reader :super_method
|
34
|
-
attr_reader :result
|
35
|
-
|
36
|
-
def initialize(type:, current_method:, super_method:, result:)
|
37
|
-
@type = type
|
38
|
-
@current_method = current_method
|
39
|
-
@super_method = super_method
|
40
|
-
@result = result
|
41
|
-
|
42
|
-
super "Invalid override of `#{current_method.name}` in #{type}: definition in #{current_method.type_name} is not compatible with its super (#{super_method.type_name})"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class InvalidIvarOverrideError < StandardError
|
47
|
-
attr_reader :type
|
48
|
-
attr_reader :ivar_name
|
49
|
-
attr_reader :current_ivar_type
|
50
|
-
attr_reader :super_ivar_type
|
51
|
-
|
52
|
-
def initialize(type:, ivar_name:, current_ivar_type:, super_ivar_type:)
|
53
|
-
@type = type
|
54
|
-
@ivar_name = ivar_name
|
55
|
-
@current_ivar_type = current_ivar_type
|
56
|
-
@super_ivar_type = super_ivar_type
|
57
|
-
|
58
|
-
super "Invalid override of `#{ivar_name}` in #{type}: #{current_ivar_type} is not compatible with #{super_ivar_type}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class PrivateOverrideError < StandardError
|
63
|
-
attr_reader :child_type
|
64
|
-
attr_reader :super_type
|
65
|
-
attr_reader :method_name
|
66
|
-
|
67
|
-
def initialize(child_type:, super_type:, method_name:)
|
68
|
-
@child_type = child_type
|
69
|
-
@super_type = super_type
|
70
|
-
@method_name = method_name
|
71
|
-
|
72
|
-
super "Public method `#{method_name}` cannot overriden to private: #{child_type} <: #{super_type}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def validate(check)
|
77
|
-
methods.each do |_, method|
|
78
|
-
validate_method_type(check, method)
|
79
|
-
validate_method_visibility method
|
80
|
-
end
|
81
|
-
|
82
|
-
ivar_chains.each do |name, chain|
|
83
|
-
validate_chain(check, name, chain)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def validate_chain(check, name, chain)
|
88
|
-
return unless chain.parent
|
89
|
-
|
90
|
-
this_type = chain.type
|
91
|
-
super_type = chain.parent.type
|
92
|
-
|
93
|
-
case
|
94
|
-
when this_type.is_a?(AST::Types::Any) && super_type.is_a?(AST::Types::Any)
|
95
|
-
# ok
|
96
|
-
else
|
97
|
-
relation = Subtyping::Relation.new(sub_type: this_type, super_type: super_type)
|
98
|
-
|
99
|
-
result1 = check.check(relation, constraints: Subtyping::Constraints.empty)
|
100
|
-
result2 = check.check(relation.flip, constraints: Subtyping::Constraints.empty)
|
101
|
-
|
102
|
-
if result1.failure? || result2.failure? || this_type.is_a?(AST::Types::Any) || super_type.is_a?(AST::Types::Any)
|
103
|
-
raise InvalidIvarOverrideError.new(type: self.type, ivar_name: name, current_ivar_type: this_type, super_ivar_type: super_type)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
validate_chain(check, name, chain.parent)
|
108
|
-
end
|
109
|
-
|
110
|
-
def validate_method_type(check, method)
|
111
|
-
if method.super_method && !method.incompatible?
|
112
|
-
result = check.check_method(method.name,
|
113
|
-
method,
|
114
|
-
method.super_method,
|
115
|
-
assumption: Set.new,
|
116
|
-
trace: Subtyping::Trace.new,
|
117
|
-
constraints: Subtyping::Constraints.empty)
|
118
|
-
|
119
|
-
if result.success?
|
120
|
-
validate_method_type(check, method.super_method)
|
121
|
-
else
|
122
|
-
raise InvalidMethodOverrideError.new(type: type,
|
123
|
-
current_method: method,
|
124
|
-
super_method: method.super_method,
|
125
|
-
result: result)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def validate_method_visibility(method)
|
131
|
-
if (super_method = method.super_method)
|
132
|
-
if method.private? && !super_method.private?
|
133
|
-
raise PrivateOverrideError.new(
|
134
|
-
child_type: method.type_name,
|
135
|
-
super_type: super_method.type_name,
|
136
|
-
method_name: method.name
|
137
|
-
)
|
138
|
-
end
|
139
|
-
|
140
|
-
validate_method_visibility(super_method)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
def select_method_type(&block)
|
145
|
-
self.class.new(
|
146
|
-
type: type,
|
147
|
-
methods: methods.each.with_object({}) do |(name, method), methods|
|
148
|
-
methods[name] = Method.new(
|
149
|
-
type_name: method.type_name,
|
150
|
-
name: method.name,
|
151
|
-
types: method.types.select(&block),
|
152
|
-
super_method: method.super_method,
|
153
|
-
attributes: method.attributes,
|
154
|
-
)
|
155
|
-
end.reject do |_, method|
|
156
|
-
method.types.empty?
|
157
|
-
end,
|
158
|
-
ivar_chains: ivar_chains
|
159
|
-
)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module Steep
|
2
|
-
module Interface
|
3
|
-
class IvarChain
|
4
|
-
attr_reader :type
|
5
|
-
attr_reader :parent
|
6
|
-
|
7
|
-
def initialize(type:, parent: nil)
|
8
|
-
@type = type
|
9
|
-
@parent = parent
|
10
|
-
end
|
11
|
-
|
12
|
-
def ==(other)
|
13
|
-
other.is_a?(IvarChain) &&
|
14
|
-
type == type &&
|
15
|
-
parent == parent
|
16
|
-
end
|
17
|
-
|
18
|
-
def subst(s)
|
19
|
-
self.class.new(
|
20
|
-
type: type.subst(s),
|
21
|
-
parent: parent&.subst(s)
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
data/lib/steep/parser.y
DELETED
@@ -1,1278 +0,0 @@
|
|
1
|
-
class Steep::Parser
|
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 kPRIVATE kALIAS
|
7
|
-
kSUPER
|
8
|
-
tARROW tBANG tBAR tCOLON tCOMMA tDOT tEQ tGT tGVAR tHAT tINT
|
9
|
-
tINTERFACE_NAME tIVAR_NAME tLBRACE tLBRACKET tIDENT tLPAREN tLT tROCKET
|
10
|
-
tMINUS tOPERATOR tPERCENT tPLUS tQUESTION tRBRACE tRBRACKET
|
11
|
-
tRPAREN tSTAR tSTAR2 tSTRING tSYMBOL tUIDENT tUMINUS tVAR
|
12
|
-
type_METHOD type_SIGNATURE type_ANNOTATION type_TYPE
|
13
|
-
tQUALIFIED_MODULE_NAME tQUALIFIED_INTERFACE_NAME tQUALIFIED_ALIAS_NAME
|
14
|
-
|
15
|
-
expect 3
|
16
|
-
|
17
|
-
rule
|
18
|
-
|
19
|
-
target: type_METHOD method_type
|
20
|
-
{
|
21
|
-
result = val[1]
|
22
|
-
}
|
23
|
-
| type_SIGNATURE signatures
|
24
|
-
{
|
25
|
-
result = val[1]
|
26
|
-
}
|
27
|
-
| type_ANNOTATION annotation
|
28
|
-
{
|
29
|
-
result = val[1]
|
30
|
-
}
|
31
|
-
| type_TYPE type
|
32
|
-
{
|
33
|
-
result = val[1]
|
34
|
-
}
|
35
|
-
|
36
|
-
method_type: type_params params block_opt tARROW return_type
|
37
|
-
{
|
38
|
-
result = AST::MethodType.new(location: AST::Location.concat(*val.compact.map(&:location)),
|
39
|
-
type_params: val[0],
|
40
|
-
params: val[1]&.value,
|
41
|
-
block: val[2],
|
42
|
-
return_type: val[4])
|
43
|
-
}
|
44
|
-
|
45
|
-
return_type: paren_type
|
46
|
-
|
47
|
-
params: # nothing
|
48
|
-
{
|
49
|
-
result = nil
|
50
|
-
}
|
51
|
-
| tLPAREN params0 tRPAREN
|
52
|
-
{
|
53
|
-
result = LocatedValue.new(location: val[0].location + val[2].location,
|
54
|
-
value: val[1])
|
55
|
-
}
|
56
|
-
| simple_type
|
57
|
-
{
|
58
|
-
result = LocatedValue.new(location: val[0].location,
|
59
|
-
value: AST::MethodType::Params::Required.new(location: val[0].location, type: val[0]))
|
60
|
-
}
|
61
|
-
|
62
|
-
params0: required_param
|
63
|
-
{
|
64
|
-
result = AST::MethodType::Params::Required.new(location: val[0].location, type: val[0])
|
65
|
-
}
|
66
|
-
| required_param tCOMMA params0
|
67
|
-
{
|
68
|
-
location = val[0].location
|
69
|
-
result = AST::MethodType::Params::Required.new(location: location,
|
70
|
-
type: val[0],
|
71
|
-
next_params: val[2])
|
72
|
-
}
|
73
|
-
| params1
|
74
|
-
{
|
75
|
-
result = val[0]
|
76
|
-
}
|
77
|
-
|
78
|
-
params1: optional_param
|
79
|
-
{
|
80
|
-
result = AST::MethodType::Params::Optional.new(location: val[0].first, type: val[0].last)
|
81
|
-
}
|
82
|
-
| optional_param tCOMMA params1
|
83
|
-
{
|
84
|
-
location = val[0].first
|
85
|
-
result = AST::MethodType::Params::Optional.new(type: val[0].last, location: location, next_params: val[2])
|
86
|
-
}
|
87
|
-
| params2
|
88
|
-
{
|
89
|
-
result = val[0]
|
90
|
-
}
|
91
|
-
|
92
|
-
params2: rest_param
|
93
|
-
{
|
94
|
-
result = AST::MethodType::Params::Rest.new(location: val[0].first, type: val[0].last)
|
95
|
-
}
|
96
|
-
| rest_param tCOMMA params3
|
97
|
-
{
|
98
|
-
loc = val[0].first
|
99
|
-
result = AST::MethodType::Params::Rest.new(location: loc, type: val[0].last, next_params: val[2])
|
100
|
-
}
|
101
|
-
| params3
|
102
|
-
{
|
103
|
-
result = val[0]
|
104
|
-
}
|
105
|
-
|
106
|
-
params3: required_keyword
|
107
|
-
{
|
108
|
-
location, name, type = val[0]
|
109
|
-
result = AST::MethodType::Params::RequiredKeyword.new(location: location, name: name, type: type)
|
110
|
-
}
|
111
|
-
| optional_keyword
|
112
|
-
{
|
113
|
-
location, name, type = val[0]
|
114
|
-
result = AST::MethodType::Params::OptionalKeyword.new(location: location, name: name, type: type)
|
115
|
-
}
|
116
|
-
| required_keyword tCOMMA params3
|
117
|
-
{
|
118
|
-
location, name, type = val[0]
|
119
|
-
result = AST::MethodType::Params::RequiredKeyword.new(location: location,
|
120
|
-
name: name,
|
121
|
-
type: type,
|
122
|
-
next_params: val[2])
|
123
|
-
}
|
124
|
-
| optional_keyword tCOMMA params3
|
125
|
-
{
|
126
|
-
location, name, type = val[0]
|
127
|
-
result = AST::MethodType::Params::OptionalKeyword.new(location: location,
|
128
|
-
name: name,
|
129
|
-
type: type,
|
130
|
-
next_params: val[2])
|
131
|
-
}
|
132
|
-
| params4
|
133
|
-
{
|
134
|
-
result = val[0]
|
135
|
-
}
|
136
|
-
|
137
|
-
params4: # nothing
|
138
|
-
{
|
139
|
-
result = nil
|
140
|
-
}
|
141
|
-
| tSTAR2 type
|
142
|
-
{
|
143
|
-
result = AST::MethodType::Params::RestKeyword.new(location: val[0].location + val[1].location,
|
144
|
-
type: val[1])
|
145
|
-
}
|
146
|
-
|
147
|
-
required_param: type
|
148
|
-
{
|
149
|
-
result = val[0]
|
150
|
-
}
|
151
|
-
|
152
|
-
optional_param: tQUESTION type
|
153
|
-
{
|
154
|
-
result = [
|
155
|
-
val[0].location + val[1].location,
|
156
|
-
val[1]
|
157
|
-
]
|
158
|
-
}
|
159
|
-
|
160
|
-
rest_param: tSTAR type
|
161
|
-
{
|
162
|
-
result = [
|
163
|
-
val[0].location + val[1].location,
|
164
|
-
val[1]
|
165
|
-
]
|
166
|
-
}
|
167
|
-
|
168
|
-
required_keyword: keyword tCOLON type
|
169
|
-
{
|
170
|
-
result = [
|
171
|
-
val[0].location + val[2].location,
|
172
|
-
val[0].value,
|
173
|
-
val[2]
|
174
|
-
]
|
175
|
-
}
|
176
|
-
|
177
|
-
optional_keyword: tQUESTION keyword tCOLON type
|
178
|
-
{
|
179
|
-
result = [
|
180
|
-
val[0].location + val[3].location,
|
181
|
-
val[1].value,
|
182
|
-
val[3]
|
183
|
-
]
|
184
|
-
}
|
185
|
-
|
186
|
-
block_opt: # nothing
|
187
|
-
{
|
188
|
-
result = nil
|
189
|
-
}
|
190
|
-
| block_optional tLBRACE tRBRACE
|
191
|
-
{
|
192
|
-
result = AST::MethodType::Block.new(params: nil,
|
193
|
-
return_type: nil,
|
194
|
-
location: (val[0] || val[1]).location + val[2].location,
|
195
|
-
optional: val[0]&.value || false)
|
196
|
-
}
|
197
|
-
| block_optional tLBRACE block_params tARROW type tRBRACE
|
198
|
-
{
|
199
|
-
result = AST::MethodType::Block.new(params: val[2],
|
200
|
-
return_type: val[4],
|
201
|
-
location: (val[0] || val[1]).location + val[5].location,
|
202
|
-
optional: val[0]&.value || false)
|
203
|
-
}
|
204
|
-
|
205
|
-
block_optional: # nothing
|
206
|
-
{
|
207
|
-
result = nil
|
208
|
-
}
|
209
|
-
| tQUESTION
|
210
|
-
{
|
211
|
-
result = LocatedValue.new(location: val[0].location, value: true)
|
212
|
-
}
|
213
|
-
|
214
|
-
block_params: # nothing
|
215
|
-
{
|
216
|
-
result = nil
|
217
|
-
}
|
218
|
-
| tLPAREN block_params0 tRPAREN
|
219
|
-
{
|
220
|
-
result = val[1]
|
221
|
-
}
|
222
|
-
|
223
|
-
block_params0: required_param
|
224
|
-
{
|
225
|
-
result = AST::MethodType::Params::Required.new(location: val[0].location,
|
226
|
-
type: val[0])
|
227
|
-
}
|
228
|
-
| required_param tCOMMA block_params0 {
|
229
|
-
result = AST::MethodType::Params::Required.new(location: val[0].location,
|
230
|
-
type: val[0],
|
231
|
-
next_params: val[2])
|
232
|
-
}
|
233
|
-
| block_params1
|
234
|
-
{
|
235
|
-
result = val[0]
|
236
|
-
}
|
237
|
-
|
238
|
-
block_params1: optional_param
|
239
|
-
{
|
240
|
-
result = AST::MethodType::Params::Optional.new(location: val[0].first,
|
241
|
-
type: val[0].last)
|
242
|
-
}
|
243
|
-
| optional_param tCOMMA block_params1
|
244
|
-
{
|
245
|
-
loc = val.first[0] + (val[2] || val[1]).location
|
246
|
-
type = val.first[1]
|
247
|
-
next_params = val[2]
|
248
|
-
result = AST::MethodType::Params::Optional.new(location: loc, type: type, next_params: next_params)
|
249
|
-
}
|
250
|
-
| block_params2
|
251
|
-
{
|
252
|
-
result = val[0]
|
253
|
-
}
|
254
|
-
|
255
|
-
block_params2: # nothing
|
256
|
-
{
|
257
|
-
result = nil
|
258
|
-
}
|
259
|
-
| rest_param
|
260
|
-
{
|
261
|
-
result = AST::MethodType::Params::Rest.new(location: val[0].first, type: val[0].last)
|
262
|
-
}
|
263
|
-
|
264
|
-
application_args: # nothing
|
265
|
-
{
|
266
|
-
result = nil
|
267
|
-
}
|
268
|
-
| tLT type_seq tGT
|
269
|
-
{
|
270
|
-
result = LocatedValue.new(location: val[0].location + val[2].location,
|
271
|
-
value: val[1])
|
272
|
-
}
|
273
|
-
|
274
|
-
simple_type: module_name tDOT kCLASS constructor
|
275
|
-
{
|
276
|
-
loc = val[0].location + (val[3] || val[2]).location
|
277
|
-
result = AST::Types::Name::Class.new(name: val[0].value,
|
278
|
-
constructor: val[3]&.value,
|
279
|
-
location: loc)
|
280
|
-
}
|
281
|
-
| module_name tDOT kMODULE
|
282
|
-
{
|
283
|
-
loc = val[0].location + val[2].location
|
284
|
-
result = AST::Types::Name::Module.new(name: val[0].value, location: loc)
|
285
|
-
}
|
286
|
-
| module_name application_args
|
287
|
-
{
|
288
|
-
loc = val[0].location + val[1]&.location
|
289
|
-
result = AST::Types::Name::Instance.new(name: val[0].value,
|
290
|
-
location: loc,
|
291
|
-
args: val[1]&.value || [])
|
292
|
-
}
|
293
|
-
| interface_name application_args
|
294
|
-
{
|
295
|
-
loc = val[0].location + val[1]&.location
|
296
|
-
result = AST::Types::Name::Interface.new(name: val[0].value,
|
297
|
-
location: loc,
|
298
|
-
args: val[1]&.value || [])
|
299
|
-
}
|
300
|
-
| alias_name application_args
|
301
|
-
{
|
302
|
-
loc = val[0].location + val[1]&.location
|
303
|
-
result = AST::Types::Name::Alias.new(name: val[0].value,
|
304
|
-
location: loc,
|
305
|
-
args: val[1]&.value || [])
|
306
|
-
}
|
307
|
-
| kANY
|
308
|
-
{
|
309
|
-
result = AST::Types::Any.new(location: val[0].location)
|
310
|
-
}
|
311
|
-
| tVAR
|
312
|
-
{
|
313
|
-
result = AST::Types::Var.new(location: val[0].location, name: val[0].value)
|
314
|
-
}
|
315
|
-
| kCLASS
|
316
|
-
{
|
317
|
-
result = AST::Types::Class.new(location: val[0].location)
|
318
|
-
}
|
319
|
-
| kMODULE
|
320
|
-
{
|
321
|
-
result = AST::Types::Class.new(location: val[0].location)
|
322
|
-
}
|
323
|
-
| kINSTANCE
|
324
|
-
{
|
325
|
-
result = AST::Types::Instance.new(location: val[0].location)
|
326
|
-
}
|
327
|
-
| kSELF
|
328
|
-
{
|
329
|
-
result = AST::Types::Self.new(location: val[0].location)
|
330
|
-
}
|
331
|
-
| kVOID
|
332
|
-
{
|
333
|
-
result = AST::Types::Void.new(location: val[0].location)
|
334
|
-
}
|
335
|
-
| kNIL
|
336
|
-
{
|
337
|
-
result = AST::Types::Nil.new(location: val[0].location)
|
338
|
-
}
|
339
|
-
| kBOOL
|
340
|
-
{
|
341
|
-
result = AST::Types::Boolean.new(location: val[0].location)
|
342
|
-
}
|
343
|
-
| simple_type tQUESTION
|
344
|
-
{
|
345
|
-
type = val[0]
|
346
|
-
nil_type = AST::Types::Nil.new(location: val[1].location)
|
347
|
-
result = AST::Types::Union.build(types: [type, nil_type], location: val[0].location + val[1].location)
|
348
|
-
}
|
349
|
-
| kSELFQ
|
350
|
-
{
|
351
|
-
type = AST::Types::Self.new(location: val[0].location)
|
352
|
-
nil_type = AST::Types::Nil.new(location: val[0].location)
|
353
|
-
result = AST::Types::Union.build(types: [type, nil_type], location: val[0].location)
|
354
|
-
}
|
355
|
-
| tINT
|
356
|
-
{
|
357
|
-
result = AST::Types::Literal.new(value: val[0].value, location: val[0].location)
|
358
|
-
}
|
359
|
-
| tSTRING
|
360
|
-
{
|
361
|
-
result = AST::Types::Literal.new(value: val[0].value, location: val[0].location)
|
362
|
-
}
|
363
|
-
| tSYMBOL
|
364
|
-
{
|
365
|
-
result = AST::Types::Literal.new(value: val[0].value, location: val[0].location)
|
366
|
-
}
|
367
|
-
| tLBRACKET type_seq tRBRACKET
|
368
|
-
{
|
369
|
-
loc = val[0].location + val[2].location
|
370
|
-
result = AST::Types::Tuple.new(types: val[1], location: loc)
|
371
|
-
}
|
372
|
-
|
373
|
-
hash_elements: # nothing
|
374
|
-
{
|
375
|
-
result = {}
|
376
|
-
}
|
377
|
-
| hash_element tCOMMA hash_elements
|
378
|
-
{
|
379
|
-
result = val[0].merge(val[2])
|
380
|
-
}
|
381
|
-
| hash_element
|
382
|
-
hash_element: tINT tROCKET type
|
383
|
-
{
|
384
|
-
result = { val[0].value => val[2] }
|
385
|
-
}
|
386
|
-
| tSTRING tROCKET type
|
387
|
-
{
|
388
|
-
result = { val[0].value => val[2] }
|
389
|
-
}
|
390
|
-
| tSYMBOL tROCKET type
|
391
|
-
{
|
392
|
-
result = { val[0].value => val[2] }
|
393
|
-
}
|
394
|
-
| keyword tCOLON type
|
395
|
-
{
|
396
|
-
result = { val[0].value => val[2] }
|
397
|
-
}
|
398
|
-
|
399
|
-
paren_type: tLPAREN type tRPAREN
|
400
|
-
{
|
401
|
-
result = val[1].with_location(val[0].location + val[2].location)
|
402
|
-
}
|
403
|
-
| tLBRACE hash_elements tRBRACE
|
404
|
-
{
|
405
|
-
location = val[0].location + val[2].location
|
406
|
-
result = AST::Types::Record.new(elements: val[1], location: location)
|
407
|
-
}
|
408
|
-
| simple_type
|
409
|
-
|
410
|
-
constructor: # nothing
|
411
|
-
{
|
412
|
-
result = nil
|
413
|
-
}
|
414
|
-
| kCONSTRUCTOR
|
415
|
-
{
|
416
|
-
result = LocatedValue.new(location: val[0].location, value: true)
|
417
|
-
}
|
418
|
-
| kNOCONSTRUCTOR
|
419
|
-
{
|
420
|
-
result = LocatedValue.new(location: val[0].location, value: false)
|
421
|
-
}
|
422
|
-
|
423
|
-
type: paren_type
|
424
|
-
| union_seq
|
425
|
-
{
|
426
|
-
loc = val[0].first.location + val[0].last.location
|
427
|
-
result = AST::Types::Union.build(types: val[0], location: loc)
|
428
|
-
}
|
429
|
-
| tHAT tLPAREN lambda_params tRPAREN tARROW paren_type
|
430
|
-
{
|
431
|
-
loc = val[0].location + val[5].location
|
432
|
-
result = AST::Types::Proc.new(params: val[2], return_type: val[5], location: loc)
|
433
|
-
}
|
434
|
-
|
435
|
-
lambda_params: lambda_params1
|
436
|
-
| paren_type
|
437
|
-
{
|
438
|
-
result = Interface::Params.empty.update(required: [val[0]])
|
439
|
-
}
|
440
|
-
| paren_type tCOMMA lambda_params
|
441
|
-
{
|
442
|
-
result = val[2].update(required: [val[0]] + val[2].required)
|
443
|
-
}
|
444
|
-
|
445
|
-
lambda_params1: # nothing
|
446
|
-
{
|
447
|
-
result = Interface::Params.empty
|
448
|
-
}
|
449
|
-
| tSTAR paren_type
|
450
|
-
{
|
451
|
-
result = Interface::Params.empty.update(rest: val[1])
|
452
|
-
}
|
453
|
-
| tQUESTION paren_type
|
454
|
-
{
|
455
|
-
result = Interface::Params.empty.update(optional: [val[1]])
|
456
|
-
}
|
457
|
-
| tQUESTION paren_type tCOMMA lambda_params1
|
458
|
-
{
|
459
|
-
result = val[3].update(optional: [val[1]] + val[3].optional)
|
460
|
-
}
|
461
|
-
|
462
|
-
|
463
|
-
type_seq: type
|
464
|
-
{
|
465
|
-
result = [val[0]]
|
466
|
-
}
|
467
|
-
| type tCOMMA type_seq
|
468
|
-
{
|
469
|
-
result = [val[0]] + val[2]
|
470
|
-
}
|
471
|
-
|
472
|
-
union_seq: simple_type tBAR simple_type
|
473
|
-
{
|
474
|
-
result = [val[0], val[2]]
|
475
|
-
}
|
476
|
-
| simple_type tBAR union_seq
|
477
|
-
{
|
478
|
-
result = [val[0]] + val[2]
|
479
|
-
}
|
480
|
-
|
481
|
-
keyword: tIDENT
|
482
|
-
| tINTERFACE_NAME
|
483
|
-
| kANY
|
484
|
-
| kCLASS
|
485
|
-
| kMODULE
|
486
|
-
| kINSTANCE
|
487
|
-
| kBLOCK
|
488
|
-
| kINCLUDE
|
489
|
-
| kIVAR
|
490
|
-
| kSELF
|
491
|
-
| kTYPE
|
492
|
-
|
493
|
-
signatures: # nothing
|
494
|
-
{
|
495
|
-
result = []
|
496
|
-
}
|
497
|
-
| interface signatures
|
498
|
-
{
|
499
|
-
result = [val[0]] + val[1]
|
500
|
-
}
|
501
|
-
| class_decl signatures
|
502
|
-
{
|
503
|
-
result = [val[0]] + val[1]
|
504
|
-
}
|
505
|
-
| module_decl signatures
|
506
|
-
{
|
507
|
-
result = [val[0]] + val[1]
|
508
|
-
}
|
509
|
-
| extension_decl signatures
|
510
|
-
{
|
511
|
-
result = [val[0]] + val[1]
|
512
|
-
}
|
513
|
-
| const_decl signatures
|
514
|
-
{
|
515
|
-
result = [val[0]] + val[1]
|
516
|
-
}
|
517
|
-
| gvar_decl signatures
|
518
|
-
{
|
519
|
-
result = [val[0]] + val[1]
|
520
|
-
}
|
521
|
-
| alias_decl signatures
|
522
|
-
{
|
523
|
-
result = [val[0]] + val[1]
|
524
|
-
}
|
525
|
-
|
526
|
-
gvar_decl: tGVAR tCOLON type
|
527
|
-
{
|
528
|
-
loc = val.first.location + val.last.location
|
529
|
-
result = AST::Signature::Gvar.new(
|
530
|
-
location: loc,
|
531
|
-
name: val[0].value,
|
532
|
-
type: val[2]
|
533
|
-
)
|
534
|
-
}
|
535
|
-
|
536
|
-
const_decl: module_name tCOLON type
|
537
|
-
{
|
538
|
-
loc = val.first.location + val.last.location
|
539
|
-
result = AST::Signature::Const.new(
|
540
|
-
location: loc,
|
541
|
-
name: val[0].value.absolute!,
|
542
|
-
type: val[2]
|
543
|
-
)
|
544
|
-
}
|
545
|
-
|
546
|
-
interface: kINTERFACE interface_name type_params interface_members kEND
|
547
|
-
{
|
548
|
-
loc = val.first.location + val.last.location
|
549
|
-
result = AST::Signature::Interface.new(
|
550
|
-
location: loc,
|
551
|
-
name: val[1].value.absolute!,
|
552
|
-
params: val[2],
|
553
|
-
methods: val[3]
|
554
|
-
)
|
555
|
-
}
|
556
|
-
|
557
|
-
class_decl: kCLASS module_name class_params_super class_members kEND
|
558
|
-
{
|
559
|
-
loc = val.first.location + val.last.location
|
560
|
-
result = AST::Signature::Class.new(name: val[1].value.absolute!,
|
561
|
-
params: val[2][0],
|
562
|
-
super_class: val[2][1],
|
563
|
-
members: val[3],
|
564
|
-
location: loc)
|
565
|
-
}
|
566
|
-
|
567
|
-
class_params_super: # nothing
|
568
|
-
{
|
569
|
-
result = [nil, nil]
|
570
|
-
}
|
571
|
-
| tLT super_class
|
572
|
-
{
|
573
|
-
result = [nil, val[1]]
|
574
|
-
}
|
575
|
-
| tLT type_param_seq tGT
|
576
|
-
{
|
577
|
-
location = val[0].location + val[2].location
|
578
|
-
params = AST::TypeParams.new(location: location, variables: val[1])
|
579
|
-
result = [params, nil]
|
580
|
-
}
|
581
|
-
| tLT type_param_seq tGT tLT super_class
|
582
|
-
{
|
583
|
-
location = val[0].location + val[2].location
|
584
|
-
params = AST::TypeParams.new(location: location, variables: val[1])
|
585
|
-
result = [params, val[4]]
|
586
|
-
}
|
587
|
-
|
588
|
-
module_decl: kMODULE module_name type_params self_type_opt class_members kEND
|
589
|
-
{
|
590
|
-
loc = val.first.location + val.last.location
|
591
|
-
result = AST::Signature::Module.new(name: val[1].value.absolute!,
|
592
|
-
location: loc,
|
593
|
-
params: val[2],
|
594
|
-
self_type: val[3],
|
595
|
-
members: val[4])
|
596
|
-
}
|
597
|
-
|
598
|
-
extension_decl: kEXTENSION module_name type_params tLPAREN tUIDENT tRPAREN class_members kEND
|
599
|
-
{
|
600
|
-
loc = val.first.location + val.last.location
|
601
|
-
result = AST::Signature::Extension.new(module_name: val[1].value.absolute!,
|
602
|
-
name: val[4].value,
|
603
|
-
location: loc,
|
604
|
-
params: val[2],
|
605
|
-
members: val[6])
|
606
|
-
}
|
607
|
-
|
608
|
-
alias_decl: kTYPE alias_name type_params tEQ type
|
609
|
-
{
|
610
|
-
loc = val[0].location + val[4].location
|
611
|
-
result = AST::Signature::Alias.new(location: loc,
|
612
|
-
name: val[1].value.absolute!,
|
613
|
-
params: val[2],
|
614
|
-
type: val[4])
|
615
|
-
}
|
616
|
-
|
617
|
-
self_type_opt: # nothing
|
618
|
-
{
|
619
|
-
result = nil
|
620
|
-
}
|
621
|
-
| tCOLON type
|
622
|
-
{
|
623
|
-
result = val[1]
|
624
|
-
}
|
625
|
-
|
626
|
-
interface_name: tQUALIFIED_INTERFACE_NAME
|
627
|
-
| tINTERFACE_NAME {
|
628
|
-
name = Names::Interface.new(name: val[0].value, namespace: AST::Namespace.empty)
|
629
|
-
result = LocatedValue.new(location: val[0].location, value: name)
|
630
|
-
}
|
631
|
-
|
632
|
-
module_name: tQUALIFIED_MODULE_NAME
|
633
|
-
| tUIDENT {
|
634
|
-
name = Names::Module.new(name: val[0].value, namespace: AST::Namespace.empty)
|
635
|
-
result = LocatedValue.new(location: val[0].location, value: name)
|
636
|
-
}
|
637
|
-
|
638
|
-
alias_name: tQUALIFIED_ALIAS_NAME
|
639
|
-
| tIDENT {
|
640
|
-
name = Names::Alias.new(name: val[0].value, namespace: AST::Namespace.empty)
|
641
|
-
result = LocatedValue.new(location: val[0].location, value: name)
|
642
|
-
}
|
643
|
-
|
644
|
-
class_members: # nothing
|
645
|
-
{
|
646
|
-
result = []
|
647
|
-
}
|
648
|
-
| class_member class_members
|
649
|
-
{
|
650
|
-
result = [val[0]] + val[1]
|
651
|
-
}
|
652
|
-
|
653
|
-
class_member: instance_method_member
|
654
|
-
| module_method_member
|
655
|
-
| module_instance_method_member
|
656
|
-
| include_member
|
657
|
-
| extend_member
|
658
|
-
| ivar_member
|
659
|
-
| attr_reader_member
|
660
|
-
| attr_accessor_member
|
661
|
-
| alias_member
|
662
|
-
|
663
|
-
ivar_member: tIVAR_NAME tCOLON type
|
664
|
-
{
|
665
|
-
loc = val.first.location + val.last.location
|
666
|
-
result = AST::Signature::Members::Ivar.new(
|
667
|
-
location: loc,
|
668
|
-
name: val[0].value,
|
669
|
-
type: val[2]
|
670
|
-
)
|
671
|
-
}
|
672
|
-
| kAT_TYPE tCOLON type
|
673
|
-
{
|
674
|
-
loc = val.first.location + val.last.location
|
675
|
-
result = AST::Signature::Members::Ivar.new(
|
676
|
-
location: loc,
|
677
|
-
name: :"@type",
|
678
|
-
type: val[2]
|
679
|
-
)
|
680
|
-
}
|
681
|
-
|
682
|
-
instance_method_member: kDEF method_annotations method_name tCOLON method_type_union
|
683
|
-
{
|
684
|
-
loc = val.first.location + val.last.last.location
|
685
|
-
result = AST::Signature::Members::Method.new(
|
686
|
-
name: val[2].value,
|
687
|
-
types: val[4],
|
688
|
-
kind: :instance,
|
689
|
-
location: loc,
|
690
|
-
attributes: val[1] || []
|
691
|
-
)
|
692
|
-
}
|
693
|
-
|
694
|
-
module_method_member: kDEF method_annotations kSELF tDOT method_name tCOLON method_type_union
|
695
|
-
{
|
696
|
-
loc = val.first.location + val.last.last.location
|
697
|
-
result = AST::Signature::Members::Method.new(
|
698
|
-
name: val[4].value,
|
699
|
-
types: val[6],
|
700
|
-
kind: :module,
|
701
|
-
location: loc,
|
702
|
-
attributes: val[1] || []
|
703
|
-
)
|
704
|
-
}
|
705
|
-
|
706
|
-
module_instance_method_member: kDEF method_annotations kSELFQ tDOT method_name tCOLON method_type_union
|
707
|
-
{
|
708
|
-
loc = val.first.location + val.last.last.location
|
709
|
-
result = AST::Signature::Members::Method.new(
|
710
|
-
name: val[4].value,
|
711
|
-
types: val[6],
|
712
|
-
kind: :module_instance,
|
713
|
-
location: loc,
|
714
|
-
attributes: val[1] || []
|
715
|
-
)
|
716
|
-
}
|
717
|
-
|
718
|
-
include_member: kINCLUDE module_name
|
719
|
-
{
|
720
|
-
loc = val[0].location + val[1].location
|
721
|
-
name = val[1].value
|
722
|
-
result = AST::Signature::Members::Include.new(name: name, location: loc, args: [])
|
723
|
-
}
|
724
|
-
| kINCLUDE module_name tLT type_seq tGT
|
725
|
-
{
|
726
|
-
loc = val[0].location + val[4].location
|
727
|
-
name = val[1].value
|
728
|
-
result = AST::Signature::Members::Include.new(name: name, location: loc, args: val[3])
|
729
|
-
}
|
730
|
-
|
731
|
-
extend_member: kEXTEND module_name
|
732
|
-
{
|
733
|
-
loc = val[0].location + val[1].location
|
734
|
-
name = val[1].value
|
735
|
-
result = AST::Signature::Members::Extend.new(name: name, location: loc, args: [])
|
736
|
-
}
|
737
|
-
| kEXTEND module_name tLT type_seq tGT
|
738
|
-
{
|
739
|
-
loc = val[0].location + val[4].location
|
740
|
-
name = val[1].value
|
741
|
-
result = AST::Signature::Members::Extend.new(name: name, location: loc, args: val[3])
|
742
|
-
}
|
743
|
-
|
744
|
-
attr_reader_member: kATTR_READER method_name attr_ivar_opt tCOLON type
|
745
|
-
{
|
746
|
-
loc = val.first.location + val.last.location
|
747
|
-
result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :reader, ivar: val[2], type: val[4])
|
748
|
-
}
|
749
|
-
|
750
|
-
attr_accessor_member: kATTR_ACCESSOR method_name attr_ivar_opt tCOLON type
|
751
|
-
{
|
752
|
-
loc = val.first.location + val.last.location
|
753
|
-
result = AST::Signature::Members::Attr.new(location: loc, name: val[1].value, kind: :accessor, ivar: val[2], type: val[4])
|
754
|
-
}
|
755
|
-
|
756
|
-
alias_member: kALIAS method_name method_name {
|
757
|
-
loc = val[0].location + val[2].location
|
758
|
-
result = AST::Signature::Members::MethodAlias.new(
|
759
|
-
location: loc,
|
760
|
-
new_name: val[1].value,
|
761
|
-
original_name: val[2].value
|
762
|
-
)
|
763
|
-
}
|
764
|
-
|
765
|
-
attr_ivar_opt: # nothing
|
766
|
-
{
|
767
|
-
result = nil
|
768
|
-
}
|
769
|
-
| tLPAREN tRPAREN
|
770
|
-
{
|
771
|
-
result = false
|
772
|
-
}
|
773
|
-
| tLPAREN tIVAR_NAME tRPAREN
|
774
|
-
{
|
775
|
-
result = val[1].value
|
776
|
-
}
|
777
|
-
|
778
|
-
method_annotations: # nothing
|
779
|
-
{
|
780
|
-
result = nil
|
781
|
-
}
|
782
|
-
| tLPAREN method_annotation_seq tRPAREN
|
783
|
-
{
|
784
|
-
result = val[1]
|
785
|
-
}
|
786
|
-
|
787
|
-
method_annotation_seq: method_annotation_keyword
|
788
|
-
{
|
789
|
-
result = [val[0]]
|
790
|
-
}
|
791
|
-
| method_annotation_keyword tCOMMA method_annotation_seq
|
792
|
-
{
|
793
|
-
result = [val[0]] + val[2]
|
794
|
-
}
|
795
|
-
|
796
|
-
method_annotation_keyword: kCONSTRUCTOR
|
797
|
-
{
|
798
|
-
result = val[0].value
|
799
|
-
}
|
800
|
-
| kINCOMPATIBLE
|
801
|
-
{
|
802
|
-
result = val[0].value
|
803
|
-
}
|
804
|
-
| kPRIVATE
|
805
|
-
{
|
806
|
-
result = val[0].value
|
807
|
-
}
|
808
|
-
|
809
|
-
super_class: module_name
|
810
|
-
{
|
811
|
-
result = AST::Signature::SuperClass.new(location: val[0].location, name: val[0].value, args: [])
|
812
|
-
}
|
813
|
-
| module_name tLT type_seq tGT
|
814
|
-
{
|
815
|
-
loc = val[0].location + val[3].location
|
816
|
-
name = val[0].value
|
817
|
-
result = AST::Signature::SuperClass.new(location: loc, name: name, args: val[2])
|
818
|
-
}
|
819
|
-
|
820
|
-
type_params: # nothing
|
821
|
-
{
|
822
|
-
result = nil
|
823
|
-
}
|
824
|
-
| tLT type_param_seq tGT
|
825
|
-
{
|
826
|
-
location = val[0].location + val[2].location
|
827
|
-
result = AST::TypeParams.new(location: location, variables: val[1])
|
828
|
-
}
|
829
|
-
|
830
|
-
type_param_seq: tVAR
|
831
|
-
{
|
832
|
-
result = [val[0].value]
|
833
|
-
}
|
834
|
-
| tVAR tCOMMA type_param_seq
|
835
|
-
{
|
836
|
-
result = [val[0].value] + val[2]
|
837
|
-
}
|
838
|
-
|
839
|
-
interface_members: # nothing
|
840
|
-
{
|
841
|
-
result = []
|
842
|
-
}
|
843
|
-
| interface_method interface_members
|
844
|
-
{
|
845
|
-
result = val[1].unshift(val[0])
|
846
|
-
}
|
847
|
-
|
848
|
-
interface_method: kDEF method_name tCOLON method_type_union
|
849
|
-
{
|
850
|
-
loc = val[0].location + val[3].last.location
|
851
|
-
result = AST::Signature::Interface::Method.new(location: loc, name: val[1].value, types: val[3])
|
852
|
-
}
|
853
|
-
|
854
|
-
method_type_union: method_type
|
855
|
-
{
|
856
|
-
result = [val[0]]
|
857
|
-
}
|
858
|
-
| kSUPER
|
859
|
-
{
|
860
|
-
result = [AST::MethodType::Super.new(location: val[0].location)]
|
861
|
-
}
|
862
|
-
| method_type tBAR method_type_union
|
863
|
-
{
|
864
|
-
result = [val[0]] + val[2]
|
865
|
-
}
|
866
|
-
|
867
|
-
method_name: method_name0
|
868
|
-
| tSTAR
|
869
|
-
| tSTAR2
|
870
|
-
| tPERCENT
|
871
|
-
| tMINUS
|
872
|
-
| tLT
|
873
|
-
| tGT
|
874
|
-
| tUMINUS
|
875
|
-
| tBAR
|
876
|
-
{
|
877
|
-
result = LocatedValue.new(location: val[0].location, value: :|)
|
878
|
-
}
|
879
|
-
| method_name0 tEQ
|
880
|
-
{
|
881
|
-
raise ParseError, "\nunexpected method name #{val[0].to_s} =" unless val[0].location.pred?(val[1].location)
|
882
|
-
result = LocatedValue.new(location: val[0].location + val[1].location,
|
883
|
-
value: :"#{val[0].value}=")
|
884
|
-
}
|
885
|
-
| method_name0 tQUESTION
|
886
|
-
{
|
887
|
-
raise ParseError, "\nunexpected method name #{val[0].to_s} ?" unless val[0].location.pred?(val[1].location)
|
888
|
-
result = LocatedValue.new(location: val[0].location + val[1].location,
|
889
|
-
value: :"#{val[0].value}?")
|
890
|
-
}
|
891
|
-
| method_name0 tBANG
|
892
|
-
{
|
893
|
-
raise ParseError, "\nunexpected method name #{val[0].to_s} !" unless val[0].location.pred?(val[1].location)
|
894
|
-
result = LocatedValue.new(location: val[0].location + val[1].location,
|
895
|
-
value: :"#{val[0].value}!")
|
896
|
-
}
|
897
|
-
| tGT tGT
|
898
|
-
{
|
899
|
-
raise ParseError, "\nunexpected method name > >" unless val[0].location.pred?(val[1].location)
|
900
|
-
result = LocatedValue.new(location: val[0].location + val[1].location, value: :>>)
|
901
|
-
}
|
902
|
-
| kNIL tQUESTION
|
903
|
-
{
|
904
|
-
raise ParseError, "\nunexpected method name #{val[0].to_s} ?" unless val[0].location.pred?(val[1].location)
|
905
|
-
result = LocatedValue.new(location: val[0].location + val[1].location,
|
906
|
-
value: :"nil?")
|
907
|
-
}
|
908
|
-
|
909
|
-
method_name0: tIDENT
|
910
|
-
| tUIDENT
|
911
|
-
| tINTERFACE_NAME
|
912
|
-
| kANY
|
913
|
-
| kVOID
|
914
|
-
| kINTERFACE
|
915
|
-
| kEND
|
916
|
-
| tPLUS
|
917
|
-
| kCLASS
|
918
|
-
| kMODULE
|
919
|
-
| kINSTANCE
|
920
|
-
| kEXTEND
|
921
|
-
| kINCLUDE
|
922
|
-
| tOPERATOR
|
923
|
-
| tHAT
|
924
|
-
| tBANG
|
925
|
-
| kBLOCK
|
926
|
-
| kBREAK
|
927
|
-
| kMETHOD
|
928
|
-
| kBOOL
|
929
|
-
| kTYPE
|
930
|
-
| kALIAS
|
931
|
-
| kCONSTRUCTOR
|
932
|
-
{
|
933
|
-
result = LocatedValue.new(location: val[0].location, value: :constructor)
|
934
|
-
}
|
935
|
-
| kNOCONSTRUCTOR
|
936
|
-
{
|
937
|
-
result = LocatedValue.new(location: val[0].location, value: :noconstructor)
|
938
|
-
}
|
939
|
-
| kATTR_READER
|
940
|
-
| kATTR_ACCESSOR
|
941
|
-
| kINCOMPATIBLE
|
942
|
-
| kPRIVATE
|
943
|
-
|
944
|
-
annotation: kAT_TYPE kVAR subject tCOLON type
|
945
|
-
{
|
946
|
-
loc = val.first.location + val.last.location
|
947
|
-
result = AST::Annotation::VarType.new(location: loc,
|
948
|
-
name: val[2].value,
|
949
|
-
type: val[4])
|
950
|
-
}
|
951
|
-
| kAT_TYPE kMETHOD method_name tCOLON method_type
|
952
|
-
{
|
953
|
-
loc = val.first.location + val.last.location
|
954
|
-
result = AST::Annotation::MethodType.new(location: loc,
|
955
|
-
name: val[2].value,
|
956
|
-
type: val[4])
|
957
|
-
}
|
958
|
-
| kAT_TYPE kRETURN tCOLON type
|
959
|
-
{
|
960
|
-
loc = val.first.location + val.last.location
|
961
|
-
result = AST::Annotation::ReturnType.new(type: val[3], location: loc)
|
962
|
-
}
|
963
|
-
| kAT_TYPE kBLOCK tCOLON type
|
964
|
-
{
|
965
|
-
loc = val.first.location + val.last.location
|
966
|
-
result = AST::Annotation::BlockType.new(type: val[3], location: loc)
|
967
|
-
}
|
968
|
-
| kAT_TYPE kSELF tCOLON type
|
969
|
-
{
|
970
|
-
loc = val.first.location + val.last.location
|
971
|
-
result = AST::Annotation::SelfType.new(type: val[3], location: loc)
|
972
|
-
}
|
973
|
-
| kAT_TYPE kCONST module_name tCOLON type
|
974
|
-
{
|
975
|
-
loc = val[0].location + val[4].location
|
976
|
-
result = AST::Annotation::ConstType.new(name: val[2].value,
|
977
|
-
type: val[4],
|
978
|
-
location: loc)
|
979
|
-
}
|
980
|
-
| kAT_TYPE kINSTANCE tCOLON type
|
981
|
-
{
|
982
|
-
loc = val.first.location + val.last.location
|
983
|
-
result = AST::Annotation::InstanceType.new(type: val[3], location: loc)
|
984
|
-
}
|
985
|
-
| kAT_TYPE kMODULE tCOLON type
|
986
|
-
{
|
987
|
-
loc = val.first.location + val.last.location
|
988
|
-
result = AST::Annotation::ModuleType.new(type: val[3], location: loc)
|
989
|
-
}
|
990
|
-
| kAT_TYPE kIVAR tIVAR_NAME tCOLON type
|
991
|
-
{
|
992
|
-
loc = val.first.location + val.last.location
|
993
|
-
result = AST::Annotation::IvarType.new(name: val[2].value, type: val[4], location: loc)
|
994
|
-
}
|
995
|
-
| kAT_IMPLEMENTS module_name type_params
|
996
|
-
{
|
997
|
-
loc = val[0].location + (val[2]&.location || val[1].location)
|
998
|
-
args = val[2]&.variables || []
|
999
|
-
name = AST::Annotation::Implements::Module.new(name: val[1].value, args: args)
|
1000
|
-
result = AST::Annotation::Implements.new(name: name, location: loc)
|
1001
|
-
}
|
1002
|
-
| kAT_DYNAMIC dynamic_names
|
1003
|
-
{
|
1004
|
-
loc = val[0].location + val[1].last.location
|
1005
|
-
result = AST::Annotation::Dynamic.new(names: val[1], location: loc)
|
1006
|
-
}
|
1007
|
-
| kAT_TYPE kBREAK tCOLON type
|
1008
|
-
{
|
1009
|
-
loc = val.first.location + val.last.location
|
1010
|
-
result = AST::Annotation::BreakType.new(type: val[3], location: loc)
|
1011
|
-
}
|
1012
|
-
|
1013
|
-
dynamic_names: dynamic_name tCOMMA dynamic_names
|
1014
|
-
{
|
1015
|
-
result = [val[0]] + val[2]
|
1016
|
-
}
|
1017
|
-
| dynamic_name
|
1018
|
-
{
|
1019
|
-
result = val
|
1020
|
-
}
|
1021
|
-
|
1022
|
-
dynamic_name: method_name
|
1023
|
-
{
|
1024
|
-
result = AST::Annotation::Dynamic::Name.new(name: val[0].value, location: val[0].location, kind: :instance)
|
1025
|
-
}
|
1026
|
-
| kSELF tDOT method_name
|
1027
|
-
{
|
1028
|
-
loc = val.first.location + val.last.location
|
1029
|
-
result = AST::Annotation::Dynamic::Name.new(name: val[2].value, location: loc, kind: :module)
|
1030
|
-
}
|
1031
|
-
| kSELFQ tDOT method_name
|
1032
|
-
{
|
1033
|
-
loc = val.first.location + val.last.location
|
1034
|
-
result = AST::Annotation::Dynamic::Name.new(name: val[2].value, location: loc, kind: :module_instance)
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
subject: tIDENT
|
1038
|
-
{
|
1039
|
-
result = val[0]
|
1040
|
-
}
|
1041
|
-
end
|
1042
|
-
|
1043
|
-
---- inner
|
1044
|
-
|
1045
|
-
require "strscan"
|
1046
|
-
|
1047
|
-
attr_reader :input
|
1048
|
-
attr_reader :buffer
|
1049
|
-
attr_reader :offset
|
1050
|
-
|
1051
|
-
def initialize(type, buffer:, offset:, input: nil)
|
1052
|
-
super()
|
1053
|
-
@type = type
|
1054
|
-
@buffer = buffer
|
1055
|
-
@input = StringScanner.new(input || buffer.content)
|
1056
|
-
@offset = offset
|
1057
|
-
end
|
1058
|
-
|
1059
|
-
def self.parse_method(input, name: nil)
|
1060
|
-
new(:METHOD, buffer: AST::Buffer.new(name: name, content: input), offset: 0).do_parse
|
1061
|
-
end
|
1062
|
-
|
1063
|
-
def self.parse_signature(input, name: nil)
|
1064
|
-
new(:SIGNATURE, buffer: AST::Buffer.new(name: name, content: input), offset: 0).do_parse
|
1065
|
-
end
|
1066
|
-
|
1067
|
-
def self.parse_annotation_opt(input, buffer:, offset: 0)
|
1068
|
-
new(:ANNOTATION, input: input, buffer: buffer, offset: offset).do_parse
|
1069
|
-
rescue => exn
|
1070
|
-
Steep.logger.debug "Parsing comment failed: #{exn.inspect}"
|
1071
|
-
nil
|
1072
|
-
end
|
1073
|
-
|
1074
|
-
def self.parse_type(input, name: nil)
|
1075
|
-
new(:TYPE, buffer: AST::Buffer.new(name: name, content: input), offset: 0).do_parse
|
1076
|
-
end
|
1077
|
-
|
1078
|
-
class LocatedValue
|
1079
|
-
attr_reader :location
|
1080
|
-
attr_reader :value
|
1081
|
-
|
1082
|
-
def initialize(location:, value:)
|
1083
|
-
@location = location
|
1084
|
-
@value = value
|
1085
|
-
end
|
1086
|
-
end
|
1087
|
-
|
1088
|
-
def new_token(type, value = nil)
|
1089
|
-
start_index = offset + input.pos - input.matched.bytesize
|
1090
|
-
end_index = offset + input.pos
|
1091
|
-
|
1092
|
-
location = AST::Location.new(buffer: buffer,
|
1093
|
-
start_pos: start_index,
|
1094
|
-
end_pos: end_index)
|
1095
|
-
|
1096
|
-
[type, LocatedValue.new(location: location, value: value)]
|
1097
|
-
end
|
1098
|
-
|
1099
|
-
def next_token
|
1100
|
-
if @type
|
1101
|
-
type = @type
|
1102
|
-
@type = nil
|
1103
|
-
return [:"type_#{type}", nil]
|
1104
|
-
end
|
1105
|
-
|
1106
|
-
case
|
1107
|
-
when input.scan(/\s+/)
|
1108
|
-
next_token
|
1109
|
-
when input.scan(/#.*/)
|
1110
|
-
next_token
|
1111
|
-
when input.eos?
|
1112
|
-
[false, false]
|
1113
|
-
when input.scan(/->/)
|
1114
|
-
new_token(:tARROW)
|
1115
|
-
when input.scan(/\?/)
|
1116
|
-
new_token(:tQUESTION)
|
1117
|
-
when input.scan(/!/)
|
1118
|
-
new_token(:tBANG, :!)
|
1119
|
-
when input.scan(/\(/)
|
1120
|
-
new_token(:tLPAREN, nil)
|
1121
|
-
when input.scan(/\)/)
|
1122
|
-
new_token(:tRPAREN, nil)
|
1123
|
-
when input.scan(/{/)
|
1124
|
-
new_token(:tLBRACE, nil)
|
1125
|
-
when input.scan(/}/)
|
1126
|
-
new_token(:tRBRACE, nil)
|
1127
|
-
when input.scan(/,/)
|
1128
|
-
new_token(:tCOMMA, nil)
|
1129
|
-
when input.scan(/:\w+/)
|
1130
|
-
new_token(:tSYMBOL, input.matched[1..-1].to_sym)
|
1131
|
-
when input.scan(/\*\*/)
|
1132
|
-
new_token(:tSTAR2, :**)
|
1133
|
-
when input.scan(/\*/)
|
1134
|
-
new_token(:tSTAR, :*)
|
1135
|
-
when input.scan(/\+/)
|
1136
|
-
new_token(:tPLUS, :+)
|
1137
|
-
when input.scan(/\./)
|
1138
|
-
new_token(:tDOT)
|
1139
|
-
when input.scan(/<:(?!:)/)
|
1140
|
-
loc = new_token("<:")[1].location
|
1141
|
-
Steep.logger.warn("`<:` syntax for super class is deprecated. Use `<` instead. (#{loc.buffer.name}:#{loc})")
|
1142
|
-
new_token(:tLT)
|
1143
|
-
when input.scan(/\^/)
|
1144
|
-
new_token(:tHAT, :"^")
|
1145
|
-
when input.scan(/=>/)
|
1146
|
-
new_token(:tROCKET, :"=>")
|
1147
|
-
when input.scan(/(\[\]=)|(\[\])|===|==|!=|<<|=~/)
|
1148
|
-
new_token(:tOPERATOR, input.matched.to_sym)
|
1149
|
-
when input.scan(/\[/)
|
1150
|
-
new_token(:tLBRACKET, nil)
|
1151
|
-
when input.scan(/\]/)
|
1152
|
-
new_token(:tRBRACKET, nil)
|
1153
|
-
when input.scan(/<=/)
|
1154
|
-
new_token(:tOPERATOR, :<=)
|
1155
|
-
when input.scan(/>=/)
|
1156
|
-
new_token(:tOPERATOR, :>=)
|
1157
|
-
when input.scan(/=/)
|
1158
|
-
new_token(:tEQ, :"=")
|
1159
|
-
when input.scan(/</)
|
1160
|
-
new_token(:tLT, :<)
|
1161
|
-
when input.scan(/>/)
|
1162
|
-
new_token(:tGT, :>)
|
1163
|
-
when input.scan(/nil\b/)
|
1164
|
-
new_token(:kNIL, :nil)
|
1165
|
-
when input.scan(/bool\b/)
|
1166
|
-
new_token(:kBOOL, :bool)
|
1167
|
-
when input.scan(/any\b/)
|
1168
|
-
new_token(:kANY, :any)
|
1169
|
-
when input.scan(/void\b/)
|
1170
|
-
new_token(:kVOID, :void)
|
1171
|
-
when input.scan(/type\b/)
|
1172
|
-
new_token(:kTYPE, :type)
|
1173
|
-
when input.scan(/interface\b/)
|
1174
|
-
new_token(:kINTERFACE, :interface)
|
1175
|
-
when input.scan(/incompatible\b/)
|
1176
|
-
new_token(:kINCOMPATIBLE, :incompatible)
|
1177
|
-
when input.scan(/end\b/)
|
1178
|
-
new_token(:kEND, :end)
|
1179
|
-
when input.scan(/\|/)
|
1180
|
-
new_token(:tBAR, :bar)
|
1181
|
-
when input.scan(/-@/)
|
1182
|
-
new_token(:tUMINUS, :"-@")
|
1183
|
-
when input.scan(/def\b/)
|
1184
|
-
new_token(:kDEF)
|
1185
|
-
when input.scan(/@type\b/)
|
1186
|
-
new_token(:kAT_TYPE)
|
1187
|
-
when input.scan(/@implements\b/)
|
1188
|
-
new_token(:kAT_IMPLEMENTS)
|
1189
|
-
when input.scan(/@dynamic\b/)
|
1190
|
-
new_token(:kAT_DYNAMIC)
|
1191
|
-
when input.scan(/const\b/)
|
1192
|
-
new_token(:kCONST, :const)
|
1193
|
-
when input.scan(/var\b/)
|
1194
|
-
new_token(:kVAR, :var)
|
1195
|
-
when input.scan(/return\b/)
|
1196
|
-
new_token(:kRETURN)
|
1197
|
-
when input.scan(/block\b/)
|
1198
|
-
new_token(:kBLOCK, :block)
|
1199
|
-
when input.scan(/break\b/)
|
1200
|
-
new_token(:kBREAK, :break)
|
1201
|
-
when input.scan(/method\b/)
|
1202
|
-
new_token(:kMETHOD, :method)
|
1203
|
-
when input.scan(/self\?/)
|
1204
|
-
new_token(:kSELFQ)
|
1205
|
-
when input.scan(/self\b/)
|
1206
|
-
new_token(:kSELF, :self)
|
1207
|
-
when input.scan(/'\w+/)
|
1208
|
-
new_token(:tVAR, input.matched.gsub(/\A'/, '').to_sym)
|
1209
|
-
when input.scan(/attr_reader\b/)
|
1210
|
-
new_token(:kATTR_READER, :attr_reader)
|
1211
|
-
when input.scan(/attr_accessor\b/)
|
1212
|
-
new_token(:kATTR_ACCESSOR, :attr_accessor)
|
1213
|
-
when input.scan(/instance\b/)
|
1214
|
-
new_token(:kINSTANCE, :instance)
|
1215
|
-
when input.scan(/class\b/)
|
1216
|
-
new_token(:kCLASS, :class)
|
1217
|
-
when input.scan(/module\b/)
|
1218
|
-
new_token(:kMODULE, :module)
|
1219
|
-
when input.scan(/include\b/)
|
1220
|
-
new_token(:kINCLUDE, :include)
|
1221
|
-
when input.scan(/extend\b/)
|
1222
|
-
new_token(:kEXTEND, :extend)
|
1223
|
-
when input.scan(/instance\b/)
|
1224
|
-
new_token(:kINSTANCE, :instance)
|
1225
|
-
when input.scan(/ivar\b/)
|
1226
|
-
new_token(:kIVAR, :ivar)
|
1227
|
-
when input.scan(/private\b/)
|
1228
|
-
new_token(:kPRIVATE, :private)
|
1229
|
-
when input.scan(/alias\b/)
|
1230
|
-
new_token(:kALIAS, :alias)
|
1231
|
-
when input.scan(/super\b/)
|
1232
|
-
new_token(:kSUPER, :super)
|
1233
|
-
when input.scan(/%/)
|
1234
|
-
new_token(:tPERCENT, :%)
|
1235
|
-
when input.scan(/-/)
|
1236
|
-
new_token(:tMINUS, :-)
|
1237
|
-
when input.scan(/&/)
|
1238
|
-
new_token(:tOPERATOR, :&)
|
1239
|
-
when input.scan(/~/)
|
1240
|
-
new_token(:tOPERATOR, :~)
|
1241
|
-
when input.scan(/\//)
|
1242
|
-
new_token(:tOPERATOR, :/)
|
1243
|
-
when input.scan(/extension\b/)
|
1244
|
-
new_token(:kEXTENSION, :extension)
|
1245
|
-
when input.scan(/constructor\b/)
|
1246
|
-
new_token(:kCONSTRUCTOR, :constructor)
|
1247
|
-
when input.scan(/noconstructor\b/)
|
1248
|
-
new_token(:kNOCONSTRUCTOR, :noconstructor)
|
1249
|
-
when input.scan(/\$\w+\b/)
|
1250
|
-
new_token(:tGVAR, input.matched.to_sym)
|
1251
|
-
when input.scan(/::([A-Z]\w*::)*_\w+/)
|
1252
|
-
new_token(:tQUALIFIED_INTERFACE_NAME, Names::Interface.parse(input.matched))
|
1253
|
-
when input.scan(/([A-Z]\w*::)+_\w+/)
|
1254
|
-
new_token(:tQUALIFIED_INTERFACE_NAME, Names::Interface.parse(input.matched))
|
1255
|
-
when input.scan(/::([A-Z]\w*::)*[a-z]\w*/)
|
1256
|
-
new_token(:tQUALIFIED_ALIAS_NAME, Names::Alias.parse(input.matched))
|
1257
|
-
when input.scan(/([A-Z]\w*::)+[a-z]\w*/)
|
1258
|
-
new_token(:tQUALIFIED_ALIAS_NAME, Names::Alias.parse(input.matched))
|
1259
|
-
when input.scan(/::([A-Z]\w*::)*[A-Z]\w*/)
|
1260
|
-
new_token(:tQUALIFIED_MODULE_NAME, Names::Module.parse(input.matched))
|
1261
|
-
when input.scan(/([A-Z]\w*::)+[A-Z]\w*/)
|
1262
|
-
new_token(:tQUALIFIED_MODULE_NAME, Names::Module.parse(input.matched))
|
1263
|
-
when input.scan(/[A-Z]\w*/)
|
1264
|
-
new_token(:tUIDENT, input.matched.to_sym)
|
1265
|
-
when input.scan(/_\w+/)
|
1266
|
-
new_token(:tINTERFACE_NAME, input.matched.to_sym)
|
1267
|
-
when input.scan(/@\w+/)
|
1268
|
-
new_token(:tIVAR_NAME, input.matched.to_sym)
|
1269
|
-
when input.scan(/\d+/)
|
1270
|
-
new_token(:tINT, input.matched.to_i)
|
1271
|
-
when input.scan(/\"[^\"]*\"/)
|
1272
|
-
new_token(:tSTRING, input.matched[1...-1])
|
1273
|
-
when input.scan(/[a-z]\w*/)
|
1274
|
-
new_token(:tIDENT, input.matched.to_sym)
|
1275
|
-
when input.scan(/:/)
|
1276
|
-
new_token(:tCOLON)
|
1277
|
-
end
|
1278
|
-
end
|