Skip to content

Commit fb39d58

Browse files
kddnewtonmatzbot
authored andcommitted
[ruby/prism] rbs-inline
ruby/prism@1fdd4c5a49
1 parent 9aa3dc6 commit fb39d58

25 files changed

Lines changed: 1450 additions & 263 deletions

lib/prism.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
# rbs_inline: enabled
23
# :markup: markdown
34

45
# The Prism Ruby parser.
@@ -37,6 +38,8 @@ module Prism
3738
# Raised when requested to parse as the currently running Ruby version but Prism has no support for it.
3839
class CurrentVersionError < ArgumentError
3940
# Initialize a new exception for the given ruby version string.
41+
#--
42+
#: (String version) -> void
4043
def initialize(version)
4144
message = +"invalid version: Requested to parse as `version: 'current'`; "
4245
segments =
@@ -61,6 +64,8 @@ def initialize(version)
6164
# resembles the return value of Ripper.lex.
6265
#
6366
# For supported options, see Prism.parse.
67+
#--
68+
#: (String source, **untyped options) -> LexCompat::Result
6469
def self.lex_compat(source, **options)
6570
LexCompat.new(source, **options).result # steep:ignore
6671
end
@@ -69,9 +74,37 @@ def self.lex_compat(source, **options)
6974
# load(source, serialized, freeze) -> ParseResult
7075
#
7176
# Load the serialized AST using the source as a reference into a tree.
77+
#--
78+
#: (String source, String serialized, ?bool freeze) -> ParseResult
7279
def self.load(source, serialized, freeze = false)
7380
Serialize.load_parse(source, serialized, freeze)
7481
end
82+
83+
# @rbs!
84+
# VERSION: String
85+
# BACKEND: :CEXT | :FFI
86+
#
87+
# interface _Stream
88+
# def gets: (?Integer integer) -> (String | nil)
89+
# end
90+
#
91+
# def self.parse: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
92+
# def self.profile: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> void
93+
# def self.lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult
94+
# def self.parse_lex: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult
95+
# def self.dump: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> String
96+
# def self.parse_comments: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment]
97+
# def self.parse_success?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
98+
# def self.parse_failure?: (String source, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
99+
# def self.parse_stream: (_Stream stream, ?filepath: String, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
100+
# def self.parse_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseResult
101+
# def self.profile_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> void
102+
# def self.lex_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> LexResult
103+
# def self.parse_lex_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> ParseLexResult
104+
# def self.dump_file: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> String
105+
# def self.parse_file_comments: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> Array[Comment]
106+
# def self.parse_file_success?: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
107+
# def self.parse_file_failure?: (String filepath, ?command_line: String, ?encoding: Encoding | false, ?freeze: bool, ?frozen_string_literal: bool, ?line: Integer, ?main_script: bool, ?partial_script: bool, ?scopes: Array[Array[Symbol]], ?version: String) -> bool
75108
end
76109

77110
require_relative "prism/polyfill/byteindex"

lib/prism/desugar_compiler.rb

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# frozen_string_literal: true
2+
# rbs_inline: enabled
23
# :markup: markdown
34

45
module Prism
56
class DesugarAndWriteNode # :nodoc:
67
include DSL
78

8-
attr_reader :node, :default_source, :read_class, :write_class, :arguments
9+
attr_reader :node #: ClassVariableAndWriteNode | ConstantAndWriteNode | GlobalVariableAndWriteNode | InstanceVariableAndWriteNode | LocalVariableAndWriteNode
10+
attr_reader :default_source #: Source
11+
attr_reader :read_class, :write_class #: Symbol
12+
attr_reader :arguments #: Hash[Symbol, untyped]
913

14+
#: ((ClassVariableAndWriteNode | ConstantAndWriteNode | GlobalVariableAndWriteNode | InstanceVariableAndWriteNode | LocalVariableAndWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
1015
def initialize(node, default_source, read_class, write_class, **arguments)
1116
@node = node
1217
@default_source = default_source
@@ -16,6 +21,8 @@ def initialize(node, default_source, read_class, write_class, **arguments)
1621
end
1722

