rbs 1.1.0 → 1.3.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -1
- data/.gitignore +2 -0
- data/CHANGELOG.md +81 -0
- data/README.md +1 -1
- data/Rakefile +11 -0
- data/Steepfile +1 -0
- data/core/array.rbs +2 -2
- data/core/basic_object.rbs +1 -1
- data/core/enumerable.rbs +1 -1
- data/core/hash.rbs +13 -5
- data/core/io.rbs +4 -4
- data/core/kernel.rbs +2 -2
- data/core/marshal.rbs +4 -3
- data/core/module.rbs +1 -1
- data/core/numeric.rbs +10 -0
- data/core/proc.rbs +1 -1
- data/core/random.rbs +4 -2
- data/core/range.rbs +2 -2
- data/core/struct.rbs +3 -2
- data/core/thread.rbs +1 -1
- data/docs/CONTRIBUTING.md +5 -3
- data/docs/rbs_by_example.md +328 -0
- data/docs/sigs.md +21 -2
- data/docs/stdlib.md +1 -1
- data/docs/syntax.md +11 -14
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/annotation.rb +2 -2
- data/lib/rbs/ast/comment.rb +2 -2
- data/lib/rbs/ast/declarations.rb +37 -22
- data/lib/rbs/ast/members.rb +26 -26
- data/lib/rbs/cli.rb +3 -0
- data/lib/rbs/constant_table.rb +4 -1
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder.rb +16 -18
- data/lib/rbs/definition_builder/ancestor_builder.rb +10 -2
- data/lib/rbs/definition_builder/method_builder.rb +4 -2
- data/lib/rbs/errors.rb +36 -0
- data/lib/rbs/location.rb +106 -2
- data/lib/rbs/locator.rb +205 -0
- data/lib/rbs/method_type.rb +2 -2
- data/lib/rbs/parser.rb +1315 -962
- data/lib/rbs/parser.y +411 -75
- data/lib/rbs/prototype/rb.rb +7 -3
- data/lib/rbs/prototype/runtime.rb +118 -42
- data/lib/rbs/test/hook.rb +8 -2
- data/lib/rbs/type_name.rb +2 -3
- data/lib/rbs/type_name_resolver.rb +1 -1
- data/lib/rbs/types.rb +36 -34
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +4 -2
- data/rbs.gemspec +1 -1
- data/sig/ancestor_builder.rbs +2 -0
- data/sig/annotation.rbs +1 -1
- data/sig/cli.rbs +31 -21
- data/sig/comment.rbs +1 -1
- data/sig/declarations.rbs +106 -21
- data/sig/environment.rbs +2 -2
- data/sig/errors.rbs +15 -0
- data/sig/location.rbs +84 -3
- data/sig/locator.rbs +44 -0
- data/sig/members.rbs +76 -12
- data/sig/method_builder.rbs +1 -1
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +1 -1
- data/sig/polyfill.rbs +4 -17
- data/sig/rbs.rbs +8 -4
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +67 -20
- data/sig/util.rbs +0 -4
- data/sig/writer.rbs +8 -2
- data/stdlib/dbm/0/dbm.rbs +43 -30
- data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
- data/stdlib/net-http/0/net-http.rbs +1846 -0
- data/stdlib/optparse/0/optparse.rbs +1214 -0
- data/stdlib/resolv/0/resolv.rbs +1504 -0
- data/stdlib/rubygems/0/requirement.rbs +84 -2
- data/stdlib/rubygems/0/rubygems.rbs +2 -2
- data/stdlib/rubygems/0/version.rbs +2 -1
- data/stdlib/shellwords/0/shellwords.rbs +252 -0
- data/stdlib/socket/0/addrinfo.rbs +469 -0
- data/stdlib/socket/0/basic_socket.rbs +503 -0
- data/stdlib/socket/0/ip_socket.rbs +72 -0
- data/stdlib/socket/0/socket.rbs +2687 -0
- data/stdlib/socket/0/tcp_server.rbs +177 -0
- data/stdlib/socket/0/tcp_socket.rbs +35 -0
- data/stdlib/socket/0/udp_socket.rbs +111 -0
- data/stdlib/socket/0/unix_server.rbs +154 -0
- data/stdlib/socket/0/unix_socket.rbs +132 -0
- data/stdlib/timeout/0/timeout.rbs +5 -0
- data/steep/Gemfile.lock +19 -16
- metadata +18 -11
- data/bin/annotate-with-rdoc +0 -153
- data/bin/console +0 -14
- data/bin/query-rdoc +0 -103
- data/bin/rbs-prof +0 -9
- data/bin/run_in_md.rb +0 -49
- data/bin/setup +0 -8
- data/bin/sort +0 -89
- data/bin/steep +0 -4
- data/bin/test_runner.rb +0 -29
data/lib/rbs/version.rb
CHANGED
data/lib/rbs/writer.rb
CHANGED
data/rbs.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
# Specify which files should be added to the gem when it is released.
|
29
29
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
30
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|bin)/}) }
|
32
32
|
end
|
33
33
|
spec.files << "lib/rbs/parser.rb"
|
34
34
|
spec.bindir = "exe"
|
data/sig/ancestor_builder.rbs
CHANGED
@@ -80,6 +80,7 @@ module RBS
|
|
80
80
|
def interface_ancestors: (TypeName, ?building_ancestors: Array[Definition::Ancestor::t]) -> Definition::InstanceAncestors
|
81
81
|
|
82
82
|
def mixin_ancestors: (Environment::ClassEntry | Environment::ModuleEntry,
|
83
|
+
TypeName,
|
83
84
|
included_modules: Array[Definition::Ancestor::Instance]?,
|
84
85
|
included_interfaces:Array[Definition::Ancestor::Instance]?,
|
85
86
|
prepended_modules: Array[Definition::Ancestor::Instance]?,
|
@@ -87,6 +88,7 @@ module RBS
|
|
87
88
|
extended_interfaces: Array[Definition::Ancestor::Instance]?) -> void
|
88
89
|
|
89
90
|
def mixin_ancestors0: (AST::Declarations::Class | AST::Declarations::Module | AST::Declarations::Interface,
|
91
|
+
TypeName,
|
90
92
|
align_params: Substitution?,
|
91
93
|
included_modules: Array[Definition::Ancestor::Instance]?,
|
92
94
|
included_interfaces:Array[Definition::Ancestor::Instance]?,
|
data/sig/annotation.rbs
CHANGED
data/sig/cli.rbs
CHANGED
@@ -8,51 +8,61 @@ module RBS
|
|
8
8
|
attr_reader repos: Array[String]
|
9
9
|
|
10
10
|
def initialize: () -> void
|
11
|
-
|
11
|
+
|
12
12
|
def loader: () -> EnvironmentLoader
|
13
|
+
|
14
|
+
def setup_library_options: (OptionParser) -> OptionParser
|
15
|
+
end
|
16
|
+
|
17
|
+
interface _IO
|
18
|
+
def puts: (*untyped) -> void
|
19
|
+
|
20
|
+
def print: (*untyped) -> void
|
21
|
+
|
22
|
+
def flush: () -> void
|
13
23
|
end
|
14
24
|
|
15
|
-
attr_reader stdout:
|
16
|
-
attr_reader stderr:
|
25
|
+
attr_reader stdout: _IO
|
26
|
+
attr_reader stderr: _IO
|
17
27
|
|
18
28
|
def initialize: (stdout: IO, stderr: IO) -> void
|
19
|
-
|
29
|
+
|
20
30
|
COMMANDS: Array[Symbol]
|
21
31
|
|
22
32
|
def library_parse: (OptionParser, options: LibraryOptions) -> void
|
23
|
-
|
33
|
+
|
24
34
|
def parse_logging_options: (OptionParser) -> void
|
25
|
-
|
35
|
+
|
26
36
|
def has_parser?: () -> bool
|
27
|
-
|
37
|
+
|
28
38
|
def run: (Array[String] args) -> void
|
29
|
-
|
39
|
+
|
30
40
|
def run_ast: (Array[String], LibraryOptions) -> void
|
31
|
-
|
41
|
+
|
32
42
|
def run_list: (Array[String], LibraryOptions) -> void
|
33
|
-
|
43
|
+
|
34
44
|
def run_ancestors: (Array[String], LibraryOptions) -> void
|
35
|
-
|
45
|
+
|
36
46
|
def run_methods: (Array[String], LibraryOptions) -> void
|
37
|
-
|
47
|
+
|
38
48
|
def run_method: (Array[String], LibraryOptions) -> void
|
39
|
-
|
49
|
+
|
40
50
|
def run_validate: (Array[String], LibraryOptions) -> void
|
41
|
-
|
51
|
+
|
42
52
|
def run_constant: (Array[String], LibraryOptions) -> void
|
43
|
-
|
53
|
+
|
44
54
|
def run_paths: (Array[String], LibraryOptions) -> void
|
45
|
-
|
55
|
+
|
46
56
|
def run_prototype: (Array[String], LibraryOptions) -> void
|
47
|
-
|
57
|
+
|
48
58
|
def run_prototype_file: (String format, Array[String]) -> void
|
49
|
-
|
59
|
+
|
50
60
|
def run_vendor: (Array[String], LibraryOptions) -> void
|
51
|
-
|
61
|
+
|
52
62
|
def run_parse: (Array[String], LibraryOptions) -> void
|
53
|
-
|
63
|
+
|
54
64
|
def run_test: (Array[String], LibraryOptions) -> void
|
55
|
-
|
65
|
+
|
56
66
|
def test_opt: (LibraryOptions) -> String?
|
57
67
|
end
|
58
68
|
end
|
data/sig/comment.rbs
CHANGED
data/sig/declarations.rbs
CHANGED
@@ -10,11 +10,21 @@ module RBS
|
|
10
10
|
|
11
11
|
class ModuleTypeParams
|
12
12
|
class TypeParam
|
13
|
+
# Key
|
14
|
+
# ^^^ name
|
15
|
+
#
|
16
|
+
# unchecked out Elem
|
17
|
+
# ^^^^^^^^^ unchecked
|
18
|
+
# ^^^ variance
|
19
|
+
# ^^^^ name
|
20
|
+
type loc = Location::WithChildren[:name, :variance | :unchecked]
|
21
|
+
|
13
22
|
attr_reader name: Symbol
|
14
23
|
attr_reader variance: variance
|
15
24
|
attr_reader skip_validation: bool
|
25
|
+
attr_reader location: loc?
|
16
26
|
|
17
|
-
def initialize: (name: Symbol, variance: variance, skip_validation: boolish) -> void
|
27
|
+
def initialize: (name: Symbol, variance: variance, skip_validation: boolish, location: loc?) -> void
|
18
28
|
|
19
29
|
include _ToJson
|
20
30
|
end
|
@@ -68,19 +78,42 @@ module RBS
|
|
68
78
|
end
|
69
79
|
|
70
80
|
class Class < Base
|
71
|
-
type member = Members::t | t
|
72
|
-
|
73
81
|
class Super
|
82
|
+
# String
|
83
|
+
# ^^^^^^ name
|
84
|
+
#
|
85
|
+
# Array[String]
|
86
|
+
# ^^^^^ name
|
87
|
+
# ^^^^^^^^ args
|
88
|
+
#
|
89
|
+
type loc = Location::WithChildren[:name, :args]
|
90
|
+
|
74
91
|
attr_reader name: TypeName
|
75
92
|
attr_reader args: Array[Types::t]
|
76
|
-
attr_reader location:
|
93
|
+
attr_reader location: loc?
|
77
94
|
|
78
|
-
def initialize: (name: TypeName, args: Array[Types::t], location:
|
95
|
+
def initialize: (name: TypeName, args: Array[Types::t], location: loc?) -> void
|
79
96
|
|
80
97
|
include _HashEqual
|
81
98
|
include _ToJson
|
82
99
|
end
|
83
100
|
|
101
|
+
type member = Members::t | t
|
102
|
+
|
103
|
+
# class Foo end
|
104
|
+
# ^^^^^ keyword
|
105
|
+
# ^^^ name
|
106
|
+
# ^^^ end
|
107
|
+
#
|
108
|
+
# class Foo[A] < String end
|
109
|
+
# ^^^^^ keyword
|
110
|
+
# ^^^ name
|
111
|
+
# ^^^ type_params
|
112
|
+
# ^ lt
|
113
|
+
# ^^^ end
|
114
|
+
#
|
115
|
+
type loc = Location::WithChildren[:keyword | :name | :end, :type_params | :lt]
|
116
|
+
|
84
117
|
include NestedDeclarationHelper
|
85
118
|
include MixinHelper
|
86
119
|
|
@@ -89,24 +122,28 @@ module RBS
|
|
89
122
|
attr_reader members: Array[member]
|
90
123
|
attr_reader super_class: Super?
|
91
124
|
attr_reader annotations: Array[Annotation]
|
92
|
-
attr_reader location:
|
125
|
+
attr_reader location: loc?
|
93
126
|
attr_reader comment: Comment?
|
94
127
|
|
95
|
-
def initialize: (name: TypeName, type_params: ModuleTypeParams, members: Array[member], super_class: Super?, annotations: Array[Annotation], location:
|
128
|
+
def initialize: (name: TypeName, type_params: ModuleTypeParams, members: Array[member], super_class: Super?, annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
|
96
129
|
|
97
130
|
include _HashEqual
|
98
131
|
include _ToJson
|
99
132
|
end
|
100
133
|
|
101
134
|
class Module < Base
|
102
|
-
type member = Members::t | t
|
103
|
-
|
104
135
|
class Self
|
136
|
+
# _Each[String]
|
137
|
+
# ^^^^^ name
|
138
|
+
# ^^^^^^^^ args
|
139
|
+
#
|
140
|
+
type loc = Location::WithChildren[:name, :args]
|
141
|
+
|
105
142
|
attr_reader name: TypeName
|
106
143
|
attr_reader args: Array[Types::t]
|
107
|
-
attr_reader location:
|
144
|
+
attr_reader location: loc?
|
108
145
|
|
109
|
-
def initialize: (name: TypeName, args: Array[Types::t], location:
|
146
|
+
def initialize: (name: TypeName, args: Array[Types::t], location: loc?) -> void
|
110
147
|
|
111
148
|
include _HashEqual
|
112
149
|
include _ToJson
|
@@ -114,18 +151,35 @@ module RBS
|
|
114
151
|
def to_s: () -> String
|
115
152
|
end
|
116
153
|
|
154
|
+
type member = Members::t | t
|
155
|
+
|
156
|
+
# module Foo end
|
157
|
+
# ^^^^^^ keyword
|
158
|
+
# ^^^ name
|
159
|
+
# ^^^ end
|
160
|
+
#
|
161
|
+
# module Foo[A] : BasicObject end
|
162
|
+
# ^^^^^^ keyword
|
163
|
+
# ^^^ name
|
164
|
+
# ^^^ type_params
|
165
|
+
# ^ colon
|
166
|
+
# ^^^^^^^^^^^ self_types
|
167
|
+
# ^^^ end
|
168
|
+
#
|
169
|
+
type loc = Location::WithChildren[:keyword | :name | :end, :type_params | :colon | :self_types]
|
170
|
+
|
117
171
|
include NestedDeclarationHelper
|
118
172
|
include MixinHelper
|
119
173
|
|
120
174
|
attr_reader name: TypeName
|
121
175
|
attr_reader type_params: ModuleTypeParams
|
122
176
|
attr_reader members: Array[member]
|
123
|
-
attr_reader location:
|
177
|
+
attr_reader location: loc?
|
124
178
|
attr_reader annotations: Array[Annotation]
|
125
179
|
attr_reader self_types: Array[Self]
|
126
180
|
attr_reader comment: Comment?
|
127
181
|
|
128
|
-
def initialize: (name: TypeName, type_params: ModuleTypeParams, members: Array[member], location:
|
182
|
+
def initialize: (name: TypeName, type_params: ModuleTypeParams, members: Array[member], location: loc?, annotations: Array[Annotation], self_types: Array[Self], comment: Comment?) -> void
|
129
183
|
|
130
184
|
include _HashEqual
|
131
185
|
include _ToJson
|
@@ -134,14 +188,27 @@ module RBS
|
|
134
188
|
class Interface
|
135
189
|
type member = Members::t
|
136
190
|
|
191
|
+
# interface _Foo end
|
192
|
+
# ^^^^^^^^^ keyword
|
193
|
+
# ^^^^ name
|
194
|
+
# ^^^ end
|
195
|
+
#
|
196
|
+
# interface _Bar[A, B] end
|
197
|
+
# ^^^^^^^^^ keyword
|
198
|
+
# ^^^^ name
|
199
|
+
# ^^^^^^ type_params
|
200
|
+
# ^^^ end
|
201
|
+
#
|
202
|
+
type loc = Location::WithChildren[:name | :keyword | :end, :type_params]
|
203
|
+
|
137
204
|
attr_reader name: TypeName
|
138
205
|
attr_reader type_params: ModuleTypeParams
|
139
206
|
attr_reader members: Array[member]
|
140
207
|
attr_reader annotations: Array[Annotation]
|
141
|
-
attr_reader location:
|
208
|
+
attr_reader location: loc?
|
142
209
|
attr_reader comment: Comment?
|
143
210
|
|
144
|
-
def initialize: (name: TypeName, type_params: ModuleTypeParams, members: Array[member], annotations: Array[Annotation], location:
|
211
|
+
def initialize: (name: TypeName, type_params: ModuleTypeParams, members: Array[member], annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
|
145
212
|
|
146
213
|
include MixinHelper
|
147
214
|
|
@@ -150,37 +217,55 @@ module RBS
|
|
150
217
|
end
|
151
218
|
|
152
219
|
class Alias < Base
|
220
|
+
# type loc = Location
|
221
|
+
# ^^^^ keyword
|
222
|
+
# ^^^ name
|
223
|
+
# ^ eq
|
224
|
+
type loc = Location::WithChildren[:keyword | :name | :eq, bot]
|
225
|
+
|
153
226
|
attr_reader name: TypeName
|
154
227
|
attr_reader type: Types::t
|
155
228
|
attr_reader annotations: Array[Annotation]
|
156
|
-
attr_reader location:
|
229
|
+
attr_reader location: loc?
|
157
230
|
attr_reader comment: Comment?
|
158
231
|
|
159
|
-
def initialize: (name: TypeName, type: Types::t, annotations: Array[Annotation], location:
|
232
|
+
def initialize: (name: TypeName, type: Types::t, annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
|
160
233
|
|
161
234
|
include _HashEqual
|
162
235
|
include _ToJson
|
163
236
|
end
|
164
237
|
|
165
238
|
class Constant < Base
|
239
|
+
# VERSION: String
|
240
|
+
# ^^^^^^^ name
|
241
|
+
# ^ colon
|
242
|
+
#
|
243
|
+
type loc = Location::WithChildren[:name | :colon, bot]
|
244
|
+
|
166
245
|
attr_reader name: TypeName
|
167
246
|
attr_reader type: Types::t
|
168
|
-
attr_reader location:
|
247
|
+
attr_reader location: loc?
|
169
248
|
attr_reader comment: Comment?
|
170
249
|
|
171
|
-
def initialize: (name: TypeName, type: Types::t, location:
|
250
|
+
def initialize: (name: TypeName, type: Types::t, location: loc?, comment: Comment?) -> void
|
172
251
|
|
173
252
|
include _HashEqual
|
174
253
|
include _ToJson
|
175
254
|
end
|
176
255
|
|
177
256
|
class Global < Base
|
257
|
+
# $SIZE: String
|
258
|
+
# ^^^^^ name
|
259
|
+
# ^ colon
|
260
|
+
#
|
261
|
+
type loc = Location::WithChildren[:name | :colon, bot]
|
262
|
+
|
178
263
|
attr_reader name: Symbol
|
179
264
|
attr_reader type: Types::t
|
180
|
-
attr_reader location:
|
265
|
+
attr_reader location: loc?
|
181
266
|
attr_reader comment: Comment?
|
182
267
|
|
183
|
-
def initialize: (name: Symbol, type: Types::t, location:
|
268
|
+
def initialize: (name: Symbol, type: Types::t, location: loc?, comment: Comment?) -> void
|
184
269
|
|
185
270
|
include _HashEqual
|
186
271
|
include _ToJson
|
data/sig/environment.rbs
CHANGED
@@ -5,7 +5,7 @@ module RBS
|
|
5
5
|
interface _WithContext
|
6
6
|
def outer: () -> Array[module_decl]
|
7
7
|
|
8
|
-
def decl: () ->
|
8
|
+
def decl: () -> untyped
|
9
9
|
end
|
10
10
|
|
11
11
|
module ContextUtil : _WithContext
|
@@ -23,7 +23,7 @@ module RBS
|
|
23
23
|
end
|
24
24
|
|
25
25
|
attr_reader name: TypeName
|
26
|
-
attr_reader decls: Array[
|
26
|
+
attr_reader decls: Array[untyped]
|
27
27
|
|
28
28
|
def initialize: (name: TypeName) -> void
|
29
29
|
|
data/sig/errors.rbs
CHANGED
@@ -181,4 +181,19 @@ module RBS
|
|
181
181
|
|
182
182
|
def location: () -> Location?
|
183
183
|
end
|
184
|
+
|
185
|
+
class MixinClassError < DefinitionError
|
186
|
+
type member = AST::Members::Include | AST::Members::Prepend | AST::Members::Extend
|
187
|
+
|
188
|
+
attr_reader type_name: TypeName
|
189
|
+
attr_reader member: member
|
190
|
+
|
191
|
+
def initialize: (type_name: TypeName, member: member) -> void
|
192
|
+
|
193
|
+
def location: () -> Location?
|
194
|
+
|
195
|
+
def self.check!: (type_name: TypeName, env: Environment, member: member) -> void
|
196
|
+
|
197
|
+
def mixin_name: () -> String
|
198
|
+
end
|
184
199
|
end
|
data/sig/location.rbs
CHANGED
@@ -13,40 +13,121 @@ module RBS
|
|
13
13
|
|
14
14
|
def initialize: (buffer: Buffer, start_pos: Integer, end_pos: Integer) -> void
|
15
15
|
|
16
|
-
def inspect: () ->
|
16
|
+
def inspect: () -> String
|
17
17
|
|
18
|
+
# Returns the name of the buffer.
|
18
19
|
def name: () -> untyped
|
19
20
|
|
21
|
+
# Line of the `start_pos` (1 origin)
|
20
22
|
def start_line: () -> Integer
|
21
23
|
|
24
|
+
# Column of the `start_pos` (0 origin)
|
22
25
|
def start_column: () -> Integer
|
23
26
|
|
27
|
+
# Line of the `end_pos` (1 origin)
|
24
28
|
def end_line: () -> Integer
|
25
29
|
|
30
|
+
# Column of the `end_pos` (0 origin)
|
26
31
|
def end_column: () -> Integer
|
27
32
|
|
28
33
|
def start_loc: () -> Buffer::loc
|
29
34
|
|
30
35
|
def end_loc: () -> Buffer::loc
|
31
36
|
|
37
|
+
def range: () -> Range[Integer]
|
38
|
+
|
39
|
+
# A substring of buffer associated to the location.
|
32
40
|
def source: () -> String
|
33
41
|
|
34
42
|
def to_s: () -> String
|
35
43
|
|
44
|
+
# Returns a string representation suitable for terminal output.
|
45
|
+
#
|
46
|
+
# Location.to_string(loc) # => a.rb:1:0...3:4
|
47
|
+
# Location.to_string(nil) # => *:*:*..*:*
|
48
|
+
#
|
36
49
|
def self.to_string: (Location? location, ?default: ::String default) -> String
|
37
50
|
|
38
51
|
def ==: (untyped other) -> bool
|
39
52
|
|
53
|
+
# Returns a new location with starting positionof `self` and ending position of `other`.
|
54
|
+
#
|
55
|
+
# l1 = Location.new(buffer: buffer, start_pos: 0, end_pox: x)
|
56
|
+
# l2 = Location.new(buffer: buffer, start_pos: y, end_pos: 20)
|
57
|
+
# l1 + l2 # => Location.new(buffer: buffer, start_pos: 0, end_pos: 20)
|
58
|
+
#
|
40
59
|
def +: (Location other) -> Location
|
41
60
|
|
61
|
+
# Returns true if `loc` is exact predecessor of `self`.
|
62
|
+
#
|
63
|
+
# l1 = Location.new(...) # 0..10
|
64
|
+
# l2 = Location.new(...) # 10..13
|
65
|
+
# l3 = Location.new(...) # 13..20
|
66
|
+
#
|
67
|
+
# l1.pred?(l2) # => true
|
68
|
+
# l2.pred?(l3) # => true
|
69
|
+
# l1.pred?(l3) # => false
|
70
|
+
#
|
42
71
|
def pred?: (Location loc) -> bool
|
43
72
|
|
44
|
-
|
73
|
+
include _ToJson
|
45
74
|
|
46
75
|
# `<<` locations given as argument.
|
76
|
+
#
|
47
77
|
def concat: (*Location?) -> Location
|
48
78
|
|
49
|
-
#
|
79
|
+
# Inplace version of `+`.
|
80
|
+
#
|
50
81
|
def <<: (Location?) -> Location
|
82
|
+
|
83
|
+
# Returns WithChildren instance with given children.
|
84
|
+
#
|
85
|
+
# location.with_children(
|
86
|
+
# required: { name: name.location },
|
87
|
+
# optional: { args: nil }
|
88
|
+
# )
|
89
|
+
#
|
90
|
+
def with_children: [R, O](?required: Hash[R, Range[Integer] | Location], ?optional: Hash[O, Range[Integer] | Location | nil]) -> WithChildren[R, O]
|
91
|
+
|
92
|
+
# Location::WithChildren contains _child_ locations.
|
93
|
+
#
|
94
|
+
# # Array[String]
|
95
|
+
# # ^^^^^ <= name
|
96
|
+
# # ^^^^^^^^ <= args
|
97
|
+
# #
|
98
|
+
# # @type var loc: Location::WithChildren[:name, :args]
|
99
|
+
# loc = Location::WithChildren.new(buffer: buffer, start_pos: 0, end_pos: 13)
|
100
|
+
# loc = loc.merge_required({ name: 1...5 })
|
101
|
+
# loc = loc.merge_optional({ args: 5...13 })
|
102
|
+
#
|
103
|
+
# loc[:name] # => Location instance for `Array`
|
104
|
+
# loc[:args] # => Location instance for `[String]`
|
105
|
+
#
|
106
|
+
class WithChildren[RequiredChildKeys, OptionalChildKeys] < Location
|
107
|
+
attr_reader required_children: Hash[RequiredChildKeys, Range[Integer]]
|
108
|
+
|
109
|
+
attr_reader optional_children: Hash[OptionalChildKeys, Range[Integer]?]
|
110
|
+
|
111
|
+
def initialize: ...
|
112
|
+
|
113
|
+
def initialize_copy: ...
|
114
|
+
|
115
|
+
# Returns `Location` instance for given _child_ name.
|
116
|
+
#
|
117
|
+
# # @type var loc: Location::WithChildren[:name, :args]
|
118
|
+
# loc[:name] # => Location
|
119
|
+
# loc[:args] # => may be nil
|
120
|
+
#
|
121
|
+
# Note that passing unknown symbol raises an error even if the child is _optional_.
|
122
|
+
# You need explicitly set `nil` for absent optional children.
|
123
|
+
#
|
124
|
+
def []: (RequiredChildKeys) -> Location
|
125
|
+
| (OptionalChildKeys) -> Location?
|
126
|
+
| (Symbol) -> Location?
|
127
|
+
|
128
|
+
def merge_required: (Hash[RequiredChildKeys, Range[Integer] | Location]) -> self
|
129
|
+
|
130
|
+
def merge_optional: (Hash[OptionalChildKeys, Range[Integer] | Location | nil]) -> self
|
131
|
+
end
|
51
132
|
end
|
52
133
|
end
|