1823
# Desugar `x &&= y` to `x && x = y`
24+
#--
25+
#: () -> node
1926
def compile
2027
and_node(
2128
location: node.location,
@@ -36,8 +43,12 @@ def compile
3643
class DesugarOrWriteDefinedNode # :nodoc:
3744
include DSL
3845

39-
attr_reader :node, :default_source, :read_class, :write_class, :arguments
46+
attr_reader :node #: ClassVariableOrWriteNode | ConstantOrWriteNode | GlobalVariableOrWriteNode
47+
attr_reader :default_source #: Source
48+
attr_reader :read_class, :write_class #: Symbol
49+
attr_reader :arguments #: Hash[Symbol, untyped]
4050

51+
#: ((ClassVariableOrWriteNode | ConstantOrWriteNode | GlobalVariableOrWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
4152
def initialize(node, default_source, read_class, write_class, **arguments)
4253
@node = node
4354
@default_source = default_source
@@ -47,6 +58,8 @@ def initialize(node, default_source, read_class, write_class, **arguments)
4758
end
4859

4960
# Desugar `x ||= y` to `defined?(x) ? x : x = y`
61+
#--
62+
#: () -> node
5063
def compile
5164
if_node(
5265
location: node.location,
@@ -87,8 +100,12 @@ def compile
87100
class DesugarOperatorWriteNode # :nodoc:
88101
include DSL
89102

90-
attr_reader :node, :default_source, :read_class, :write_class, :arguments
103+
attr_reader :node #: ClassVariableOperatorWriteNode | ConstantOperatorWriteNode | GlobalVariableOperatorWriteNode | InstanceVariableOperatorWriteNode | LocalVariableOperatorWriteNode
104+
attr_reader :default_source #: Source
105+
attr_reader :read_class, :write_class #: Symbol
106+
attr_reader :arguments #: Hash[Symbol, untyped]
91107

108+
#: ((ClassVariableOperatorWriteNode | ConstantOperatorWriteNode | GlobalVariableOperatorWriteNode | InstanceVariableOperatorWriteNode | LocalVariableOperatorWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
92109
def initialize(node, default_source, read_class, write_class, **arguments)
93110
@node = node
94111
@default_source = default_source
@@ -98,6 +115,8 @@ def initialize(node, default_source, read_class, write_class, **arguments)
98115
end
99116

100117
# Desugar `x += y` to `x = x + y`
118+
#--
119+
#: () -> node
101120
def compile
102121
binary_operator_loc = node.binary_operator_loc.chop
103122

@@ -131,8 +150,12 @@ def compile
131150
class DesugarOrWriteNode # :nodoc:
132151
include DSL
133152

134-
attr_reader :node, :default_source, :read_class, :write_class, :arguments
153+
attr_reader :node #: InstanceVariableOrWriteNode | LocalVariableOrWriteNode
154+
attr_reader :default_source #: Source
155+
attr_reader :read_class, :write_class #: Symbol
156+
attr_reader :arguments #: Hash[Symbol, untyped]
135157

158+
#: ((InstanceVariableOrWriteNode | LocalVariableOrWriteNode) node, Source default_source, Symbol read_class, Symbol write_class, **untyped arguments) -> void
136159
def initialize(node, default_source, read_class, write_class, **arguments)
137160
@node = node
138161
@default_source = default_source
@@ -142,6 +165,8 @@ def initialize(node, default_source, read_class, write_class, **arguments)
142165
end
143166

144167
# Desugar `x ||= y` to `x || x = y`
168+
#--
169+
#: () -> node
145170
def compile
146171
or_node(
147172
location: node.location,
@@ -162,90 +187,105 @@ def compile
162187
private_constant :DesugarAndWriteNode, :DesugarOrWriteNode, :DesugarOrWriteDefinedNode, :DesugarOperatorWriteNode
163188

164189
class ClassVariableAndWriteNode
190+
#: () -> node
165191
def desugar # :nodoc:
166192
DesugarAndWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
167193
end
168194
end
169195

170196
class ClassVariableOrWriteNode
197+
#: () -> node
171198
def desugar # :nodoc:
172199
DesugarOrWriteDefinedNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
173200
end
174201
end
175202

176203
class ClassVariableOperatorWriteNode
204+
#: () -> node
177205
def desugar # :nodoc:
178206
DesugarOperatorWriteNode.new(self, source, :class_variable_read_node, :class_variable_write_node, name: name).compile
179207
end
180208
end
181209

182210
class ConstantAndWriteNode
211+
#: () -> node
183212
def desugar # :nodoc:
184213
DesugarAndWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
185214
end
186215
end
187216

188217
class ConstantOrWriteNode
218+
#: () -> node
189219
def desugar # :nodoc:
190220
DesugarOrWriteDefinedNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
191221
end
192222
end
193223

194224
class ConstantOperatorWriteNode
225+
#: () -> node
195226
def desugar # :nodoc:
196227
DesugarOperatorWriteNode.new(self, source, :constant_read_node, :constant_write_node, name: name).compile
197228
end
198229
end
199230

200231
class GlobalVariableAndWriteNode
232+
#: () -> node
201233
def desugar # :nodoc:
202234
DesugarAndWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
203235
end
204236
end
205237

206238
class GlobalVariableOrWriteNode
239+
#: () -> node
207240
def desugar # :nodoc:
208241
DesugarOrWriteDefinedNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
209242
end
210243
end
211244

212245
class GlobalVariableOperatorWriteNode
246+
#: () -> node
213247
def desugar # :nodoc:
214248
DesugarOperatorWriteNode.new(self, source, :global_variable_read_node, :global_variable_write_node, name: name).compile
215249
end
216250
end
217251

218252
class InstanceVariableAndWriteNode
253+
#: () -> node
219254
def desugar # :nodoc:
220255
DesugarAndWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
221256
end
222257
end
223258

224259
class InstanceVariableOrWriteNode
260+
#: () -> node
225261
def desugar # :nodoc:
226262
DesugarOrWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
227263
end
228264
end
229265

230266
class InstanceVariableOperatorWriteNode
267+
#: () -> node
231268
def desugar # :nodoc:
232269
DesugarOperatorWriteNode.new(self, source, :instance_variable_read_node, :instance_variable_write_node, name: name).compile
233270
end
234271
end
235272

236273
class LocalVariableAndWriteNode
274+
#: () -> node
237275
def desugar # :nodoc:
238276
DesugarAndWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
239277
end
240278
end
241279

242280
class LocalVariableOrWriteNode
281+
#: () -> node
243282
def desugar # :nodoc:
244283
DesugarOrWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
245284
end
246285
end
247286

248287
class LocalVariableOperatorWriteNode
288+
#: () -> node
249289
def desugar # :nodoc:
250290
DesugarOperatorWriteNode.new(self, source, :local_variable_read_node, :local_variable_write_node, name: name, depth: depth).compile
251291
end
@@ -259,6 +299,8 @@ class DesugarCompiler < MutationCompiler
259299
# becomes
260300
#
261301
# `@@foo && @@foo = bar`
302+
#--
303+
#: (ClassVariableAndWriteNode node) -> node
262304
def visit_class_variable_and_write_node(node)
263305
node.desugar
264306
end
@@ -268,6 +310,8 @@ def visit_class_variable_and_write_node(node)
268310
# becomes
269311
#
270312
# `defined?(@@foo) ? @@foo : @@foo = bar`
313+
#--
314+
#: (ClassVariableOrWriteNode node) -> node
271315
def visit_class_variable_or_write_node(node)
272316
node.desugar
273317
end
@@ -277,6 +321,8 @@ def visit_class_variable_or_write_node(node)
277321
# becomes
278322
#
279323
# `@@foo = @@foo + bar`
324+
#--
325+
#: (ClassVariableOperatorWriteNode node) -> node
280326
def visit_class_variable_operator_write_node(node)
281327
node.desugar
282328
end
@@ -286,6 +332,8 @@ def visit_class_variable_operator_write_node(node)
286332
# becomes
287333
#
288334
# `Foo && Foo = bar`
335+
#--
336+
#: (ConstantAndWriteNode node) -> node
289337
def visit_constant_and_write_node(node)
290338
node.desugar
291339
end
@@ -295,6 +343,8 @@ def visit_constant_and_write_node(node)
295343
# becomes
296344
#
297345
# `defined?(Foo) ? Foo : Foo = bar`
346+
#--
347+
#: (ConstantOrWriteNode node) -> node
298348
def visit_constant_or_write_node(node)
299349
node.desugar
300350
end
@@ -304,6 +354,8 @@ def visit_constant_or_write_node(node)
304354
# becomes
305355
#
306356
# `Foo = Foo + bar`
357+
#--
358+
#: (ConstantOperatorWriteNode node) -> node
307359
def visit_constant_operator_write_node(node)
308360
node.desugar
309361
end
@@ -313,6 +365,8 @@ def visit_constant_operator_write_node(node)
313365
# becomes
314366
#
315367
# `$foo && $foo = bar`
368+
#--
369+
#: (GlobalVariableAndWriteNode node) -> node
316370
def visit_global_variable_and_write_node(node)
317371
node.desugar
318372
end
@@ -322,6 +376,8 @@ def visit_global_variable_and_write_node(node)
322376
# becomes
323377
#
324378
# `defined?($foo) ? $foo : $foo = bar`
379+
#--
380+
#: (GlobalVariableOrWriteNode node) -> node
325381
def visit_global_variable_or_write_node(node)
326382
node.desugar
327383
end
@@ -331,6 +387,8 @@ def visit_global_variable_or_write_node(node)
331387
# becomes
332388
#
333389
# `$foo = $foo + bar`
390+
#--
391+
#: (GlobalVariableOperatorWriteNode node) -> node
334392
def visit_global_variable_operator_write_node(node)
335393
node.desugar
336394
end
@@ -340,6 +398,8 @@ def visit_global_variable_operator_write_node(node)
340398
# becomes
341399
#
342400
# `@foo && @foo = bar`
401+
#--
402+
#: (InstanceVariableAndWriteNode node) -> node
343403
def visit_instance_variable_and_write_node(node)
344404
node.desugar
345405
end
@@ -349,6 +409,8 @@ def visit_instance_variable_and_write_node(node)
349409
# becomes
350410
#
351411
# `@foo || @foo = bar`
412+
#--
413+
#: (InstanceVariableOrWriteNode node) -> node
352414
def visit_instance_variable_or_write_node(node)
353415
node.desugar
354416
end
@@ -358,6 +420,8 @@ def visit_instance_variable_or_write_node(node)
358420
# becomes
359421
#
360422
# `@foo = @foo + bar`
423+
#--
424+
#: (InstanceVariableOperatorWriteNode node) -> node
361425
def visit_instance_variable_operator_write_node(node)
362426
node.desugar
363427
end
@@ -367,6 +431,8 @@ def visit_instance_variable_operator_write_node(node)
367431
# becomes
368432
#
369433
# `foo && foo = bar`
434+
#--
435+
#: (LocalVariableAndWriteNode node) -> node
370436
def visit_local_variable_and_write_node(node)
371437
node.desugar
372438
end
@@ -376,6 +442,8 @@ def visit_local_variable_and_write_node(node)
376442
# becomes
377443
#
378444
# `foo || foo = bar`
445+
#--
446+
#: (LocalVariableOrWriteNode node) -> node
379447
def visit_local_variable_or_write_node(node)
380448
node.desugar
381449
end
@@ -385,6 +453,8 @@ def visit_local_variable_or_write_node(node)
385453
# becomes
386454
#
387455
# `foo = foo + bar`
456+
#--
457+
#: (LocalVariableOperatorWriteNode node) -> node
388458
def visit_local_variable_operator_write_node(node)
389459
node.desugar
390460
end

0 commit comments

Comments
 (0)