lib-ruby-parser 4.0.3.0-arm64-darwin
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 +7 -0
- data/README.md +122 -0
- data/lib/lib-ruby-parser/messages.rb +828 -0
- data/lib/lib-ruby-parser/native/aarch64-apple-darwin/lib_ruby_parser.bundle +0 -0
- data/lib/lib-ruby-parser/nodes.rb +4452 -0
- data/lib/lib-ruby-parser/version.rb +4 -0
- data/lib/lib-ruby-parser.rb +320 -0
- data/lib-ruby-parser.gemspec +34 -0
- metadata +52 -0
@@ -0,0 +1,4452 @@
|
|
1
|
+
# This file is autogenerated by codegen/nodes.rb.liquid
|
2
|
+
|
3
|
+
# Root module
|
4
|
+
module LibRubyParser
|
5
|
+
# Module with all known Node sub-types
|
6
|
+
module Nodes
|
7
|
+
# Represents `alias to from` statement.
|
8
|
+
class Alias < Node
|
9
|
+
# Target of the `alias`.
|
10
|
+
#
|
11
|
+
# `Sym("foo")` node for `alias :foo :bar`
|
12
|
+
#
|
13
|
+
# @return [Node]
|
14
|
+
attr_reader :to
|
15
|
+
# Source of the `alias`.
|
16
|
+
#
|
17
|
+
# `Sym("bar")` node for `alias :foo :bar`
|
18
|
+
#
|
19
|
+
# @return [Node]
|
20
|
+
attr_reader :from
|
21
|
+
# Location of the `alias` keyword
|
22
|
+
#
|
23
|
+
# ```text
|
24
|
+
# alias foo bar
|
25
|
+
# ~~~~~
|
26
|
+
# ```
|
27
|
+
#
|
28
|
+
# @return [Loc]
|
29
|
+
attr_reader :keyword_l
|
30
|
+
# Location of the full expression
|
31
|
+
#
|
32
|
+
# ```text
|
33
|
+
# alias foo bar
|
34
|
+
# ~~~~~~~~~~~~~
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
# @return [Loc]
|
38
|
+
attr_reader :expression_l
|
39
|
+
end
|
40
|
+
|
41
|
+
# Represents `foo && bar` (or `foo and bar`) statement.
|
42
|
+
class And < Node
|
43
|
+
# Left hand statament of the `&&` operation.
|
44
|
+
#
|
45
|
+
# `Lvar("foo")` node for `foo && bar`
|
46
|
+
#
|
47
|
+
# @return [Node]
|
48
|
+
attr_reader :lhs
|
49
|
+
# Right hand statement of the `&&` operation.
|
50
|
+
#
|
51
|
+
# `Lvar("bar")` node for `foo && bar`
|
52
|
+
#
|
53
|
+
# @return [Node]
|
54
|
+
attr_reader :rhs
|
55
|
+
# Location of the `&&` (or `and`) operator
|
56
|
+
#
|
57
|
+
# ```text
|
58
|
+
# a && b
|
59
|
+
# ~~
|
60
|
+
# ```
|
61
|
+
#
|
62
|
+
# @return [Loc]
|
63
|
+
attr_reader :operator_l
|
64
|
+
# Location of the full expression
|
65
|
+
#
|
66
|
+
# ```text
|
67
|
+
# a && b
|
68
|
+
# ~~~~~~
|
69
|
+
# ```
|
70
|
+
#
|
71
|
+
# @return [Loc]
|
72
|
+
attr_reader :expression_l
|
73
|
+
end
|
74
|
+
|
75
|
+
# Represents `a &&= 1` statement.
|
76
|
+
class AndAsgn < Node
|
77
|
+
# Receiver of the `&&=` operation.
|
78
|
+
#
|
79
|
+
# `Lvasgn("a")` node for `a &&= 1`
|
80
|
+
#
|
81
|
+
# @return [Node]
|
82
|
+
attr_reader :recv
|
83
|
+
# Right hand statement of assignment
|
84
|
+
#
|
85
|
+
# `Int("1")` node for `a &&= 1`
|
86
|
+
#
|
87
|
+
# @return [Node]
|
88
|
+
attr_reader :value
|
89
|
+
# Location of the `&&=` operator
|
90
|
+
#
|
91
|
+
# ```text
|
92
|
+
# a &&= 1
|
93
|
+
# ~~~
|
94
|
+
# ```
|
95
|
+
#
|
96
|
+
# @return [Loc]
|
97
|
+
attr_reader :operator_l
|
98
|
+
# Location of the full expression
|
99
|
+
#
|
100
|
+
# ```text
|
101
|
+
# a &&= 1
|
102
|
+
# ~~~~~~~
|
103
|
+
# ```
|
104
|
+
#
|
105
|
+
# @return [Loc]
|
106
|
+
attr_reader :expression_l
|
107
|
+
end
|
108
|
+
|
109
|
+
# Represents a positional required block/method argument.
|
110
|
+
#
|
111
|
+
# `a` in `def m(a); end` or `proc { |a| }`
|
112
|
+
class Arg < Node
|
113
|
+
# Name of the argument
|
114
|
+
#
|
115
|
+
# @return [String]
|
116
|
+
attr_reader :name
|
117
|
+
# Location of the full expression
|
118
|
+
#
|
119
|
+
# ```text
|
120
|
+
# def m(argument); end
|
121
|
+
# ~~~~~~~~
|
122
|
+
# ```
|
123
|
+
#
|
124
|
+
# @return [Loc]
|
125
|
+
attr_reader :expression_l
|
126
|
+
end
|
127
|
+
|
128
|
+
# Represents an arguments list
|
129
|
+
#
|
130
|
+
# `Args(vec![Arg("a"), Optarg("b", Int("1"))])` in `def m(a, b = 1); end`
|
131
|
+
class Args < Node
|
132
|
+
# List of arguments
|
133
|
+
#
|
134
|
+
# @return [::Array<Node>]
|
135
|
+
attr_reader :args
|
136
|
+
# Location of the full expression
|
137
|
+
#
|
138
|
+
# ```text
|
139
|
+
# def m(a, b = 1, c:, &blk); end
|
140
|
+
# ~~~~~~~~~~~~~~~~~~~~
|
141
|
+
# ```
|
142
|
+
#
|
143
|
+
# @return [Loc]
|
144
|
+
attr_reader :expression_l
|
145
|
+
# Location of the open parenthesis
|
146
|
+
#
|
147
|
+
# ```text
|
148
|
+
# def m(a, b = 1, c:, &blk); end
|
149
|
+
# ~
|
150
|
+
# ```
|
151
|
+
#
|
152
|
+
# `None` for code like `def m; end` or `def m arg; end`
|
153
|
+
#
|
154
|
+
# @return [Loc, nil]
|
155
|
+
attr_reader :begin_l
|
156
|
+
# Location of the closing parenthesis
|
157
|
+
#
|
158
|
+
# ```text
|
159
|
+
# def m(a, b = 1, c:, &blk); end
|
160
|
+
# ~
|
161
|
+
# ```
|
162
|
+
#
|
163
|
+
# `None` for code like `def m; end` or `def m arg; end`
|
164
|
+
#
|
165
|
+
# @return [Loc, nil]
|
166
|
+
attr_reader :end_l
|
167
|
+
end
|
168
|
+
|
169
|
+
# Represents an array literal
|
170
|
+
class Array < Node
|
171
|
+
# A list of elements
|
172
|
+
#
|
173
|
+
# @return [::Array<Node>]
|
174
|
+
attr_reader :elements
|
175
|
+
# Location of the open bracket
|
176
|
+
#
|
177
|
+
# ```text
|
178
|
+
# [1, 2, 3]
|
179
|
+
# ~
|
180
|
+
# ```
|
181
|
+
#
|
182
|
+
# @return [Loc, nil]
|
183
|
+
attr_reader :begin_l
|
184
|
+
# Location of the closing bracket
|
185
|
+
#
|
186
|
+
# ```text
|
187
|
+
# [1, 2, 3]
|
188
|
+
# ~
|
189
|
+
# ```
|
190
|
+
#
|
191
|
+
# @return [Loc, nil]
|
192
|
+
attr_reader :end_l
|
193
|
+
# Location of the full expression
|
194
|
+
#
|
195
|
+
# ```text
|
196
|
+
# [1, 2, 3]
|
197
|
+
# ~~~~~~~~~
|
198
|
+
# ```
|
199
|
+
#
|
200
|
+
# @return [Loc]
|
201
|
+
attr_reader :expression_l
|
202
|
+
end
|
203
|
+
|
204
|
+
# Represents an array pattern used in pattern matching
|
205
|
+
class ArrayPattern < Node
|
206
|
+
# A list of elements
|
207
|
+
#
|
208
|
+
# @return [::Array<Node>]
|
209
|
+
attr_reader :elements
|
210
|
+
# Location of the open bracket
|
211
|
+
#
|
212
|
+
# ```text
|
213
|
+
# [1, ^a, 3 => foo]
|
214
|
+
# ~
|
215
|
+
# ```
|
216
|
+
#
|
217
|
+
# `None` for pattern like `1, 2` without brackets
|
218
|
+
#
|
219
|
+
# @return [Loc, nil]
|
220
|
+
attr_reader :begin_l
|
221
|
+
# Location of the closing bracket
|
222
|
+
#
|
223
|
+
# ```text
|
224
|
+
# [1, ^a, 3 => foo]
|
225
|
+
# ~
|
226
|
+
# ```
|
227
|
+
#
|
228
|
+
# `None` for pattern like `1, 2` without brackets
|
229
|
+
#
|
230
|
+
# @return [Loc, nil]
|
231
|
+
attr_reader :end_l
|
232
|
+
# Location of the full expression
|
233
|
+
#
|
234
|
+
# ```text
|
235
|
+
# [1, ^a, 3 => foo]
|
236
|
+
# ~~~~~~~~~~~~~~~~~
|
237
|
+
# ```
|
238
|
+
#
|
239
|
+
# @return [Loc]
|
240
|
+
attr_reader :expression_l
|
241
|
+
end
|
242
|
+
|
243
|
+
# Represents an array pattern *with trailing comma* used in pattern matching
|
244
|
+
#
|
245
|
+
# It's slightly different from `ArrayPattern`, trailing comma at the end works as `, *`
|
246
|
+
class ArrayPatternWithTail < Node
|
247
|
+
# A list of elements
|
248
|
+
#
|
249
|
+
# @return [::Array<Node>]
|
250
|
+
attr_reader :elements
|
251
|
+
# Location of the open bracket
|
252
|
+
#
|
253
|
+
# ```text
|
254
|
+
# [1, ^a, 3 => foo,]
|
255
|
+
# ~
|
256
|
+
# ```
|
257
|
+
#
|
258
|
+
# `None` for pattern like `1, 2,` without brackets
|
259
|
+
#
|
260
|
+
# @return [Loc, nil]
|
261
|
+
attr_reader :begin_l
|
262
|
+
# Location of the closing bracket
|
263
|
+
#
|
264
|
+
# ```text
|
265
|
+
# [1, ^a, 3 => foo,]
|
266
|
+
# ~
|
267
|
+
# ```
|
268
|
+
#
|
269
|
+
# `None` for pattern like `1, 2,` without brackets
|
270
|
+
#
|
271
|
+
# @return [Loc, nil]
|
272
|
+
attr_reader :end_l
|
273
|
+
# Location of the full expression
|
274
|
+
#
|
275
|
+
# ```text
|
276
|
+
# [1, ^a, 3 => foo,]
|
277
|
+
# ~~~~~~~~~~~~~~~~~~
|
278
|
+
# ```
|
279
|
+
#
|
280
|
+
# @return [Loc]
|
281
|
+
attr_reader :expression_l
|
282
|
+
end
|
283
|
+
|
284
|
+
# Represents special global variables:
|
285
|
+
# 1. `` $` ``
|
286
|
+
# 2. `$&`
|
287
|
+
# 3. `$'`
|
288
|
+
# 4. `$+`
|
289
|
+
class BackRef < Node
|
290
|
+
# Name of the variable (`"$+"` for `$+`)
|
291
|
+
#
|
292
|
+
# @return [String]
|
293
|
+
attr_reader :name
|
294
|
+
# Location of the full expression
|
295
|
+
#
|
296
|
+
# ```text
|
297
|
+
# $+
|
298
|
+
# ~~
|
299
|
+
# ```
|
300
|
+
#
|
301
|
+
# @return [Loc]
|
302
|
+
attr_reader :expression_l
|
303
|
+
end
|
304
|
+
|
305
|
+
# Represents compound statement (i.e. a multi-statement)
|
306
|
+
#
|
307
|
+
# Basically all blocks of code are wrapped into `Begin` node (e.g. method/block body, rescue/ensure handler etc)
|
308
|
+
class Begin < Node
|
309
|
+
# A list of statements
|
310
|
+
#
|
311
|
+
# @return [::Array<Node>]
|
312
|
+
attr_reader :statements
|
313
|
+
# Begin of the block
|
314
|
+
#
|
315
|
+
# ```text
|
316
|
+
# (1; 2)
|
317
|
+
# ~
|
318
|
+
# ```
|
319
|
+
#
|
320
|
+
# `None` if the block of code is "implicit", like
|
321
|
+
#
|
322
|
+
# ```text
|
323
|
+
# if true; 1; 2; end
|
324
|
+
# ```
|
325
|
+
#
|
326
|
+
# @return [Loc, nil]
|
327
|
+
attr_reader :begin_l
|
328
|
+
# End of the block
|
329
|
+
#
|
330
|
+
# ```text
|
331
|
+
# (1; 2)
|
332
|
+
# ~
|
333
|
+
# ```
|
334
|
+
#
|
335
|
+
# `None` if the block of code is "implicit", like
|
336
|
+
#
|
337
|
+
# ```text
|
338
|
+
# if true; 1; 2; end
|
339
|
+
# ```
|
340
|
+
#
|
341
|
+
# @return [Loc, nil]
|
342
|
+
attr_reader :end_l
|
343
|
+
# Location of the full expression
|
344
|
+
#
|
345
|
+
# ```text
|
346
|
+
# (1; 2)
|
347
|
+
# ~~~~~~
|
348
|
+
# ```
|
349
|
+
#
|
350
|
+
# @return [Loc]
|
351
|
+
attr_reader :expression_l
|
352
|
+
end
|
353
|
+
|
354
|
+
# Represents a Ruby block that is passed to a method (`proc { |foo| bar }`)
|
355
|
+
class Block < Node
|
356
|
+
# Method call that takes a block
|
357
|
+
#
|
358
|
+
# `Send("foo")` in `foo {}`
|
359
|
+
#
|
360
|
+
# @return [Node]
|
361
|
+
attr_reader :call
|
362
|
+
# A list of argument that block takes
|
363
|
+
#
|
364
|
+
# `vec![ Arg("a"), Optarg("b", Int("1")) ]` for `proc { |a, b = 1| }`
|
365
|
+
#
|
366
|
+
# `None` if the block takes no arguments
|
367
|
+
#
|
368
|
+
# @return [Node, nil]
|
369
|
+
attr_reader :args
|
370
|
+
# Block body, `None` if block has no body.
|
371
|
+
#
|
372
|
+
# @return [Node, nil]
|
373
|
+
attr_reader :body
|
374
|
+
# Location of the open brace
|
375
|
+
#
|
376
|
+
# ```text
|
377
|
+
# proc { }
|
378
|
+
# ~
|
379
|
+
# ```
|
380
|
+
#
|
381
|
+
# @return [Loc]
|
382
|
+
attr_reader :begin_l
|
383
|
+
# Location of the closing brace
|
384
|
+
#
|
385
|
+
# ```text
|
386
|
+
# proc { }
|
387
|
+
# ~
|
388
|
+
# ```
|
389
|
+
#
|
390
|
+
# @return [Loc]
|
391
|
+
attr_reader :end_l
|
392
|
+
# Location of the full expression
|
393
|
+
#
|
394
|
+
# ```text
|
395
|
+
# proc { }
|
396
|
+
# ~~~~~~~~
|
397
|
+
# ```
|
398
|
+
#
|
399
|
+
# @return [Loc]
|
400
|
+
attr_reader :expression_l
|
401
|
+
end
|
402
|
+
|
403
|
+
# Represents a `&blk` argument in the method definition (but not in the method call, see `BlockPass`)
|
404
|
+
class Blockarg < Node
|
405
|
+
# Name of the argument, `String("foo")` for `def m(&foo)`
|
406
|
+
#
|
407
|
+
# @return [String, nil]
|
408
|
+
attr_reader :name
|
409
|
+
# Location of the `&` operator
|
410
|
+
#
|
411
|
+
# ```text
|
412
|
+
# def m(&foo); end
|
413
|
+
# ~
|
414
|
+
# ```
|
415
|
+
#
|
416
|
+
# @return [Loc]
|
417
|
+
attr_reader :operator_l
|
418
|
+
# Location of the name
|
419
|
+
#
|
420
|
+
# ```text
|
421
|
+
# def m(&foo); end
|
422
|
+
# ~~~
|
423
|
+
# ```
|
424
|
+
#
|
425
|
+
# @return [Loc, nil]
|
426
|
+
attr_reader :name_l
|
427
|
+
# Location of the full expression
|
428
|
+
#
|
429
|
+
# ```text
|
430
|
+
# def m(&foo); end
|
431
|
+
# ~~~~
|
432
|
+
# ```
|
433
|
+
#
|
434
|
+
# @return [Loc]
|
435
|
+
attr_reader :expression_l
|
436
|
+
end
|
437
|
+
|
438
|
+
# Represents a `&blk` argument of the method call (but not of the method definition, see `BlockArg`)
|
439
|
+
class BlockPass < Node
|
440
|
+
# Value that is converted to a block
|
441
|
+
#
|
442
|
+
# `Int("1")` in `foo(&1)` (yes, it's possible)
|
443
|
+
#
|
444
|
+
# @return [Node, nil]
|
445
|
+
attr_reader :value
|
446
|
+
# Location of the `&` operator
|
447
|
+
#
|
448
|
+
# ```text
|
449
|
+
# foo(&blk)
|
450
|
+
# ~
|
451
|
+
# ```
|
452
|
+
#
|
453
|
+
# @return [Loc]
|
454
|
+
attr_reader :operator_l
|
455
|
+
# Location of the full expression
|
456
|
+
#
|
457
|
+
# ```text
|
458
|
+
# foo(&bar)
|
459
|
+
# ~~~~
|
460
|
+
# ```
|
461
|
+
#
|
462
|
+
# @return [Loc]
|
463
|
+
attr_reader :expression_l
|
464
|
+
end
|
465
|
+
|
466
|
+
# Represents a `break` keyword (with optional argument)
|
467
|
+
class Break < Node
|
468
|
+
# A list of arguments
|
469
|
+
#
|
470
|
+
# @return [::Array<Node>]
|
471
|
+
attr_reader :args
|
472
|
+
# Location of the `break` keyword
|
473
|
+
#
|
474
|
+
# ```text
|
475
|
+
# break :foo
|
476
|
+
# ~~~~~
|
477
|
+
# ```
|
478
|
+
#
|
479
|
+
# @return [Loc]
|
480
|
+
attr_reader :keyword_l
|
481
|
+
# Location of the full expression
|
482
|
+
#
|
483
|
+
# ```text
|
484
|
+
# break(:foo)
|
485
|
+
# ~~~~~~~~~~~
|
486
|
+
# ```
|
487
|
+
#
|
488
|
+
# @return [Loc]
|
489
|
+
attr_reader :expression_l
|
490
|
+
end
|
491
|
+
|
492
|
+
# Represents a `case` statement (for pattern matching see `CaseMatch` node)
|
493
|
+
class Case < Node
|
494
|
+
# Expression given to `case`, `Int("1")` for `case 1; end`
|
495
|
+
# `None` for code like
|
496
|
+
#
|
497
|
+
# ```text
|
498
|
+
# case
|
499
|
+
# when pattern
|
500
|
+
# end
|
501
|
+
# ```
|
502
|
+
#
|
503
|
+
# @return [Node, nil]
|
504
|
+
attr_reader :expr
|
505
|
+
# A list of `When` nodes (each has `patterns` and `body`)
|
506
|
+
#
|
507
|
+
# @return [::Array<Node>]
|
508
|
+
attr_reader :when_bodies
|
509
|
+
# Body of the `else` branch, `None` if there's no `else` branch
|
510
|
+
#
|
511
|
+
# @return [Node, nil]
|
512
|
+
attr_reader :else_body
|
513
|
+
# Location of the `case` keyword
|
514
|
+
#
|
515
|
+
# ```text
|
516
|
+
# case 1; end
|
517
|
+
# ~~~~
|
518
|
+
# ```
|
519
|
+
#
|
520
|
+
# @return [Loc]
|
521
|
+
attr_reader :keyword_l
|
522
|
+
# Location of the `else` keyword
|
523
|
+
#
|
524
|
+
# ```text
|
525
|
+
# case 1; else; end
|
526
|
+
# ~~~~
|
527
|
+
# ```
|
528
|
+
#
|
529
|
+
# `None` if there's no `else` branch
|
530
|
+
#
|
531
|
+
# @return [Loc, nil]
|
532
|
+
attr_reader :else_l
|
533
|
+
# Location of the `end` keyword
|
534
|
+
#
|
535
|
+
# ```text
|
536
|
+
# case 1; end
|
537
|
+
# ~~~
|
538
|
+
# ```
|
539
|
+
#
|
540
|
+
# @return [Loc]
|
541
|
+
attr_reader :end_l
|
542
|
+
# Location of the full expression
|
543
|
+
#
|
544
|
+
# ```text
|
545
|
+
# case 1; end
|
546
|
+
# ~~~~~~~~~~~
|
547
|
+
# ```
|
548
|
+
#
|
549
|
+
# @return [Loc]
|
550
|
+
attr_reader :expression_l
|
551
|
+
end
|
552
|
+
|
553
|
+
# Represents a `case` statement used for pattern matching (for regular `case` see `Case` node)
|
554
|
+
class CaseMatch < Node
|
555
|
+
# Expression given to `case`, `Int("1")` for `case 1; in 1; end`
|
556
|
+
# `None` for code like
|
557
|
+
#
|
558
|
+
# ```text
|
559
|
+
# case
|
560
|
+
# in pattern
|
561
|
+
# end
|
562
|
+
# ```
|
563
|
+
#
|
564
|
+
# @return [Node]
|
565
|
+
attr_reader :expr
|
566
|
+
# A list of `InPattern` nodes (each has `pattern`, `guard` and `body`)
|
567
|
+
#
|
568
|
+
# @return [::Array<Node>]
|
569
|
+
attr_reader :in_bodies
|
570
|
+
# Body of the `else` branch, `None` if there's no `else` branch
|
571
|
+
#
|
572
|
+
# @return [Node, nil]
|
573
|
+
attr_reader :else_body
|
574
|
+
# Location of the `case` keyword
|
575
|
+
#
|
576
|
+
# ```text
|
577
|
+
# case 1; in 2; end
|
578
|
+
# ~~~~
|
579
|
+
# ```
|
580
|
+
#
|
581
|
+
# @return [Loc]
|
582
|
+
attr_reader :keyword_l
|
583
|
+
# Location of the `else` keyword
|
584
|
+
#
|
585
|
+
# ```text
|
586
|
+
# case 1; in 2; else; end
|
587
|
+
# ~~~~
|
588
|
+
# ```
|
589
|
+
#
|
590
|
+
# `None` if there's no `else` branch
|
591
|
+
#
|
592
|
+
# @return [Loc, nil]
|
593
|
+
attr_reader :else_l
|
594
|
+
# Location of the `end` keyword
|
595
|
+
#
|
596
|
+
# ```text
|
597
|
+
# case 1; in 2; end
|
598
|
+
# ~~~
|
599
|
+
# ```
|
600
|
+
#
|
601
|
+
# @return [Loc]
|
602
|
+
attr_reader :end_l
|
603
|
+
# Location of the full expression
|
604
|
+
#
|
605
|
+
# ```text
|
606
|
+
# case 1; in 2; end
|
607
|
+
# ~~~~~~~~~~~~~~~~~
|
608
|
+
# ```
|
609
|
+
#
|
610
|
+
# @return [Loc]
|
611
|
+
attr_reader :expression_l
|
612
|
+
end
|
613
|
+
|
614
|
+
# Represents a constant assignment (i.e. `A = 1`)
|
615
|
+
class Casgn < Node
|
616
|
+
# Scope where the constant is defined:
|
617
|
+
# 1. `Some(Const("A"))` for `A::B = 1`
|
618
|
+
# 2. `None` if it's defined in the current scope (i.e. `A = 1`)
|
619
|
+
# 3. `Some(Cbase)` if it's defined in the global scope (i.e. `::A = 1`)
|
620
|
+
#
|
621
|
+
# @return [Node, nil]
|
622
|
+
attr_reader :scope
|
623
|
+
# Name of the constant, `String("A")` for `A = 1`
|
624
|
+
#
|
625
|
+
# @return [String]
|
626
|
+
attr_reader :name
|
627
|
+
# Value that is assigned to a constant, `Int("1")` for `A = 1`.
|
628
|
+
#
|
629
|
+
# **Note**: `None` if constant assignment is a part of the multi-assignment.
|
630
|
+
# In such case `value` belongs to `Masgn` node of the multi-assignment.
|
631
|
+
#
|
632
|
+
# @return [Node, nil]
|
633
|
+
attr_reader :value
|
634
|
+
# Location of the `::` operator
|
635
|
+
#
|
636
|
+
# ```text
|
637
|
+
# A::B = 1
|
638
|
+
# ~~
|
639
|
+
#
|
640
|
+
# ::A = 1
|
641
|
+
# ~~
|
642
|
+
# ```
|
643
|
+
#
|
644
|
+
# `None` if the constant is defined in the current scope
|
645
|
+
#
|
646
|
+
# @return [Loc, nil]
|
647
|
+
attr_reader :double_colon_l
|
648
|
+
# Location of the constant name
|
649
|
+
#
|
650
|
+
# ```text
|
651
|
+
# A::CONST = 1
|
652
|
+
# ~~~~~
|
653
|
+
# ```
|
654
|
+
#
|
655
|
+
# @return [Loc]
|
656
|
+
attr_reader :name_l
|
657
|
+
# Location of the `=` operator
|
658
|
+
#
|
659
|
+
# ```text
|
660
|
+
# A = 1
|
661
|
+
# ~
|
662
|
+
# ```
|
663
|
+
#
|
664
|
+
# `None` if constant assignment is a part of the multi-assignment.
|
665
|
+
# In such case `=` belongs to a `Masgn` node
|
666
|
+
#
|
667
|
+
# @return [Loc, nil]
|
668
|
+
attr_reader :operator_l
|
669
|
+
# Location of the full expression
|
670
|
+
#
|
671
|
+
# ```text
|
672
|
+
# A = 1
|
673
|
+
# ~~~~~
|
674
|
+
# ```
|
675
|
+
#
|
676
|
+
# @return [Loc]
|
677
|
+
attr_reader :expression_l
|
678
|
+
end
|
679
|
+
|
680
|
+
# Represents leading `::` part of the constant access/assignment that is used to get/set on a global namespace.
|
681
|
+
class Cbase < Node
|
682
|
+
# Location of the full expression
|
683
|
+
#
|
684
|
+
# ```text
|
685
|
+
# ::A
|
686
|
+
# ~~
|
687
|
+
# ```
|
688
|
+
#
|
689
|
+
# @return [Loc]
|
690
|
+
attr_reader :expression_l
|
691
|
+
end
|
692
|
+
|
693
|
+
# Represents a class definition (using a `class` keyword, `Class.new` is just a method call)
|
694
|
+
class Class < Node
|
695
|
+
# Name of the class, `String("Foo")` for `class Foo; end`
|
696
|
+
#
|
697
|
+
# @return [Node]
|
698
|
+
attr_reader :name
|
699
|
+
# Superclass. Can be an expression in cases like `class A < (obj.foo + 1); end`
|
700
|
+
#
|
701
|
+
# `None` if no explicit superclass given (i.e. `class Foo; end`)
|
702
|
+
#
|
703
|
+
# @return [Node, nil]
|
704
|
+
attr_reader :superclass
|
705
|
+
# Body of the method, `None` if there's no body.
|
706
|
+
#
|
707
|
+
# @return [Node, nil]
|
708
|
+
attr_reader :body
|
709
|
+
# Location of the `class` keyword.
|
710
|
+
#
|
711
|
+
# ```text
|
712
|
+
# class Foo; end
|
713
|
+
# ~~~~~
|
714
|
+
# ```
|
715
|
+
#
|
716
|
+
# @return [Loc]
|
717
|
+
attr_reader :keyword_l
|
718
|
+
# Location of the `<` operator
|
719
|
+
#
|
720
|
+
# ```text
|
721
|
+
# class A < B; end
|
722
|
+
# ~
|
723
|
+
# ```
|
724
|
+
#
|
725
|
+
# `None` if there's no explicit superclass given.
|
726
|
+
#
|
727
|
+
# @return [Loc, nil]
|
728
|
+
attr_reader :operator_l
|
729
|
+
# Location of the `end` keyword.
|
730
|
+
#
|
731
|
+
# ```text
|
732
|
+
# class Foo; end
|
733
|
+
# ~~~
|
734
|
+
# ```
|
735
|
+
#
|
736
|
+
# @return [Loc]
|
737
|
+
attr_reader :end_l
|
738
|
+
# Location of the full expression
|
739
|
+
#
|
740
|
+
# ```text
|
741
|
+
# class Foo; end
|
742
|
+
# ~~~~~~~~~~~~~~
|
743
|
+
# ```
|
744
|
+
#
|
745
|
+
# @return [Loc]
|
746
|
+
attr_reader :expression_l
|
747
|
+
end
|
748
|
+
|
749
|
+
# Represents a `Complex` literal (that returns an `Complex` number)
|
750
|
+
class Complex < Node
|
751
|
+
# Value of the complex literal, returned as a `String`, `String("1i")` for `1i`
|
752
|
+
#
|
753
|
+
# @return [String]
|
754
|
+
attr_reader :value
|
755
|
+
# Location of the `-` (but not `+`) operator. `+` is a part of the literal:
|
756
|
+
# 1. `+1i` is `String("+1i")` with `operator = None`
|
757
|
+
# 2. `-1i` is `String("1i")` with `operator = String("-")`
|
758
|
+
#
|
759
|
+
# ```text
|
760
|
+
# -1i
|
761
|
+
# ~
|
762
|
+
# ```
|
763
|
+
#
|
764
|
+
# @return [Loc, nil]
|
765
|
+
attr_reader :operator_l
|
766
|
+
# Location of the full expression
|
767
|
+
#
|
768
|
+
# ```text
|
769
|
+
# -1i
|
770
|
+
# ~~~
|
771
|
+
# ```
|
772
|
+
#
|
773
|
+
# @return [Loc]
|
774
|
+
attr_reader :expression_l
|
775
|
+
end
|
776
|
+
|
777
|
+
# Represents constant access (i.e. `Foo::Bar`)
|
778
|
+
class Const < Node
|
779
|
+
# Scope where the constant is taken from:
|
780
|
+
# 1. `Some(Const("A"))` for `A::B`
|
781
|
+
# 2. `None` if it's taken from the current scope (i.e. `A`)
|
782
|
+
# 3. `Some(Cbase)` if it's taken from the global scope (i.e. `::A`)
|
783
|
+
#
|
784
|
+
# @return [Node, nil]
|
785
|
+
attr_reader :scope
|
786
|
+
# Name of the constant, `String("Foo")` for `Foo`
|
787
|
+
#
|
788
|
+
# @return [String]
|
789
|
+
attr_reader :name
|
790
|
+
# Location of the `::` operator. `None` if constant is taken from the current scope.
|
791
|
+
#
|
792
|
+
# ```text
|
793
|
+
# A::B
|
794
|
+
# ~~
|
795
|
+
# ```
|
796
|
+
#
|
797
|
+
# @return [Loc, nil]
|
798
|
+
attr_reader :double_colon_l
|
799
|
+
# Location of the constant name
|
800
|
+
#
|
801
|
+
# ```text
|
802
|
+
# Foo::Bar
|
803
|
+
# ~~~
|
804
|
+
# ```
|
805
|
+
#
|
806
|
+
# @return [Loc]
|
807
|
+
attr_reader :name_l
|
808
|
+
# Location of the full expression
|
809
|
+
#
|
810
|
+
# ```text
|
811
|
+
# Foo::Bar
|
812
|
+
# ~~~~~~~~
|
813
|
+
# ```
|
814
|
+
#
|
815
|
+
# @return [Loc]
|
816
|
+
attr_reader :expression_l
|
817
|
+
end
|
818
|
+
|
819
|
+
# Const pattern used in pattern matching (e.g. `in A(1, 2)`)
|
820
|
+
class ConstPattern < Node
|
821
|
+
# Constant that is used, `Const("Foo")` for `in For(42)`
|
822
|
+
#
|
823
|
+
# @return [Node]
|
824
|
+
attr_reader :const
|
825
|
+
# Inner part of the constant pattern
|
826
|
+
#
|
827
|
+
# `ArrayPattern(vec![ Int("1") ])` for `Foo(1)`
|
828
|
+
#
|
829
|
+
# @return [Node]
|
830
|
+
attr_reader :pattern
|
831
|
+
# Location of the open parenthesis
|
832
|
+
#
|
833
|
+
# ```text
|
834
|
+
# case 1; in Foo(42); end
|
835
|
+
# ~
|
836
|
+
# ```
|
837
|
+
#
|
838
|
+
# @return [Loc]
|
839
|
+
attr_reader :begin_l
|
840
|
+
# Location of the closing parenthesis
|
841
|
+
#
|
842
|
+
# ```text
|
843
|
+
# case 1; in Foo(42); end
|
844
|
+
# ~
|
845
|
+
# ```
|
846
|
+
#
|
847
|
+
# @return [Loc]
|
848
|
+
attr_reader :end_l
|
849
|
+
# Location of the full expression
|
850
|
+
#
|
851
|
+
# ```text
|
852
|
+
# case 1; in Foo(42); end
|
853
|
+
# ~~~~~~~
|
854
|
+
# ```
|
855
|
+
#
|
856
|
+
# @return [Loc]
|
857
|
+
attr_reader :expression_l
|
858
|
+
end
|
859
|
+
|
860
|
+
# Represents conditional method call using `&.` operator
|
861
|
+
class CSend < Node
|
862
|
+
# Receiver of the method call, `Int("1")` for `1&.foo`
|
863
|
+
#
|
864
|
+
# @return [Node]
|
865
|
+
attr_reader :recv
|
866
|
+
# Name of the method, `String("foo")` for `1&.foo`
|
867
|
+
#
|
868
|
+
# @return [String]
|
869
|
+
attr_reader :method_name
|
870
|
+
# List of arguments
|
871
|
+
#
|
872
|
+
# ```text
|
873
|
+
# foo&.bar(42)
|
874
|
+
# # and also setters like
|
875
|
+
# foo&.bar = 42
|
876
|
+
# ```
|
877
|
+
#
|
878
|
+
# @return [::Array<Node>]
|
879
|
+
attr_reader :args
|
880
|
+
# Location of the `&.` operator
|
881
|
+
#
|
882
|
+
# ```text
|
883
|
+
# foo&.bar
|
884
|
+
# ~~
|
885
|
+
# ```
|
886
|
+
#
|
887
|
+
# @return [Loc]
|
888
|
+
attr_reader :dot_l
|
889
|
+
# Location of the method name
|
890
|
+
#
|
891
|
+
# ```text
|
892
|
+
# foo&.bar(42)
|
893
|
+
# ~~~
|
894
|
+
# ```
|
895
|
+
#
|
896
|
+
# `None` in a very special case when method call is implicit (i.e. `foo&.()`)
|
897
|
+
#
|
898
|
+
# @return [Loc, nil]
|
899
|
+
attr_reader :selector_l
|
900
|
+
# Location of the open parenthesis
|
901
|
+
#
|
902
|
+
# ```text
|
903
|
+
# foo&.bar(42)
|
904
|
+
# ~
|
905
|
+
# ```
|
906
|
+
#
|
907
|
+
# `None` if there are no parentheses
|
908
|
+
#
|
909
|
+
# @return [Loc, nil]
|
910
|
+
attr_reader :begin_l
|
911
|
+
# Location of the closing parenthesis
|
912
|
+
#
|
913
|
+
# ```text
|
914
|
+
# foo&.bar(42)
|
915
|
+
# ~
|
916
|
+
# ```
|
917
|
+
#
|
918
|
+
# `None` if there are no parentheses
|
919
|
+
#
|
920
|
+
# @return [Loc, nil]
|
921
|
+
attr_reader :end_l
|
922
|
+
# Location of the operator if `CSend` is a part of assignment like
|
923
|
+
#
|
924
|
+
# ```text
|
925
|
+
# foo&.bar = 1
|
926
|
+
# ~
|
927
|
+
# ```
|
928
|
+
#
|
929
|
+
# `None` for a regular call.
|
930
|
+
#
|
931
|
+
# @return [Loc, nil]
|
932
|
+
attr_reader :operator_l
|
933
|
+
# Location of the full expression
|
934
|
+
#
|
935
|
+
# ```text
|
936
|
+
# foo&.bar(42)
|
937
|
+
# ~~~~~~~~~~~~
|
938
|
+
# ```
|
939
|
+
#
|
940
|
+
# @return [Loc]
|
941
|
+
attr_reader :expression_l
|
942
|
+
end
|
943
|
+
|
944
|
+
# Represents access to class variable (i.e. `@@var`)
|
945
|
+
class Cvar < Node
|
946
|
+
# Name of the class variable, `String("@@foo")` for `@@foo`
|
947
|
+
#
|
948
|
+
# @return [String]
|
949
|
+
attr_reader :name
|
950
|
+
# Location of the full expression
|
951
|
+
#
|
952
|
+
# ```text
|
953
|
+
# @@foo
|
954
|
+
# ~~~~~
|
955
|
+
# ```
|
956
|
+
#
|
957
|
+
# @return [Loc]
|
958
|
+
attr_reader :expression_l
|
959
|
+
end
|
960
|
+
|
961
|
+
# Represents class variable assignment (i.e. `@@var = 42`)
|
962
|
+
class Cvasgn < Node
|
963
|
+
# Name of the class variable, `String("@@foo")` for `@@foo = 1`
|
964
|
+
#
|
965
|
+
# @return [String]
|
966
|
+
attr_reader :name
|
967
|
+
# Value that is assigned to class variable, `Int("1")` for `@@foo = 1`
|
968
|
+
#
|
969
|
+
# @return [Node, nil]
|
970
|
+
attr_reader :value
|
971
|
+
# Location of the class variable name
|
972
|
+
#
|
973
|
+
# ```text
|
974
|
+
# @@foo = 1
|
975
|
+
# ~~~~~
|
976
|
+
# ```
|
977
|
+
#
|
978
|
+
# @return [Loc]
|
979
|
+
attr_reader :name_l
|
980
|
+
# Location of the `=` operator
|
981
|
+
#
|
982
|
+
# ```text
|
983
|
+
# @@foo = 1
|
984
|
+
# ~
|
985
|
+
# ```
|
986
|
+
#
|
987
|
+
# @return [Loc, nil]
|
988
|
+
attr_reader :operator_l
|
989
|
+
# Location of the full expression
|
990
|
+
#
|
991
|
+
# ```text
|
992
|
+
# @@foo = 1
|
993
|
+
# ~~~~~~~~~
|
994
|
+
# ```
|
995
|
+
#
|
996
|
+
# @return [Loc]
|
997
|
+
attr_reader :expression_l
|
998
|
+
end
|
999
|
+
|
1000
|
+
# Represents method definition using `def` keyword (not on a singleton, see `Defs` node).
|
1001
|
+
class Def < Node
|
1002
|
+
# Name of the method, `String("foo")` for `def foo; end`
|
1003
|
+
#
|
1004
|
+
# @return [String]
|
1005
|
+
attr_reader :name
|
1006
|
+
# Arguments of a method, `None` if there's no arguments.
|
1007
|
+
#
|
1008
|
+
# All information about parentheses around arguments is stored in this node.
|
1009
|
+
#
|
1010
|
+
# @return [Node, nil]
|
1011
|
+
attr_reader :args
|
1012
|
+
# Body of a method, `None` if there's no body.
|
1013
|
+
#
|
1014
|
+
# @return [Node, nil]
|
1015
|
+
attr_reader :body
|
1016
|
+
# Location of the `def` keyword.
|
1017
|
+
#
|
1018
|
+
# ```text
|
1019
|
+
# def foo; end
|
1020
|
+
# ~~~
|
1021
|
+
# ```
|
1022
|
+
#
|
1023
|
+
# @return [Loc]
|
1024
|
+
attr_reader :keyword_l
|
1025
|
+
# Location of the method name.
|
1026
|
+
#
|
1027
|
+
# ```text
|
1028
|
+
# def foo; end
|
1029
|
+
# ~~~
|
1030
|
+
# ```
|
1031
|
+
#
|
1032
|
+
# @return [Loc]
|
1033
|
+
attr_reader :name_l
|
1034
|
+
# Location of the `end` keyword.
|
1035
|
+
#
|
1036
|
+
# ```text
|
1037
|
+
# def foo; end
|
1038
|
+
# ~~~
|
1039
|
+
# ```
|
1040
|
+
#
|
1041
|
+
# `None` for endless method definition
|
1042
|
+
#
|
1043
|
+
# @return [Loc, nil]
|
1044
|
+
attr_reader :end_l
|
1045
|
+
# Location of the `=` operator for endless method definition
|
1046
|
+
#
|
1047
|
+
# ```text
|
1048
|
+
# def m() = 1
|
1049
|
+
# ~
|
1050
|
+
# ```
|
1051
|
+
#
|
1052
|
+
# `None` for regular method definition
|
1053
|
+
#
|
1054
|
+
# @return [Loc, nil]
|
1055
|
+
attr_reader :assignment_l
|
1056
|
+
# Location of the full expression
|
1057
|
+
#
|
1058
|
+
# ```text
|
1059
|
+
# def m(a); foo; end
|
1060
|
+
# ~~~~~~~~~~~~~~~~~~
|
1061
|
+
# ```
|
1062
|
+
#
|
1063
|
+
# @return [Loc]
|
1064
|
+
attr_reader :expression_l
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
# Represents a `defined?(foo)` expression
|
1068
|
+
class Defined < Node
|
1069
|
+
# Value given to `defined?`
|
1070
|
+
#
|
1071
|
+
# @return [Node]
|
1072
|
+
attr_reader :value
|
1073
|
+
# Location of the `defined?` keyword
|
1074
|
+
#
|
1075
|
+
# ```text
|
1076
|
+
# defined?(foo)
|
1077
|
+
# ~~~~~~~~
|
1078
|
+
# ```
|
1079
|
+
#
|
1080
|
+
# @return [Loc]
|
1081
|
+
attr_reader :keyword_l
|
1082
|
+
# Location of the open parenthesis
|
1083
|
+
#
|
1084
|
+
# ```text
|
1085
|
+
# defined?(foo)
|
1086
|
+
# ~
|
1087
|
+
# ```
|
1088
|
+
#
|
1089
|
+
# `None` if there are no parentheses
|
1090
|
+
#
|
1091
|
+
# @return [Loc, nil]
|
1092
|
+
attr_reader :begin_l
|
1093
|
+
# Location of the closing parenthesis
|
1094
|
+
#
|
1095
|
+
# ```text
|
1096
|
+
# defined?(foo)
|
1097
|
+
# ~
|
1098
|
+
# ```
|
1099
|
+
#
|
1100
|
+
# `None` if there are no parentheses
|
1101
|
+
#
|
1102
|
+
# @return [Loc, nil]
|
1103
|
+
attr_reader :end_l
|
1104
|
+
# Location of the full expression
|
1105
|
+
#
|
1106
|
+
# ```text
|
1107
|
+
# defined?(foo)
|
1108
|
+
# ~~~~~~~~~~~~~
|
1109
|
+
# ```
|
1110
|
+
#
|
1111
|
+
# @return [Loc]
|
1112
|
+
attr_reader :expression_l
|
1113
|
+
end
|
1114
|
+
|
1115
|
+
# Represents a singleton method definition (i.e. `def self.foo; end`)
|
1116
|
+
class Defs < Node
|
1117
|
+
# Definee of a method definition, `Lvar("x")` for `def x.foo; end`
|
1118
|
+
#
|
1119
|
+
# @return [Node]
|
1120
|
+
attr_reader :definee
|
1121
|
+
# Name of the method, `String("foo")` for `def x.foo; end`
|
1122
|
+
#
|
1123
|
+
# @return [String]
|
1124
|
+
attr_reader :name
|
1125
|
+
# Arguments of a method, `None` if there's no arguments.
|
1126
|
+
#
|
1127
|
+
# All information about parentheses around arguments is stored in this node.
|
1128
|
+
#
|
1129
|
+
# @return [Node, nil]
|
1130
|
+
attr_reader :args
|
1131
|
+
# Body of the method, `None` if there's no body.
|
1132
|
+
#
|
1133
|
+
# @return [Node, nil]
|
1134
|
+
attr_reader :body
|
1135
|
+
# Location of the `def` keyword
|
1136
|
+
#
|
1137
|
+
# ```text
|
1138
|
+
# def self.foo; end
|
1139
|
+
# ~~~
|
1140
|
+
# ```
|
1141
|
+
#
|
1142
|
+
# @return [Loc]
|
1143
|
+
attr_reader :keyword_l
|
1144
|
+
# Location of the `.`
|
1145
|
+
#
|
1146
|
+
# ```text
|
1147
|
+
# def self.foo; end
|
1148
|
+
# ~
|
1149
|
+
# ```
|
1150
|
+
#
|
1151
|
+
# @return [Loc]
|
1152
|
+
attr_reader :operator_l
|
1153
|
+
# Location of the method name
|
1154
|
+
#
|
1155
|
+
# ```text
|
1156
|
+
# def self.foo; end
|
1157
|
+
# ~~~
|
1158
|
+
# ```
|
1159
|
+
#
|
1160
|
+
# @return [Loc]
|
1161
|
+
attr_reader :name_l
|
1162
|
+
# Location of the `=` operator for endless method definition
|
1163
|
+
#
|
1164
|
+
# ```text
|
1165
|
+
# def self.foo() = 42
|
1166
|
+
# ~
|
1167
|
+
# ```
|
1168
|
+
#
|
1169
|
+
# `None` for regular method definition
|
1170
|
+
#
|
1171
|
+
# @return [Loc, nil]
|
1172
|
+
attr_reader :assignment_l
|
1173
|
+
# Location of the `end` keyword
|
1174
|
+
#
|
1175
|
+
# ```text
|
1176
|
+
# def self.foo; end
|
1177
|
+
# ~~~
|
1178
|
+
# ```
|
1179
|
+
#
|
1180
|
+
# `None` for endless method definition
|
1181
|
+
#
|
1182
|
+
# @return [Loc, nil]
|
1183
|
+
attr_reader :end_l
|
1184
|
+
# Location of the full expression
|
1185
|
+
#
|
1186
|
+
# ```text
|
1187
|
+
# def self.foo; end
|
1188
|
+
# ~~~~~~~~~~~~~~~~~
|
1189
|
+
# ```
|
1190
|
+
#
|
1191
|
+
# @return [Loc]
|
1192
|
+
attr_reader :expression_l
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
# Represents a string with interpolation (i.e. `"#{foo}"`)
|
1196
|
+
class Dstr < Node
|
1197
|
+
# A list of string parts (static literals and interpolated expressions)
|
1198
|
+
#
|
1199
|
+
# @return [::Array<Node>]
|
1200
|
+
attr_reader :parts
|
1201
|
+
# Location of the string begin
|
1202
|
+
#
|
1203
|
+
# ```text
|
1204
|
+
# "#{foo}"
|
1205
|
+
# ~
|
1206
|
+
#
|
1207
|
+
# %Q{#{foo}}
|
1208
|
+
# ~~~
|
1209
|
+
# ```
|
1210
|
+
#
|
1211
|
+
# @return [Loc, nil]
|
1212
|
+
attr_reader :begin_l
|
1213
|
+
# Location of the string end
|
1214
|
+
#
|
1215
|
+
# ```text
|
1216
|
+
# "#{foo}"
|
1217
|
+
# ~
|
1218
|
+
#
|
1219
|
+
# %Q{#{foo}}
|
1220
|
+
# ~
|
1221
|
+
# ```
|
1222
|
+
#
|
1223
|
+
# @return [Loc, nil]
|
1224
|
+
attr_reader :end_l
|
1225
|
+
# Location of the full expression
|
1226
|
+
#
|
1227
|
+
# ```text
|
1228
|
+
# "#{foo}"
|
1229
|
+
# ~~~~~~~~
|
1230
|
+
#
|
1231
|
+
# %Q{#{foo}}
|
1232
|
+
# ~~~~~~~~~~
|
1233
|
+
# ```
|
1234
|
+
#
|
1235
|
+
# @return [Loc]
|
1236
|
+
attr_reader :expression_l
|
1237
|
+
end
|
1238
|
+
|
1239
|
+
# Represents a symbol with interpolation (i.e. `:"#{foo}"`)
|
1240
|
+
class Dsym < Node
|
1241
|
+
# A list of symbol parts (static literals and interpolated expressions)
|
1242
|
+
#
|
1243
|
+
# @return [::Array<Node>]
|
1244
|
+
attr_reader :parts
|
1245
|
+
# Location of the symbol begin
|
1246
|
+
#
|
1247
|
+
# ```text
|
1248
|
+
# :"#{foo}"
|
1249
|
+
# ~~
|
1250
|
+
# ```
|
1251
|
+
#
|
1252
|
+
# `None` if `Dsym` is a part of the interpolated symbol array:
|
1253
|
+
#
|
1254
|
+
# ```text
|
1255
|
+
# %I[#{bar}]
|
1256
|
+
# ```
|
1257
|
+
#
|
1258
|
+
# @return [Loc, nil]
|
1259
|
+
attr_reader :begin_l
|
1260
|
+
# Location of the symbol begin
|
1261
|
+
#
|
1262
|
+
# ```text
|
1263
|
+
# :"#{foo}"
|
1264
|
+
# ~
|
1265
|
+
# ```
|
1266
|
+
#
|
1267
|
+
# `None` if `Dsym` is a part of the interpolated symbol array:
|
1268
|
+
#
|
1269
|
+
# ```text
|
1270
|
+
# %I[#{bar}]
|
1271
|
+
# ```
|
1272
|
+
#
|
1273
|
+
# @return [Loc, nil]
|
1274
|
+
attr_reader :end_l
|
1275
|
+
# Location of the full expression
|
1276
|
+
#
|
1277
|
+
# ```text
|
1278
|
+
# :"#{foo}"
|
1279
|
+
# ~~~~~~~~~
|
1280
|
+
# ```
|
1281
|
+
#
|
1282
|
+
# @return [Loc]
|
1283
|
+
attr_reader :expression_l
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
# Represents exclusive flip-flop (i.e. in `if foo...bar; end`)
|
1287
|
+
class EFlipFlop < Node
|
1288
|
+
# Left part of the flip-flop. `None` if based on a range without begin (`...bar`)
|
1289
|
+
#
|
1290
|
+
# @return [Node, nil]
|
1291
|
+
attr_reader :left
|
1292
|
+
# Right part of the flip-flop. `None` if based on a range without end (`foo...`)
|
1293
|
+
#
|
1294
|
+
# @return [Node, nil]
|
1295
|
+
attr_reader :right
|
1296
|
+
# Location of the `...` operator
|
1297
|
+
#
|
1298
|
+
# ```text
|
1299
|
+
# if foo...bar; end
|
1300
|
+
# ~~~
|
1301
|
+
# ```
|
1302
|
+
#
|
1303
|
+
# @return [Loc]
|
1304
|
+
attr_reader :operator_l
|
1305
|
+
# Location of the full expression
|
1306
|
+
#
|
1307
|
+
# ```text
|
1308
|
+
# if foo...bar; end
|
1309
|
+
# ~~~~~~~~~
|
1310
|
+
# ```
|
1311
|
+
#
|
1312
|
+
# @return [Loc]
|
1313
|
+
attr_reader :expression_l
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
# Represents a special empty else that is a part of the pattern matching.
|
1317
|
+
#
|
1318
|
+
# Usually empty else (e.g. part of the `if` statement) doesn't mean anything,
|
1319
|
+
# however in pattern matching it prevents raising a `NoPatternError`.
|
1320
|
+
#
|
1321
|
+
# Throwing away this `else` may affect your code.
|
1322
|
+
class EmptyElse < Node
|
1323
|
+
# Location of the `else` keyword
|
1324
|
+
#
|
1325
|
+
# ```text
|
1326
|
+
# case foo; in 1; else; end
|
1327
|
+
# ~~~~
|
1328
|
+
# ```
|
1329
|
+
#
|
1330
|
+
# @return [Loc]
|
1331
|
+
attr_reader :expression_l
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
# Represents a special `__ENCODING__` keyword
|
1335
|
+
class Encoding < Node
|
1336
|
+
# Location of the `__ENCODING__` keyword
|
1337
|
+
#
|
1338
|
+
# ```text
|
1339
|
+
# __ENCODING__
|
1340
|
+
# ~~~~~~~~~~~~
|
1341
|
+
# ```
|
1342
|
+
#
|
1343
|
+
# @return [Loc]
|
1344
|
+
attr_reader :expression_l
|
1345
|
+
end
|
1346
|
+
|
1347
|
+
# Represents a block of code with `ensure` (i.e. `begin; ensure; end`)
|
1348
|
+
class Ensure < Node
|
1349
|
+
# Block of code that is wrapped into `ensure`
|
1350
|
+
# **Note**: that's the body of the `ensure` block
|
1351
|
+
#
|
1352
|
+
# `Int("1")` for `begin; 1; ensure; 2; end`
|
1353
|
+
#
|
1354
|
+
# @return [Node, nil]
|
1355
|
+
attr_reader :body
|
1356
|
+
# Body of the `ensure` block
|
1357
|
+
#
|
1358
|
+
# `Int("2")` for `begin; 1; ensure; 2; end`
|
1359
|
+
#
|
1360
|
+
# @return [Node, nil]
|
1361
|
+
attr_reader :ensure
|
1362
|
+
# Location of the `ensure` keyword
|
1363
|
+
#
|
1364
|
+
# ```text
|
1365
|
+
# begin; ensure; end
|
1366
|
+
# ~~~~~~
|
1367
|
+
# ```
|
1368
|
+
#
|
1369
|
+
# @return [Loc]
|
1370
|
+
attr_reader :keyword_l
|
1371
|
+
# Location of the full expression
|
1372
|
+
#
|
1373
|
+
# ```text
|
1374
|
+
# begin; 1; rescue; 2; else; 3; ensure; 4; end
|
1375
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
1376
|
+
# ```
|
1377
|
+
#
|
1378
|
+
# **Note**: begin/end belong to `KwBegin` node.
|
1379
|
+
#
|
1380
|
+
# @return [Loc]
|
1381
|
+
attr_reader :expression_l
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
# Represents range literal with excluded `end` (i.e. `1...3`)
|
1385
|
+
class Erange < Node
|
1386
|
+
# Begin of the range, `None` if range has no begin (i.e `...42`)
|
1387
|
+
#
|
1388
|
+
# @return [Node, nil]
|
1389
|
+
attr_reader :left
|
1390
|
+
# End of the range, `None` if range has no end (i.e `42...`)
|
1391
|
+
#
|
1392
|
+
# @return [Node, nil]
|
1393
|
+
attr_reader :right
|
1394
|
+
# Location of the `...` operator
|
1395
|
+
#
|
1396
|
+
# ```text
|
1397
|
+
# 1...3
|
1398
|
+
# ~~~
|
1399
|
+
# ```
|
1400
|
+
#
|
1401
|
+
# @return [Loc]
|
1402
|
+
attr_reader :operator_l
|
1403
|
+
# Location of the full expression
|
1404
|
+
#
|
1405
|
+
# ```text
|
1406
|
+
# 1...3
|
1407
|
+
# ~~~~~
|
1408
|
+
# ```
|
1409
|
+
#
|
1410
|
+
# @return [Loc]
|
1411
|
+
attr_reader :expression_l
|
1412
|
+
end
|
1413
|
+
|
1414
|
+
# Represents a `false` literal
|
1415
|
+
class False < Node
|
1416
|
+
# Location of the `false` literal
|
1417
|
+
#
|
1418
|
+
# ```text
|
1419
|
+
# false
|
1420
|
+
# ~~~~~
|
1421
|
+
# ```
|
1422
|
+
#
|
1423
|
+
# @return [Loc]
|
1424
|
+
attr_reader :expression_l
|
1425
|
+
end
|
1426
|
+
|
1427
|
+
# Represents a special `__FILE__` literal
|
1428
|
+
class File < Node
|
1429
|
+
# Location of the `__FILE__` literal
|
1430
|
+
#
|
1431
|
+
# ```text
|
1432
|
+
# __FILE__
|
1433
|
+
# ~~~~~~~~
|
1434
|
+
# ```
|
1435
|
+
#
|
1436
|
+
# @return [Loc]
|
1437
|
+
attr_reader :expression_l
|
1438
|
+
end
|
1439
|
+
|
1440
|
+
# Represents a find pattern using in pattern matching (i.e. `in [*x, 1 => a, *y]`)
|
1441
|
+
#
|
1442
|
+
# It's different from `ArrayPattern`/`ConstPattern` because it supports multiple wildcard pattern
|
1443
|
+
class FindPattern < Node
|
1444
|
+
# Inner part of the find pattern
|
1445
|
+
#
|
1446
|
+
# @return [::Array<Node>]
|
1447
|
+
attr_reader :elements
|
1448
|
+
# Location of the begin
|
1449
|
+
#
|
1450
|
+
# ```text
|
1451
|
+
# case foo; in [*x, 1 => a, *y]; end
|
1452
|
+
# ~
|
1453
|
+
# ```
|
1454
|
+
#
|
1455
|
+
# `None` if there are no brackets/parentheses
|
1456
|
+
#
|
1457
|
+
# @return [Loc, nil]
|
1458
|
+
attr_reader :begin_l
|
1459
|
+
# Location of the end
|
1460
|
+
#
|
1461
|
+
# ```text
|
1462
|
+
# case foo; in [*x, 1 => a, *y]; end
|
1463
|
+
# ~
|
1464
|
+
# ```
|
1465
|
+
#
|
1466
|
+
# `None` if there are no brackets/parentheses
|
1467
|
+
#
|
1468
|
+
# @return [Loc, nil]
|
1469
|
+
attr_reader :end_l
|
1470
|
+
# Location of the full expression
|
1471
|
+
#
|
1472
|
+
# ```text
|
1473
|
+
# case foo; in [*x, 1 => a, *y]; end
|
1474
|
+
# ~~~~~~~~~~~~~~~~
|
1475
|
+
# ```
|
1476
|
+
#
|
1477
|
+
# @return [Loc]
|
1478
|
+
attr_reader :expression_l
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
# Represents a float literal (i.e. `42.5`)
|
1482
|
+
class Float < Node
|
1483
|
+
# String value of the literal, `String("42.5")` for `42.5`
|
1484
|
+
#
|
1485
|
+
# @return [String]
|
1486
|
+
attr_reader :value
|
1487
|
+
# Location of unary `-` (but not `+`)
|
1488
|
+
#
|
1489
|
+
# ```text
|
1490
|
+
# -42.5
|
1491
|
+
# ~
|
1492
|
+
# ```
|
1493
|
+
#
|
1494
|
+
# @return [Loc, nil]
|
1495
|
+
attr_reader :operator_l
|
1496
|
+
# Location of the full expression
|
1497
|
+
#
|
1498
|
+
# ```text
|
1499
|
+
# -42.5
|
1500
|
+
# ~~~~~
|
1501
|
+
# ```
|
1502
|
+
#
|
1503
|
+
# @return [Loc]
|
1504
|
+
attr_reader :expression_l
|
1505
|
+
end
|
1506
|
+
|
1507
|
+
# Represents a `for` loop
|
1508
|
+
class For < Node
|
1509
|
+
# Variable that is used in loop, `Lvasgn("a")` in `for a in b; end`
|
1510
|
+
#
|
1511
|
+
# @return [Node]
|
1512
|
+
attr_reader :iterator
|
1513
|
+
# Collection that is for iteration. `Lvar("b")` in `for a in b; end`
|
1514
|
+
#
|
1515
|
+
# @return [Node]
|
1516
|
+
attr_reader :iteratee
|
1517
|
+
# Body of the loop. `None` if there's no body
|
1518
|
+
#
|
1519
|
+
# @return [Node, nil]
|
1520
|
+
attr_reader :body
|
1521
|
+
# Location of the `for` keyword
|
1522
|
+
#
|
1523
|
+
# ```text
|
1524
|
+
# for a in b; end
|
1525
|
+
# ~~~
|
1526
|
+
# ```
|
1527
|
+
#
|
1528
|
+
# @return [Loc]
|
1529
|
+
attr_reader :keyword_l
|
1530
|
+
# Location of the `in` keyword
|
1531
|
+
#
|
1532
|
+
# ```text
|
1533
|
+
# for a in b; end
|
1534
|
+
# ~~
|
1535
|
+
# ```
|
1536
|
+
#
|
1537
|
+
# @return [Loc]
|
1538
|
+
attr_reader :operator_l
|
1539
|
+
# Location of the `do` keyword
|
1540
|
+
#
|
1541
|
+
# ```text
|
1542
|
+
# for a in b do; end
|
1543
|
+
# ~~
|
1544
|
+
# ```
|
1545
|
+
#
|
1546
|
+
# **Note**: this `do` is optional, and so `begin_l` can be `None`.
|
1547
|
+
#
|
1548
|
+
# @return [Loc]
|
1549
|
+
attr_reader :begin_l
|
1550
|
+
# Location of the `end` keyword
|
1551
|
+
#
|
1552
|
+
# ```text
|
1553
|
+
# for a in b; end
|
1554
|
+
# ~~~
|
1555
|
+
# ```
|
1556
|
+
#
|
1557
|
+
# @return [Loc]
|
1558
|
+
attr_reader :end_l
|
1559
|
+
# Location of the full expression
|
1560
|
+
#
|
1561
|
+
# ```text
|
1562
|
+
# for a in b; end
|
1563
|
+
# ~~~~~~~~~~~~~~~
|
1564
|
+
# ```
|
1565
|
+
#
|
1566
|
+
# @return [Loc]
|
1567
|
+
attr_reader :expression_l
|
1568
|
+
end
|
1569
|
+
|
1570
|
+
# Represents a special `...` argument that forwards positional/keyword/block arguments.
|
1571
|
+
class ForwardArg < Node
|
1572
|
+
# Location of the `...`
|
1573
|
+
#
|
1574
|
+
# ```text
|
1575
|
+
# def m(...); end
|
1576
|
+
# ~~~
|
1577
|
+
# ```
|
1578
|
+
#
|
1579
|
+
# @return [Loc]
|
1580
|
+
attr_reader :expression_l
|
1581
|
+
end
|
1582
|
+
|
1583
|
+
# Represents a `...` operator that contains forwarded argument (see `ForwardArg`)
|
1584
|
+
class ForwardedArgs < Node
|
1585
|
+
# Location of the `...`
|
1586
|
+
#
|
1587
|
+
# ```text
|
1588
|
+
# def m(...); foo(...); end
|
1589
|
+
# ~~~
|
1590
|
+
# ```
|
1591
|
+
#
|
1592
|
+
# @return [Loc]
|
1593
|
+
attr_reader :expression_l
|
1594
|
+
end
|
1595
|
+
|
1596
|
+
# Represents access to global variable (i.e. `$foo`)
|
1597
|
+
class Gvar < Node
|
1598
|
+
# Name of the global variable, `String("$foo")` for `$foo`
|
1599
|
+
#
|
1600
|
+
# @return [String]
|
1601
|
+
attr_reader :name
|
1602
|
+
# Location of the full expression
|
1603
|
+
#
|
1604
|
+
# ```text
|
1605
|
+
# $foo
|
1606
|
+
# ~~~~
|
1607
|
+
# ```
|
1608
|
+
#
|
1609
|
+
# @return [Loc]
|
1610
|
+
attr_reader :expression_l
|
1611
|
+
end
|
1612
|
+
|
1613
|
+
# Represents global variable assignment (i.e. `$foo = 42`)
|
1614
|
+
class Gvasgn < Node
|
1615
|
+
# Name of the global variable, `String("$foo")` for `$foo`
|
1616
|
+
#
|
1617
|
+
# @return [String]
|
1618
|
+
attr_reader :name
|
1619
|
+
# Value that is assigned to global variable, `Int("42")` for `$foo = 42`
|
1620
|
+
#
|
1621
|
+
# `None` if global variable assignment is a part of the multi-assignment.
|
1622
|
+
# In such case `value` is a part of the `Masgn` node.
|
1623
|
+
#
|
1624
|
+
# @return [Node, nil]
|
1625
|
+
attr_reader :value
|
1626
|
+
# Location of the global variable name
|
1627
|
+
#
|
1628
|
+
# ```text
|
1629
|
+
# $foo = 42
|
1630
|
+
# ~~~~
|
1631
|
+
# ```
|
1632
|
+
#
|
1633
|
+
# @return [Loc]
|
1634
|
+
attr_reader :name_l
|
1635
|
+
# Location of the `=` operator
|
1636
|
+
#
|
1637
|
+
# ```text
|
1638
|
+
# $foo = 42
|
1639
|
+
# ~
|
1640
|
+
# ```
|
1641
|
+
#
|
1642
|
+
# `None` if global variable assignment is a part of the multi-assignment.
|
1643
|
+
# In such case `=` operator belongs to the `Masgn` node.
|
1644
|
+
#
|
1645
|
+
# @return [Loc, nil]
|
1646
|
+
attr_reader :operator_l
|
1647
|
+
# Location of the full expression
|
1648
|
+
#
|
1649
|
+
# ```text
|
1650
|
+
# $foo = 42
|
1651
|
+
# ~~~~~~~~~
|
1652
|
+
# ```
|
1653
|
+
#
|
1654
|
+
# @return [Loc]
|
1655
|
+
attr_reader :expression_l
|
1656
|
+
end
|
1657
|
+
|
1658
|
+
# Represents a hash literal (i.e. `{ foo: 42 }`)
|
1659
|
+
class Hash < Node
|
1660
|
+
# A list of key-value pairs
|
1661
|
+
#
|
1662
|
+
# @return [::Array<Node>]
|
1663
|
+
attr_reader :pairs
|
1664
|
+
# Location of the open parenthesis
|
1665
|
+
#
|
1666
|
+
# ```text
|
1667
|
+
# { a: 1 }
|
1668
|
+
# ~
|
1669
|
+
# ```
|
1670
|
+
#
|
1671
|
+
# `None` if hash literal is implicit, e.g. `foo(key: "value")`
|
1672
|
+
#
|
1673
|
+
# @return [Loc, nil]
|
1674
|
+
attr_reader :begin_l
|
1675
|
+
# Location of the closing parenthesis
|
1676
|
+
#
|
1677
|
+
# ```text
|
1678
|
+
# { a: 1 }
|
1679
|
+
# ~
|
1680
|
+
# ```
|
1681
|
+
#
|
1682
|
+
# `None` if hash literal is implicit, e.g. `foo(key: "value")`
|
1683
|
+
#
|
1684
|
+
# @return [Loc, nil]
|
1685
|
+
attr_reader :end_l
|
1686
|
+
# Location of the full expression
|
1687
|
+
#
|
1688
|
+
# ```text
|
1689
|
+
# { a: 1 }
|
1690
|
+
# ~~~~~~~~
|
1691
|
+
# ```
|
1692
|
+
#
|
1693
|
+
# @return [Loc]
|
1694
|
+
attr_reader :expression_l
|
1695
|
+
end
|
1696
|
+
|
1697
|
+
# Represents a hash pattern used in pattern matching (i.e. `in { a: 1 }`)
|
1698
|
+
class HashPattern < Node
|
1699
|
+
# A list of inner patterns
|
1700
|
+
#
|
1701
|
+
# @return [::Array<Node>]
|
1702
|
+
attr_reader :elements
|
1703
|
+
# Location of the open parenthesis
|
1704
|
+
#
|
1705
|
+
# ```text
|
1706
|
+
# case foo; in { a: 1 }; end
|
1707
|
+
# ~
|
1708
|
+
# ```
|
1709
|
+
#
|
1710
|
+
# `None` if there are no parentheses
|
1711
|
+
#
|
1712
|
+
# @return [Loc, nil]
|
1713
|
+
attr_reader :begin_l
|
1714
|
+
# Location of the open parenthesis
|
1715
|
+
#
|
1716
|
+
# ```text
|
1717
|
+
# case foo; in { a: 1 }; end
|
1718
|
+
# ~
|
1719
|
+
# ```
|
1720
|
+
#
|
1721
|
+
# `None` if there are no parentheses
|
1722
|
+
#
|
1723
|
+
# @return [Loc, nil]
|
1724
|
+
attr_reader :end_l
|
1725
|
+
# Location of the full expression
|
1726
|
+
#
|
1727
|
+
# ```text
|
1728
|
+
# case foo; in { a: 1 }; end
|
1729
|
+
# ~~~~~~~~
|
1730
|
+
# ```
|
1731
|
+
#
|
1732
|
+
# @return [Loc]
|
1733
|
+
attr_reader :expression_l
|
1734
|
+
end
|
1735
|
+
|
1736
|
+
# Represents a here-document literal (both with and without interpolation)
|
1737
|
+
#
|
1738
|
+
# It's similar to `Dstr` in terms of abstract syntax tree, but has different source maps.
|
1739
|
+
class Heredoc < Node
|
1740
|
+
# A list of string parts (static literals and interpolated expressions)
|
1741
|
+
#
|
1742
|
+
# @return [::Array<Node>]
|
1743
|
+
attr_reader :parts
|
1744
|
+
# Location of the here-document body
|
1745
|
+
#
|
1746
|
+
# ```text
|
1747
|
+
# <<-HERE\n a\n #{42}\nHERE
|
1748
|
+
# ~~~~~~~~~~~~~~~
|
1749
|
+
# ```
|
1750
|
+
#
|
1751
|
+
# @return [Loc]
|
1752
|
+
attr_reader :heredoc_body_l
|
1753
|
+
# Location of the here-document end
|
1754
|
+
#
|
1755
|
+
# ```text
|
1756
|
+
# <<-HERE\n a\n #{42}\nHERE
|
1757
|
+
# ~~~~
|
1758
|
+
# ```
|
1759
|
+
#
|
1760
|
+
# @return [Loc]
|
1761
|
+
attr_reader :heredoc_end_l
|
1762
|
+
# Location of the here-document identifier
|
1763
|
+
#
|
1764
|
+
# ```text
|
1765
|
+
# <<-HERE\n a\n #{42}\nHERE
|
1766
|
+
# ~~~~~~~
|
1767
|
+
# ```
|
1768
|
+
#
|
1769
|
+
# **Note**: This is the only node (with `XHeredoc`) that has `expression_l` smaller that all other sub-locations merged.
|
1770
|
+
# The reason for that is that it's possible to add more code after here-document ID:
|
1771
|
+
#
|
1772
|
+
# ```text
|
1773
|
+
# <<-HERE + "rest"
|
1774
|
+
# content
|
1775
|
+
# HERE
|
1776
|
+
# ```
|
1777
|
+
#
|
1778
|
+
# @return [Loc]
|
1779
|
+
attr_reader :expression_l
|
1780
|
+
end
|
1781
|
+
|
1782
|
+
# Represents an `if` statement (i.e. `if foo; bar; else; baz; end`)
|
1783
|
+
class If < Node
|
1784
|
+
# Condition given to the `if` statement, `Lvar("a")` for `if a; b; else; c; end`
|
1785
|
+
#
|
1786
|
+
# @return [Node]
|
1787
|
+
attr_reader :cond
|
1788
|
+
# True-branch of the `if` statement, `Lvar("b")` for `if a; b; else; c; end`
|
1789
|
+
#
|
1790
|
+
# @return [Node, nil]
|
1791
|
+
attr_reader :if_true
|
1792
|
+
# False-branch of the `if` statement, `Lvar("c")` for `if a; b; else; c; end`
|
1793
|
+
#
|
1794
|
+
# @return [Node, nil]
|
1795
|
+
attr_reader :if_false
|
1796
|
+
# Location of the `if` keyword
|
1797
|
+
#
|
1798
|
+
# ```text
|
1799
|
+
# if foo; end
|
1800
|
+
# ~~
|
1801
|
+
# ```
|
1802
|
+
#
|
1803
|
+
# @return [Loc]
|
1804
|
+
attr_reader :keyword_l
|
1805
|
+
# Location of the `then` keyword
|
1806
|
+
#
|
1807
|
+
# ```text
|
1808
|
+
# if foo then; end
|
1809
|
+
# ~~~~
|
1810
|
+
# ```
|
1811
|
+
#
|
1812
|
+
# `None` if `then` keyword is omitted
|
1813
|
+
#
|
1814
|
+
# @return [Loc]
|
1815
|
+
attr_reader :begin_l
|
1816
|
+
# Location of the `else` keyword
|
1817
|
+
#
|
1818
|
+
# ```text
|
1819
|
+
# if foo; else; end
|
1820
|
+
# ~~~~
|
1821
|
+
# ```
|
1822
|
+
#
|
1823
|
+
# `None` if there's no `else` branch
|
1824
|
+
#
|
1825
|
+
# @return [Loc, nil]
|
1826
|
+
attr_reader :else_l
|
1827
|
+
# Location of the `end` keyword
|
1828
|
+
#
|
1829
|
+
# ```text
|
1830
|
+
# if foo; end
|
1831
|
+
# ~~~
|
1832
|
+
# ```
|
1833
|
+
#
|
1834
|
+
# @return [Loc, nil]
|
1835
|
+
attr_reader :end_l
|
1836
|
+
# Location of the full expression
|
1837
|
+
#
|
1838
|
+
# ```text
|
1839
|
+
# if a then; b; else; c end
|
1840
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
|
1841
|
+
# ```
|
1842
|
+
#
|
1843
|
+
# @return [Loc]
|
1844
|
+
attr_reader :expression_l
|
1845
|
+
end
|
1846
|
+
|
1847
|
+
# Represents an `if` guard used in pattern matching (i.e. `case foo; in pattern if guard; end`)
|
1848
|
+
class IfGuard < Node
|
1849
|
+
# Condition of the guard, `Lvar("foo")` in `in pattern if guard`
|
1850
|
+
#
|
1851
|
+
# @return [Node]
|
1852
|
+
attr_reader :cond
|
1853
|
+
# Location of the `if` keyword
|
1854
|
+
#
|
1855
|
+
# ```text
|
1856
|
+
# case foo; in pattern if cond; end
|
1857
|
+
# ~~
|
1858
|
+
# ```
|
1859
|
+
#
|
1860
|
+
# @return [Loc]
|
1861
|
+
attr_reader :keyword_l
|
1862
|
+
# Location of the full expression
|
1863
|
+
#
|
1864
|
+
# ```text
|
1865
|
+
# case foo; in pattern if cond; end
|
1866
|
+
# ~~~~~~~
|
1867
|
+
# ```
|
1868
|
+
#
|
1869
|
+
# @return [Loc]
|
1870
|
+
attr_reader :expression_l
|
1871
|
+
end
|
1872
|
+
|
1873
|
+
# Represents inclusive flip-flop (i.e. in `if foo..bar; end`)
|
1874
|
+
class IFlipFlop < Node
|
1875
|
+
# Left part of the flip-flop. `None` if based on a range without begin (`..bar`)
|
1876
|
+
#
|
1877
|
+
# @return [Node, nil]
|
1878
|
+
attr_reader :left
|
1879
|
+
# Right part of the flip-flop. `None` if based on a range without end (`foo..`)
|
1880
|
+
#
|
1881
|
+
# @return [Node, nil]
|
1882
|
+
attr_reader :right
|
1883
|
+
# Location of the `..` operator
|
1884
|
+
#
|
1885
|
+
# ```text
|
1886
|
+
# if foo..bar; end
|
1887
|
+
# ~~
|
1888
|
+
# ```
|
1889
|
+
#
|
1890
|
+
# @return [Loc]
|
1891
|
+
attr_reader :operator_l
|
1892
|
+
# Location of the full expression
|
1893
|
+
#
|
1894
|
+
# ```text
|
1895
|
+
# if foo..bar; end
|
1896
|
+
# ~~~~~~~~
|
1897
|
+
# ```
|
1898
|
+
#
|
1899
|
+
# @return [Loc]
|
1900
|
+
attr_reader :expression_l
|
1901
|
+
end
|
1902
|
+
|
1903
|
+
# Represents an `if`/`unless` modifier (i.e. `stmt if cond`)
|
1904
|
+
class IfMod < Node
|
1905
|
+
# Condition of the modifier
|
1906
|
+
#
|
1907
|
+
# @return [Node]
|
1908
|
+
attr_reader :cond
|
1909
|
+
# True-branch of the modifier.
|
1910
|
+
#
|
1911
|
+
# Always set for `if` modifier.
|
1912
|
+
# Always `None` for `unless` modifier.
|
1913
|
+
#
|
1914
|
+
# @return [Node, nil]
|
1915
|
+
attr_reader :if_true
|
1916
|
+
# False-branch of the modifier.
|
1917
|
+
#
|
1918
|
+
# Always set for `unless` modifier.
|
1919
|
+
# Always `None` for `if` modifier.
|
1920
|
+
#
|
1921
|
+
# @return [Node, nil]
|
1922
|
+
attr_reader :if_false
|
1923
|
+
# Location of the `if`/`unless` keyword
|
1924
|
+
#
|
1925
|
+
# ```text
|
1926
|
+
# stmt if cond
|
1927
|
+
# ~~
|
1928
|
+
#
|
1929
|
+
# stmt unless cond
|
1930
|
+
# ~~~~~~
|
1931
|
+
# ```
|
1932
|
+
#
|
1933
|
+
# @return [Loc]
|
1934
|
+
attr_reader :keyword_l
|
1935
|
+
# Location of the full expression
|
1936
|
+
#
|
1937
|
+
# ```text
|
1938
|
+
# stmt if cond
|
1939
|
+
# ~~~~~~~~~~~~
|
1940
|
+
#
|
1941
|
+
# stmt unless cond
|
1942
|
+
# ~~~~~~~~~~~~~~~~
|
1943
|
+
# ```
|
1944
|
+
#
|
1945
|
+
# @return [Loc]
|
1946
|
+
attr_reader :expression_l
|
1947
|
+
end
|
1948
|
+
|
1949
|
+
# Represents ternary `if` statement (i.e. `cond ? if_true : if_false`)
|
1950
|
+
class IfTernary < Node
|
1951
|
+
# Condition of the `if` statement
|
1952
|
+
#
|
1953
|
+
# @return [Node]
|
1954
|
+
attr_reader :cond
|
1955
|
+
# True-branch
|
1956
|
+
#
|
1957
|
+
# @return [Node]
|
1958
|
+
attr_reader :if_true
|
1959
|
+
# True-branch
|
1960
|
+
#
|
1961
|
+
# @return [Node]
|
1962
|
+
attr_reader :if_false
|
1963
|
+
# Location of the `?` operator
|
1964
|
+
#
|
1965
|
+
# ```text
|
1966
|
+
# cond ? if_true : if_false
|
1967
|
+
# ~
|
1968
|
+
# ```
|
1969
|
+
#
|
1970
|
+
# @return [Loc]
|
1971
|
+
attr_reader :question_l
|
1972
|
+
# Location of the `:` operator
|
1973
|
+
#
|
1974
|
+
# ```text
|
1975
|
+
# cond ? if_true : if_false
|
1976
|
+
# ~
|
1977
|
+
# ```
|
1978
|
+
#
|
1979
|
+
# @return [Loc]
|
1980
|
+
attr_reader :colon_l
|
1981
|
+
# Location of the full expression
|
1982
|
+
#
|
1983
|
+
# ```text
|
1984
|
+
# cond ? if_true : if_false
|
1985
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
|
1986
|
+
# ```
|
1987
|
+
#
|
1988
|
+
# @return [Loc]
|
1989
|
+
attr_reader :expression_l
|
1990
|
+
end
|
1991
|
+
|
1992
|
+
# Represents indexing operation (i.e. `foo[1,2,3]`)
|
1993
|
+
class Index < Node
|
1994
|
+
# Receiver of indexing
|
1995
|
+
#
|
1996
|
+
# @return [Node]
|
1997
|
+
attr_reader :recv
|
1998
|
+
# A list of indexes
|
1999
|
+
#
|
2000
|
+
# @return [::Array<Node>]
|
2001
|
+
attr_reader :indexes
|
2002
|
+
# Location of open bracket
|
2003
|
+
#
|
2004
|
+
# ```text
|
2005
|
+
# foo[1, 2, 3]
|
2006
|
+
# ~
|
2007
|
+
# ```
|
2008
|
+
#
|
2009
|
+
# @return [Loc]
|
2010
|
+
attr_reader :begin_l
|
2011
|
+
# Location of closing bracket
|
2012
|
+
#
|
2013
|
+
# ```text
|
2014
|
+
# foo[1, 2, 3]
|
2015
|
+
# ~
|
2016
|
+
# ```
|
2017
|
+
#
|
2018
|
+
# @return [Loc]
|
2019
|
+
attr_reader :end_l
|
2020
|
+
# Location of the full expression
|
2021
|
+
#
|
2022
|
+
# ```text
|
2023
|
+
# foo[1, 2, 3]
|
2024
|
+
# ~~~~~~~~~~~~
|
2025
|
+
# ```
|
2026
|
+
#
|
2027
|
+
# @return [Loc]
|
2028
|
+
attr_reader :expression_l
|
2029
|
+
end
|
2030
|
+
|
2031
|
+
# Represents assignment using indexing operation (i.e. `foo[1, 2, 3] = bar`)
|
2032
|
+
class IndexAsgn < Node
|
2033
|
+
# Receiver of the indexing
|
2034
|
+
#
|
2035
|
+
# @return [Node]
|
2036
|
+
attr_reader :recv
|
2037
|
+
# A list of indexes
|
2038
|
+
#
|
2039
|
+
# @return [::Array<Node>]
|
2040
|
+
attr_reader :indexes
|
2041
|
+
# Value that is assigned
|
2042
|
+
#
|
2043
|
+
# `None` if assignment is a part of the multi-assignment.
|
2044
|
+
# In such case `value` belongs to `Masgn` node.
|
2045
|
+
#
|
2046
|
+
# @return [Node, nil]
|
2047
|
+
attr_reader :value
|
2048
|
+
# Location of open bracket
|
2049
|
+
#
|
2050
|
+
# ```text
|
2051
|
+
# foo[1, 2, 3] = bar
|
2052
|
+
# ~
|
2053
|
+
# ```
|
2054
|
+
#
|
2055
|
+
# @return [Loc]
|
2056
|
+
attr_reader :begin_l
|
2057
|
+
# Location of closing bracket
|
2058
|
+
#
|
2059
|
+
# ```text
|
2060
|
+
# foo[1, 2, 3] = bar
|
2061
|
+
# ~
|
2062
|
+
# ```
|
2063
|
+
#
|
2064
|
+
# @return [Loc]
|
2065
|
+
attr_reader :end_l
|
2066
|
+
# Location of the `=` operator
|
2067
|
+
#
|
2068
|
+
# ```text
|
2069
|
+
# foo[1, 2, 3] = bar
|
2070
|
+
# ~
|
2071
|
+
# ```
|
2072
|
+
#
|
2073
|
+
# `None` if assignment is a part of the multi-assignment.
|
2074
|
+
# In such case operator `=` belongs to `Masgn` node.
|
2075
|
+
#
|
2076
|
+
# @return [Loc, nil]
|
2077
|
+
attr_reader :operator_l
|
2078
|
+
# Location of the full expression
|
2079
|
+
#
|
2080
|
+
# ```text
|
2081
|
+
# foo[1, 2, 3] = bar
|
2082
|
+
# ~~~~~~~~~~~~~~~~~~
|
2083
|
+
# ```
|
2084
|
+
#
|
2085
|
+
# @return [Loc]
|
2086
|
+
attr_reader :expression_l
|
2087
|
+
end
|
2088
|
+
|
2089
|
+
# Represents an `in pattern` branch of the pattern matching
|
2090
|
+
class InPattern < Node
|
2091
|
+
# Value that is used for matching
|
2092
|
+
#
|
2093
|
+
# @return [Node]
|
2094
|
+
attr_reader :pattern
|
2095
|
+
# Guard that is used for matching
|
2096
|
+
#
|
2097
|
+
# Optional, so can be `None`
|
2098
|
+
#
|
2099
|
+
# @return [Node, nil]
|
2100
|
+
attr_reader :guard
|
2101
|
+
# Body of the branch that is invoked if value matches pattern
|
2102
|
+
#
|
2103
|
+
# @return [Node, nil]
|
2104
|
+
attr_reader :body
|
2105
|
+
# Location of the `in` keyword
|
2106
|
+
#
|
2107
|
+
# ```text
|
2108
|
+
# case value; in pattern; end
|
2109
|
+
# ~~
|
2110
|
+
# ```
|
2111
|
+
#
|
2112
|
+
# @return [Loc]
|
2113
|
+
attr_reader :keyword_l
|
2114
|
+
# Location of the `then` keyword
|
2115
|
+
#
|
2116
|
+
# ```text
|
2117
|
+
# case value; in pattern then; end
|
2118
|
+
# ~~~~
|
2119
|
+
# ```
|
2120
|
+
#
|
2121
|
+
# @return [Loc]
|
2122
|
+
attr_reader :begin_l
|
2123
|
+
# Location of the full expression
|
2124
|
+
#
|
2125
|
+
# ```text
|
2126
|
+
# case value; in pattern then; 42; end
|
2127
|
+
# ~~~~~~~~~~~~~~~~~~~
|
2128
|
+
# ```
|
2129
|
+
#
|
2130
|
+
# @return [Loc]
|
2131
|
+
attr_reader :expression_l
|
2132
|
+
end
|
2133
|
+
|
2134
|
+
# Represents an integer literal (i.e. `42`)
|
2135
|
+
class Int < Node
|
2136
|
+
# String value of the literal, `String("42")` for `42`
|
2137
|
+
#
|
2138
|
+
# @return [String]
|
2139
|
+
attr_reader :value
|
2140
|
+
# Location of unary `-` (but not `+`)
|
2141
|
+
#
|
2142
|
+
# ```text
|
2143
|
+
# -42
|
2144
|
+
# ~
|
2145
|
+
# ```
|
2146
|
+
#
|
2147
|
+
# @return [Loc, nil]
|
2148
|
+
attr_reader :operator_l
|
2149
|
+
# Location of the full expression
|
2150
|
+
#
|
2151
|
+
# ```text
|
2152
|
+
# -42
|
2153
|
+
# ~~~
|
2154
|
+
# ```
|
2155
|
+
#
|
2156
|
+
# @return [Loc]
|
2157
|
+
attr_reader :expression_l
|
2158
|
+
end
|
2159
|
+
|
2160
|
+
# Represents inclusive range (i.e. `2..4`)
|
2161
|
+
class Irange < Node
|
2162
|
+
# Begin of the range, `None` if range has no `begin` (i.e. `..4`)
|
2163
|
+
#
|
2164
|
+
# @return [Node, nil]
|
2165
|
+
attr_reader :left
|
2166
|
+
# End of the range, `None` if range has no `end` (i.e. `2..`)
|
2167
|
+
#
|
2168
|
+
# @return [Node, nil]
|
2169
|
+
attr_reader :right
|
2170
|
+
# Location of the `..` operator
|
2171
|
+
#
|
2172
|
+
# ```text
|
2173
|
+
# 2..4
|
2174
|
+
# ~~
|
2175
|
+
# ```
|
2176
|
+
#
|
2177
|
+
# @return [Loc]
|
2178
|
+
attr_reader :operator_l
|
2179
|
+
# Location of the full expression
|
2180
|
+
#
|
2181
|
+
# ```text
|
2182
|
+
# 2..4
|
2183
|
+
# ~~~~
|
2184
|
+
# ```
|
2185
|
+
#
|
2186
|
+
# @return [Loc]
|
2187
|
+
attr_reader :expression_l
|
2188
|
+
end
|
2189
|
+
|
2190
|
+
# Represents access to instance variable (i.e. `@foo`)
|
2191
|
+
class Ivar < Node
|
2192
|
+
# Name of the instance variable, `String("@foo")` in `@foo`
|
2193
|
+
#
|
2194
|
+
# @return [String]
|
2195
|
+
attr_reader :name
|
2196
|
+
# Location of the full expression
|
2197
|
+
#
|
2198
|
+
# ```text
|
2199
|
+
# @foo
|
2200
|
+
# ~~~~
|
2201
|
+
# ```
|
2202
|
+
#
|
2203
|
+
# @return [Loc]
|
2204
|
+
attr_reader :expression_l
|
2205
|
+
end
|
2206
|
+
|
2207
|
+
# Represents instance variable assignment (i.e `@foo = 42`)
|
2208
|
+
class Ivasgn < Node
|
2209
|
+
# Name of the instance variable, `String("@foo")` in `@foo = 42`
|
2210
|
+
#
|
2211
|
+
# @return [String]
|
2212
|
+
attr_reader :name
|
2213
|
+
# Value that is assigned to instance variable.
|
2214
|
+
#
|
2215
|
+
# `None` if instance variable assignment is a part of the multi-assignment.
|
2216
|
+
# In such case `value` is a part of the `Masgn` node.
|
2217
|
+
#
|
2218
|
+
# @return [Node, nil]
|
2219
|
+
attr_reader :value
|
2220
|
+
# Location of the instance variable name.
|
2221
|
+
#
|
2222
|
+
# ```text
|
2223
|
+
# @foo = 1
|
2224
|
+
# ~~~~
|
2225
|
+
# ```
|
2226
|
+
#
|
2227
|
+
# @return [Loc]
|
2228
|
+
attr_reader :name_l
|
2229
|
+
# Location of the `=` operator.
|
2230
|
+
#
|
2231
|
+
# ```text
|
2232
|
+
# @foo = 1
|
2233
|
+
# ~
|
2234
|
+
# ```
|
2235
|
+
#
|
2236
|
+
# `None` if instance variable assignment is a part of the multi-assignment.
|
2237
|
+
# In such case `value` is a part of the `Masgn` node.
|
2238
|
+
#
|
2239
|
+
# @return [Loc, nil]
|
2240
|
+
attr_reader :operator_l
|
2241
|
+
# Location of the full expression
|
2242
|
+
#
|
2243
|
+
# ```text
|
2244
|
+
# @foo = 42
|
2245
|
+
# ~~~~~~~~~
|
2246
|
+
# ```
|
2247
|
+
#
|
2248
|
+
# @return [Loc]
|
2249
|
+
attr_reader :expression_l
|
2250
|
+
end
|
2251
|
+
|
2252
|
+
# Represents required keyword argument (i.e. `foo` in `def m(foo:); end`)
|
2253
|
+
class Kwarg < Node
|
2254
|
+
# Name of the keyword argument
|
2255
|
+
#
|
2256
|
+
# @return [String]
|
2257
|
+
attr_reader :name
|
2258
|
+
# Location of the name
|
2259
|
+
#
|
2260
|
+
# ```text
|
2261
|
+
# def foo(bar:); end
|
2262
|
+
# ~~~
|
2263
|
+
# ```
|
2264
|
+
#
|
2265
|
+
# @return [Loc]
|
2266
|
+
attr_reader :name_l
|
2267
|
+
# Location of the full expression
|
2268
|
+
#
|
2269
|
+
# ```text
|
2270
|
+
# def foo(bar:); end
|
2271
|
+
# ~~~~
|
2272
|
+
# ```
|
2273
|
+
#
|
2274
|
+
# @return [Loc]
|
2275
|
+
attr_reader :expression_l
|
2276
|
+
end
|
2277
|
+
|
2278
|
+
# Represents kwargs that are given to a method call, super or yield (i.e. `foo(bar: 1)`)
|
2279
|
+
class Kwargs < Node
|
2280
|
+
# A list of key-value pairs
|
2281
|
+
#
|
2282
|
+
# @return [::Array<Node>]
|
2283
|
+
attr_reader :pairs
|
2284
|
+
# Location of the full expression
|
2285
|
+
#
|
2286
|
+
# ```text
|
2287
|
+
# foo(bar: 1)
|
2288
|
+
# ~~~~~~
|
2289
|
+
# ```
|
2290
|
+
#
|
2291
|
+
# @return [Loc]
|
2292
|
+
attr_reader :expression_l
|
2293
|
+
end
|
2294
|
+
|
2295
|
+
# Represents an explicit `begin; end` block.
|
2296
|
+
#
|
2297
|
+
# The reason why it's different is that
|
2298
|
+
# ```text
|
2299
|
+
# begin; foo; end while cond
|
2300
|
+
# ```
|
2301
|
+
# is a post-while loop (same with post-until loop)
|
2302
|
+
class KwBegin < Node
|
2303
|
+
# A list of statements
|
2304
|
+
#
|
2305
|
+
# @return [::Array<Node>]
|
2306
|
+
attr_reader :statements
|
2307
|
+
# Location of the `begin` keyword
|
2308
|
+
#
|
2309
|
+
# ```text
|
2310
|
+
# begin; foo; end
|
2311
|
+
# ~~~~~
|
2312
|
+
# ```
|
2313
|
+
#
|
2314
|
+
# @return [Loc, nil]
|
2315
|
+
attr_reader :begin_l
|
2316
|
+
# Location of the `end` keyword
|
2317
|
+
#
|
2318
|
+
# ```text
|
2319
|
+
# begin; foo; end
|
2320
|
+
# ~~~
|
2321
|
+
# ```
|
2322
|
+
#
|
2323
|
+
# @return [Loc, nil]
|
2324
|
+
attr_reader :end_l
|
2325
|
+
# Location of the full expression
|
2326
|
+
#
|
2327
|
+
# ```text
|
2328
|
+
# begin; foo; bar
|
2329
|
+
# ~~~~~~~~~~~~~~~
|
2330
|
+
# ```
|
2331
|
+
#
|
2332
|
+
# @return [Loc]
|
2333
|
+
attr_reader :expression_l
|
2334
|
+
end
|
2335
|
+
|
2336
|
+
# Represents an special argument that rejects all keyword arguments (i.e. `def m(**nil); end`)
|
2337
|
+
class Kwnilarg < Node
|
2338
|
+
# Location of the `nil`
|
2339
|
+
#
|
2340
|
+
# ```text
|
2341
|
+
# def m(**nil); end
|
2342
|
+
# ~~~
|
2343
|
+
# ```
|
2344
|
+
#
|
2345
|
+
# @return [Loc]
|
2346
|
+
attr_reader :name_l
|
2347
|
+
# Location of the `nil`
|
2348
|
+
#
|
2349
|
+
# ```text
|
2350
|
+
# def m(**nil); end
|
2351
|
+
# ~~~~~
|
2352
|
+
# ```
|
2353
|
+
#
|
2354
|
+
# @return [Loc]
|
2355
|
+
attr_reader :expression_l
|
2356
|
+
end
|
2357
|
+
|
2358
|
+
# Represents an optional keyword argument (i.e. `foo` in `def m(foo: 42); end`)
|
2359
|
+
class Kwoptarg < Node
|
2360
|
+
# Name of the optional keyword argument
|
2361
|
+
#
|
2362
|
+
# @return [String]
|
2363
|
+
attr_reader :name
|
2364
|
+
# Default value of the optional keyword argument
|
2365
|
+
#
|
2366
|
+
# @return [Node]
|
2367
|
+
attr_reader :default
|
2368
|
+
# Location of the argument name
|
2369
|
+
#
|
2370
|
+
# ```text
|
2371
|
+
# def m(foo: 1); end
|
2372
|
+
# ~~~
|
2373
|
+
# ```
|
2374
|
+
#
|
2375
|
+
# @return [Loc]
|
2376
|
+
attr_reader :name_l
|
2377
|
+
# Location of the argument name
|
2378
|
+
#
|
2379
|
+
# ```text
|
2380
|
+
# def m(foo: 1); end
|
2381
|
+
# ~~~~~~
|
2382
|
+
# ```
|
2383
|
+
#
|
2384
|
+
# @return [Loc]
|
2385
|
+
attr_reader :expression_l
|
2386
|
+
end
|
2387
|
+
|
2388
|
+
# Represents a keyword rest argument (i.e. `foo` in `def m(**foo); end`)
|
2389
|
+
class Kwrestarg < Node
|
2390
|
+
# Name of the keyword rest argument, `String("foo")` in `def m(**foo); end`.
|
2391
|
+
#
|
2392
|
+
# `None` if argument has no name (`def m(**); end`)
|
2393
|
+
#
|
2394
|
+
# @return [String, nil]
|
2395
|
+
attr_reader :name
|
2396
|
+
# Location of the `**` operator
|
2397
|
+
#
|
2398
|
+
# ```text
|
2399
|
+
# def m(**foo); end
|
2400
|
+
# ~~
|
2401
|
+
# ```
|
2402
|
+
#
|
2403
|
+
# @return [Loc]
|
2404
|
+
attr_reader :operator_l
|
2405
|
+
# Location of the argument name
|
2406
|
+
#
|
2407
|
+
# ```text
|
2408
|
+
# def m(**foo); end
|
2409
|
+
# ~~~
|
2410
|
+
# ```
|
2411
|
+
#
|
2412
|
+
# `None` if argument has no name (`def m(**); end`)
|
2413
|
+
#
|
2414
|
+
# @return [Loc, nil]
|
2415
|
+
attr_reader :name_l
|
2416
|
+
# Location of the full expression
|
2417
|
+
#
|
2418
|
+
# ```text
|
2419
|
+
# def m(**foo); end
|
2420
|
+
# ~~~~~
|
2421
|
+
# ```
|
2422
|
+
#
|
2423
|
+
# @return [Loc]
|
2424
|
+
attr_reader :expression_l
|
2425
|
+
end
|
2426
|
+
|
2427
|
+
# Represents a keyword arguments splat (i.e. `**bar` in a call like `foo(**bar)`)
|
2428
|
+
class Kwsplat < Node
|
2429
|
+
# Value that is converted into a `Hash` using `**`
|
2430
|
+
#
|
2431
|
+
# @return [Node]
|
2432
|
+
attr_reader :value
|
2433
|
+
# Location of the `**` operator
|
2434
|
+
#
|
2435
|
+
# ```text
|
2436
|
+
# foo(**bar)
|
2437
|
+
# ~~
|
2438
|
+
# ```
|
2439
|
+
#
|
2440
|
+
# @return [Loc]
|
2441
|
+
attr_reader :operator_l
|
2442
|
+
# Location of the full expression
|
2443
|
+
#
|
2444
|
+
# ```text
|
2445
|
+
# foo(**bar)
|
2446
|
+
# ~~~~~
|
2447
|
+
# ```
|
2448
|
+
#
|
2449
|
+
# @return [Loc]
|
2450
|
+
attr_reader :expression_l
|
2451
|
+
end
|
2452
|
+
|
2453
|
+
# Represents a lambda call using `->` (i.e. `-> {}`)
|
2454
|
+
#
|
2455
|
+
# Note that `Lambda` is a part of the `Block`, not other way around.
|
2456
|
+
class Lambda < Node
|
2457
|
+
# Location of the `->`
|
2458
|
+
#
|
2459
|
+
# ```text
|
2460
|
+
# -> {}
|
2461
|
+
# ~~
|
2462
|
+
# ```
|
2463
|
+
#
|
2464
|
+
# @return [Loc]
|
2465
|
+
attr_reader :expression_l
|
2466
|
+
end
|
2467
|
+
|
2468
|
+
# Represents a special `__LINE__` literal
|
2469
|
+
class Line < Node
|
2470
|
+
# Location of the `__LINE__` literal
|
2471
|
+
#
|
2472
|
+
# ```text
|
2473
|
+
# __LINE__
|
2474
|
+
# ~~~~~~~~
|
2475
|
+
# ```
|
2476
|
+
#
|
2477
|
+
# @return [Loc]
|
2478
|
+
attr_reader :expression_l
|
2479
|
+
end
|
2480
|
+
|
2481
|
+
# Represents access to a local variable (i.e. `foo`)
|
2482
|
+
#
|
2483
|
+
# Parser knows that it's a local variable because:
|
2484
|
+
# 1. there was an assignment to this variable **before** accessing it
|
2485
|
+
# 2. it's an argument of the current method / block
|
2486
|
+
# 3. it's been implicitly declared by `MatchWithLvasgn` node
|
2487
|
+
#
|
2488
|
+
# Otherwise it's a method call (see `Send`)
|
2489
|
+
class Lvar < Node
|
2490
|
+
# Name of the local variable
|
2491
|
+
#
|
2492
|
+
# @return [String]
|
2493
|
+
attr_reader :name
|
2494
|
+
# Location of the local variable
|
2495
|
+
#
|
2496
|
+
# ```text
|
2497
|
+
# foo
|
2498
|
+
# ~~~
|
2499
|
+
# ```
|
2500
|
+
#
|
2501
|
+
# @return [Loc]
|
2502
|
+
attr_reader :expression_l
|
2503
|
+
end
|
2504
|
+
|
2505
|
+
# Represents local variable assignment (i.e. `foo = 42`)
|
2506
|
+
class Lvasgn < Node
|
2507
|
+
# Name of the local variable
|
2508
|
+
#
|
2509
|
+
# @return [String]
|
2510
|
+
attr_reader :name
|
2511
|
+
# Value that is assigned to a local variable
|
2512
|
+
#
|
2513
|
+
# @return [Node, nil]
|
2514
|
+
attr_reader :value
|
2515
|
+
# Location of the local variable name
|
2516
|
+
#
|
2517
|
+
# ```text
|
2518
|
+
# foo = 42
|
2519
|
+
# ~~~
|
2520
|
+
# ```
|
2521
|
+
#
|
2522
|
+
# @return [Loc]
|
2523
|
+
attr_reader :name_l
|
2524
|
+
# Location of the `=` operator
|
2525
|
+
#
|
2526
|
+
# ```text
|
2527
|
+
# foo = 42
|
2528
|
+
# ~
|
2529
|
+
# ```
|
2530
|
+
#
|
2531
|
+
# `None` if local variable assignment is a part of the multi-assignment.
|
2532
|
+
# In such case `value` is a part of the `Masgn` node.
|
2533
|
+
#
|
2534
|
+
# @return [Loc, nil]
|
2535
|
+
attr_reader :operator_l
|
2536
|
+
# Location of the full expression
|
2537
|
+
#
|
2538
|
+
# ```text
|
2539
|
+
# foo = 42
|
2540
|
+
# ~~~~~~~~
|
2541
|
+
# ```
|
2542
|
+
#
|
2543
|
+
# @return [Loc]
|
2544
|
+
attr_reader :expression_l
|
2545
|
+
end
|
2546
|
+
|
2547
|
+
# Represents mass-assignment (i.e. `foo, bar = 1, 2`)
|
2548
|
+
class Masgn < Node
|
2549
|
+
# Left hand statement of the assignment
|
2550
|
+
#
|
2551
|
+
# @return [Node]
|
2552
|
+
attr_reader :lhs
|
2553
|
+
# Left hand statement of the assignment
|
2554
|
+
#
|
2555
|
+
# @return [Node]
|
2556
|
+
attr_reader :rhs
|
2557
|
+
# Location of the `=` operator
|
2558
|
+
#
|
2559
|
+
# ```text
|
2560
|
+
# foo, bar = 1, 2
|
2561
|
+
# ~
|
2562
|
+
# ```
|
2563
|
+
#
|
2564
|
+
# @return [Loc]
|
2565
|
+
attr_reader :operator_l
|
2566
|
+
# Location of the full expression
|
2567
|
+
#
|
2568
|
+
# ```text
|
2569
|
+
# foo, bar = 1, 2
|
2570
|
+
# ~~~~~~~~~~~~~~~
|
2571
|
+
# ```
|
2572
|
+
#
|
2573
|
+
# @return [Loc]
|
2574
|
+
attr_reader :expression_l
|
2575
|
+
end
|
2576
|
+
|
2577
|
+
# Represents pattern matching using one of the given patterns (i.e. `foo in 1 | 2`)
|
2578
|
+
class MatchAlt < Node
|
2579
|
+
# Left pattern
|
2580
|
+
#
|
2581
|
+
# @return [Node]
|
2582
|
+
attr_reader :lhs
|
2583
|
+
# Right pattern
|
2584
|
+
#
|
2585
|
+
# @return [Node]
|
2586
|
+
attr_reader :rhs
|
2587
|
+
# Location of the `|` operator
|
2588
|
+
#
|
2589
|
+
# ```text
|
2590
|
+
# foo in 1 | 2
|
2591
|
+
# ~
|
2592
|
+
# ```
|
2593
|
+
#
|
2594
|
+
# @return [Loc]
|
2595
|
+
attr_reader :operator_l
|
2596
|
+
# Location of the full expression
|
2597
|
+
#
|
2598
|
+
# ```text
|
2599
|
+
# foo in 1 | 2
|
2600
|
+
# ~~~~~
|
2601
|
+
# ```
|
2602
|
+
#
|
2603
|
+
# @return [Loc]
|
2604
|
+
attr_reader :expression_l
|
2605
|
+
end
|
2606
|
+
|
2607
|
+
# Represents matching with renaming into specified local variable (i.e. `case 1; in Integer => a; end`)
|
2608
|
+
class MatchAs < Node
|
2609
|
+
# Pattern that is used for matching
|
2610
|
+
#
|
2611
|
+
# @return [Node]
|
2612
|
+
attr_reader :value
|
2613
|
+
# Variable that is assigned if matched (see `MatchVar` node)
|
2614
|
+
#
|
2615
|
+
# @return [Node]
|
2616
|
+
attr_reader :as
|
2617
|
+
# Location of the `=>` operator
|
2618
|
+
#
|
2619
|
+
# ```text
|
2620
|
+
# case 1; in Integer => a; end
|
2621
|
+
# ~~
|
2622
|
+
# ```
|
2623
|
+
#
|
2624
|
+
# @return [Loc]
|
2625
|
+
attr_reader :operator_l
|
2626
|
+
# Location of the full expression
|
2627
|
+
#
|
2628
|
+
# ```text
|
2629
|
+
# case 1; in Integer => a; end
|
2630
|
+
# ~~~~~~~~~~~~
|
2631
|
+
# ```
|
2632
|
+
#
|
2633
|
+
# @return [Loc]
|
2634
|
+
attr_reader :expression_l
|
2635
|
+
end
|
2636
|
+
|
2637
|
+
# Represents implicit matching using `if /regex/`
|
2638
|
+
#
|
2639
|
+
# ```text
|
2640
|
+
# if /.*/
|
2641
|
+
# puts 'true'
|
2642
|
+
# else
|
2643
|
+
# puts 'false'
|
2644
|
+
# end
|
2645
|
+
# ```
|
2646
|
+
# Prints "false".
|
2647
|
+
#
|
2648
|
+
# Under the hood this construction matches regex against `$_`, so the following works:
|
2649
|
+
# ```text
|
2650
|
+
# $_ = 'match_me'
|
2651
|
+
# if /match_me/
|
2652
|
+
# puts 'true'
|
2653
|
+
# else
|
2654
|
+
# puts 'false'
|
2655
|
+
# end
|
2656
|
+
# ```
|
2657
|
+
# this code prints "true".
|
2658
|
+
class MatchCurrentLine < Node
|
2659
|
+
# Given regex
|
2660
|
+
#
|
2661
|
+
# @return [Node]
|
2662
|
+
attr_reader :re
|
2663
|
+
# Location of the regex
|
2664
|
+
#
|
2665
|
+
# ```text
|
2666
|
+
# if /re/; end
|
2667
|
+
# ~~~~
|
2668
|
+
# ```
|
2669
|
+
#
|
2670
|
+
# Technically this location is redundant, but keeping it is the only way to
|
2671
|
+
# have the same interface for all nodes.
|
2672
|
+
#
|
2673
|
+
# @return [Loc]
|
2674
|
+
attr_reader :expression_l
|
2675
|
+
end
|
2676
|
+
|
2677
|
+
# Represents empty hash pattern that is used in pattern matching (i.e. `in **nil`)
|
2678
|
+
class MatchNilPattern < Node
|
2679
|
+
# Location of the `**` operator
|
2680
|
+
#
|
2681
|
+
# ```text
|
2682
|
+
# in **nil
|
2683
|
+
# ~~
|
2684
|
+
# ```
|
2685
|
+
#
|
2686
|
+
# @return [Loc]
|
2687
|
+
attr_reader :operator_l
|
2688
|
+
# Location of the name
|
2689
|
+
#
|
2690
|
+
# ```text
|
2691
|
+
# in **nil
|
2692
|
+
# ~~~
|
2693
|
+
# ```
|
2694
|
+
#
|
2695
|
+
# @return [Loc]
|
2696
|
+
attr_reader :name_l
|
2697
|
+
# Location of the full expression
|
2698
|
+
#
|
2699
|
+
# ```text
|
2700
|
+
# in **nil
|
2701
|
+
# ~~~~~
|
2702
|
+
# ```
|
2703
|
+
#
|
2704
|
+
# @return [Loc]
|
2705
|
+
attr_reader :expression_l
|
2706
|
+
end
|
2707
|
+
|
2708
|
+
# Represents a one-line pattern matching that can throw an error (i.e. `foo => pattern`)
|
2709
|
+
class MatchPattern < Node
|
2710
|
+
# Value that is used for matching
|
2711
|
+
#
|
2712
|
+
# @return [Node]
|
2713
|
+
attr_reader :value
|
2714
|
+
# Pattern that is used for matching
|
2715
|
+
#
|
2716
|
+
# @return [Node]
|
2717
|
+
attr_reader :pattern
|
2718
|
+
# Location of the `=>` operator
|
2719
|
+
#
|
2720
|
+
# ```text
|
2721
|
+
# foo => pattern
|
2722
|
+
# ~~
|
2723
|
+
# ```
|
2724
|
+
#
|
2725
|
+
# @return [Loc]
|
2726
|
+
attr_reader :operator_l
|
2727
|
+
# Location of the full expression
|
2728
|
+
#
|
2729
|
+
# ```text
|
2730
|
+
# foo => pattern
|
2731
|
+
# ~~~~~~~~~~~~~~
|
2732
|
+
# ```
|
2733
|
+
#
|
2734
|
+
# @return [Loc]
|
2735
|
+
attr_reader :expression_l
|
2736
|
+
end
|
2737
|
+
|
2738
|
+
# Represents a one-line pattern matching that never throws but returns true/false (i.e. `foo in pattern`)
|
2739
|
+
class MatchPatternP < Node
|
2740
|
+
# Value that is used for matching
|
2741
|
+
#
|
2742
|
+
# @return [Node]
|
2743
|
+
attr_reader :value
|
2744
|
+
# Pattern that is used for matching
|
2745
|
+
#
|
2746
|
+
# @return [Node]
|
2747
|
+
attr_reader :pattern
|
2748
|
+
# Location of the `in` operator
|
2749
|
+
#
|
2750
|
+
# ```text
|
2751
|
+
# foo in pattern
|
2752
|
+
# ~~
|
2753
|
+
# ```
|
2754
|
+
#
|
2755
|
+
# @return [Loc]
|
2756
|
+
attr_reader :operator_l
|
2757
|
+
# Location of the full expression
|
2758
|
+
#
|
2759
|
+
# ```text
|
2760
|
+
# foo in pattern
|
2761
|
+
# ~~~~~~~~~~~~~~
|
2762
|
+
# ```
|
2763
|
+
#
|
2764
|
+
# @return [Loc]
|
2765
|
+
attr_reader :expression_l
|
2766
|
+
end
|
2767
|
+
|
2768
|
+
# Represents a wildcard pattern used in pattern matching (i.e. `in *foo`)
|
2769
|
+
class MatchRest < Node
|
2770
|
+
# Name of the variable name
|
2771
|
+
#
|
2772
|
+
# `None` if there's no name (i.e. `in *`)
|
2773
|
+
#
|
2774
|
+
# @return [Node, nil]
|
2775
|
+
attr_reader :name
|
2776
|
+
# Location of the `*` operator
|
2777
|
+
#
|
2778
|
+
# ```text
|
2779
|
+
# case foo; in *bar; end
|
2780
|
+
# ~
|
2781
|
+
# ```
|
2782
|
+
#
|
2783
|
+
# @return [Loc]
|
2784
|
+
attr_reader :operator_l
|
2785
|
+
# Location of the `*` operator
|
2786
|
+
#
|
2787
|
+
# ```text
|
2788
|
+
# case foo; in *bar; end
|
2789
|
+
# ~~~~
|
2790
|
+
# ```
|
2791
|
+
#
|
2792
|
+
# @return [Loc]
|
2793
|
+
attr_reader :expression_l
|
2794
|
+
end
|
2795
|
+
|
2796
|
+
# Represents matching with assignment into a local variable (i.e. `pattern => var`)
|
2797
|
+
class MatchVar < Node
|
2798
|
+
# Name of the variable that is assigned if matching succeeds
|
2799
|
+
#
|
2800
|
+
# @return [String]
|
2801
|
+
attr_reader :name
|
2802
|
+
# Location of the name
|
2803
|
+
#
|
2804
|
+
# ```text
|
2805
|
+
# case foo; in pattern => bar; end
|
2806
|
+
# ~~~
|
2807
|
+
# ```
|
2808
|
+
#
|
2809
|
+
# **Note** it can also be produced by a hash pattern
|
2810
|
+
#
|
2811
|
+
# ```text
|
2812
|
+
# case foo; in { a: }; end
|
2813
|
+
# ~
|
2814
|
+
# ```
|
2815
|
+
#
|
2816
|
+
# @return [Loc]
|
2817
|
+
attr_reader :name_l
|
2818
|
+
# Location of the full expression
|
2819
|
+
#
|
2820
|
+
# ```text
|
2821
|
+
# case foo; in pattern => bar; end
|
2822
|
+
# ~~~
|
2823
|
+
# ```
|
2824
|
+
#
|
2825
|
+
# **Note** it can also be produced by a hash pattern
|
2826
|
+
#
|
2827
|
+
# ```text
|
2828
|
+
# case foo; in { a: }; end
|
2829
|
+
# ~~
|
2830
|
+
# ```
|
2831
|
+
#
|
2832
|
+
# @return [Loc]
|
2833
|
+
attr_reader :expression_l
|
2834
|
+
end
|
2835
|
+
|
2836
|
+
# Represents matching a regex that produces local variables (i.e. `/(?<match>bar)/ =~ 'bar'`)
|
2837
|
+
#
|
2838
|
+
# Each named group in regex declares a local variable.
|
2839
|
+
class MatchWithLvasgn < Node
|
2840
|
+
# Regex that is used for matching
|
2841
|
+
#
|
2842
|
+
# @return [Node]
|
2843
|
+
attr_reader :re
|
2844
|
+
# Value that is used for matching
|
2845
|
+
#
|
2846
|
+
# @return [Node]
|
2847
|
+
attr_reader :value
|
2848
|
+
# Location of the `=~` operatir
|
2849
|
+
#
|
2850
|
+
# ```text
|
2851
|
+
# /(?<match>bar)/ =~ 'bar'
|
2852
|
+
# ~~
|
2853
|
+
# ```
|
2854
|
+
#
|
2855
|
+
# @return [Loc]
|
2856
|
+
attr_reader :operator_l
|
2857
|
+
# Location of the full expression
|
2858
|
+
#
|
2859
|
+
# ```text
|
2860
|
+
# /(?<match>bar)/ =~ 'bar'
|
2861
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~
|
2862
|
+
# ```
|
2863
|
+
#
|
2864
|
+
# @return [Loc]
|
2865
|
+
attr_reader :expression_l
|
2866
|
+
end
|
2867
|
+
|
2868
|
+
# Represents left hand statement of the mass-assignment (i.e. `foo, bar` in `foo, bar = 1, 2`)
|
2869
|
+
class Mlhs < Node
|
2870
|
+
# A list of items that are assigned
|
2871
|
+
#
|
2872
|
+
# @return [::Array<Node>]
|
2873
|
+
attr_reader :items
|
2874
|
+
# Location of the open parenthesis
|
2875
|
+
#
|
2876
|
+
# ```text
|
2877
|
+
# (a, b) = 1, 2
|
2878
|
+
# ~
|
2879
|
+
# ```
|
2880
|
+
#
|
2881
|
+
# `None` if there are no parentheses
|
2882
|
+
#
|
2883
|
+
# @return [Loc, nil]
|
2884
|
+
attr_reader :begin_l
|
2885
|
+
# Location of the closing parenthesis
|
2886
|
+
#
|
2887
|
+
# ```text
|
2888
|
+
# (a, b) = 1, 2
|
2889
|
+
# ~
|
2890
|
+
# ```
|
2891
|
+
#
|
2892
|
+
# `None` if there are no parentheses
|
2893
|
+
#
|
2894
|
+
# @return [Loc, nil]
|
2895
|
+
attr_reader :end_l
|
2896
|
+
# Location of the full expression
|
2897
|
+
#
|
2898
|
+
# ```text
|
2899
|
+
# (a, b) = 1, 2
|
2900
|
+
# ~~~~~~
|
2901
|
+
# ```
|
2902
|
+
#
|
2903
|
+
# @return [Loc]
|
2904
|
+
attr_reader :expression_l
|
2905
|
+
end
|
2906
|
+
|
2907
|
+
# Represents module declaration using `module` keyword
|
2908
|
+
class Module < Node
|
2909
|
+
# Name of the module
|
2910
|
+
#
|
2911
|
+
# @return [Node]
|
2912
|
+
attr_reader :name
|
2913
|
+
# Body of the module
|
2914
|
+
#
|
2915
|
+
# `None` if module has no body
|
2916
|
+
#
|
2917
|
+
# @return [Node, nil]
|
2918
|
+
attr_reader :body
|
2919
|
+
# Location of the `module` keyword
|
2920
|
+
#
|
2921
|
+
# ```text
|
2922
|
+
# module M; end
|
2923
|
+
# ~~~~~~
|
2924
|
+
# ```
|
2925
|
+
#
|
2926
|
+
# @return [Loc]
|
2927
|
+
attr_reader :keyword_l
|
2928
|
+
# Location of the `end` keyword
|
2929
|
+
#
|
2930
|
+
# ```text
|
2931
|
+
# module M; end
|
2932
|
+
# ~~~
|
2933
|
+
# ```
|
2934
|
+
#
|
2935
|
+
# @return [Loc]
|
2936
|
+
attr_reader :end_l
|
2937
|
+
# Location of the full expression
|
2938
|
+
#
|
2939
|
+
# ```text
|
2940
|
+
# module M; end
|
2941
|
+
# ~~~~~~~~~~~~~
|
2942
|
+
# ```
|
2943
|
+
#
|
2944
|
+
# @return [Loc]
|
2945
|
+
attr_reader :expression_l
|
2946
|
+
end
|
2947
|
+
|
2948
|
+
# Represents `next` keyword
|
2949
|
+
class Next < Node
|
2950
|
+
# Arguments given to `next`
|
2951
|
+
#
|
2952
|
+
# @return [::Array<Node>]
|
2953
|
+
attr_reader :args
|
2954
|
+
# Location of the `next` keyword
|
2955
|
+
#
|
2956
|
+
# ```text
|
2957
|
+
# next 42
|
2958
|
+
# ~~~~
|
2959
|
+
# ```
|
2960
|
+
#
|
2961
|
+
# @return [Loc]
|
2962
|
+
attr_reader :keyword_l
|
2963
|
+
# Location of the full expression
|
2964
|
+
#
|
2965
|
+
# ```text
|
2966
|
+
# next(42)
|
2967
|
+
# ~~~~~~~~
|
2968
|
+
# ```
|
2969
|
+
#
|
2970
|
+
# @return [Loc]
|
2971
|
+
attr_reader :expression_l
|
2972
|
+
end
|
2973
|
+
|
2974
|
+
# Represents `nil` literal
|
2975
|
+
class Nil < Node
|
2976
|
+
# Location of the `nil` keyword
|
2977
|
+
#
|
2978
|
+
# ```text
|
2979
|
+
# nil
|
2980
|
+
# ~~~
|
2981
|
+
# ```
|
2982
|
+
#
|
2983
|
+
# @return [Loc]
|
2984
|
+
attr_reader :expression_l
|
2985
|
+
end
|
2986
|
+
|
2987
|
+
# Represents numeric global variable (e.g. `$1`)
|
2988
|
+
class NthRef < Node
|
2989
|
+
# Name of the variable, `String("1")` for `$1`
|
2990
|
+
#
|
2991
|
+
# @return [String]
|
2992
|
+
attr_reader :name
|
2993
|
+
# Location of the full expression
|
2994
|
+
#
|
2995
|
+
# ```text
|
2996
|
+
# $1
|
2997
|
+
# ~~
|
2998
|
+
# ```
|
2999
|
+
#
|
3000
|
+
# @return [Loc]
|
3001
|
+
attr_reader :expression_l
|
3002
|
+
end
|
3003
|
+
|
3004
|
+
# Represents a block that takes numbered parameters (i.e. `proc { _1 }`)
|
3005
|
+
class Numblock < Node
|
3006
|
+
# Method call that takes a block
|
3007
|
+
#
|
3008
|
+
# @return [Node]
|
3009
|
+
attr_reader :call
|
3010
|
+
# Number of parameters that block takes
|
3011
|
+
#
|
3012
|
+
# @return [Integer]
|
3013
|
+
attr_reader :numargs
|
3014
|
+
# Block body
|
3015
|
+
#
|
3016
|
+
# @return [Node]
|
3017
|
+
attr_reader :body
|
3018
|
+
# Location of the open brace
|
3019
|
+
#
|
3020
|
+
# ```text
|
3021
|
+
# proc { _1 }
|
3022
|
+
# ~
|
3023
|
+
# ```
|
3024
|
+
#
|
3025
|
+
# @return [Loc]
|
3026
|
+
attr_reader :begin_l
|
3027
|
+
# Location of the closing brace
|
3028
|
+
#
|
3029
|
+
# ```text
|
3030
|
+
# proc { _1 }
|
3031
|
+
# ~
|
3032
|
+
# ```
|
3033
|
+
#
|
3034
|
+
# @return [Loc]
|
3035
|
+
attr_reader :end_l
|
3036
|
+
# Location of the open brace
|
3037
|
+
#
|
3038
|
+
# ```text
|
3039
|
+
# proc { _1 }
|
3040
|
+
# ~~~~~~~~~~~
|
3041
|
+
# ```
|
3042
|
+
#
|
3043
|
+
# @return [Loc]
|
3044
|
+
attr_reader :expression_l
|
3045
|
+
end
|
3046
|
+
|
3047
|
+
# Represents an operation with assignment (e.g. `a += 1`)
|
3048
|
+
class OpAsgn < Node
|
3049
|
+
# Left hand statement of the assignment
|
3050
|
+
#
|
3051
|
+
# @return [Node]
|
3052
|
+
attr_reader :recv
|
3053
|
+
# Operator, can be one of:
|
3054
|
+
# 1. `+=`
|
3055
|
+
# 2. `-=`
|
3056
|
+
# 3. `*=`
|
3057
|
+
# 4. `/=`
|
3058
|
+
# 5. `|=`
|
3059
|
+
# 6. `&=`
|
3060
|
+
# 7. `>>=`
|
3061
|
+
# 8. `<<=`
|
3062
|
+
# 9. `%=`
|
3063
|
+
# 10. `^=`
|
3064
|
+
# 11. `**=`
|
3065
|
+
#
|
3066
|
+
# @return [String]
|
3067
|
+
attr_reader :operator
|
3068
|
+
# Right hand statement of the assignment
|
3069
|
+
#
|
3070
|
+
# @return [Node]
|
3071
|
+
attr_reader :value
|
3072
|
+
# Location of the operator
|
3073
|
+
#
|
3074
|
+
# ```text
|
3075
|
+
# a.b <<= c
|
3076
|
+
# ~~~
|
3077
|
+
# ```
|
3078
|
+
#
|
3079
|
+
# @return [Loc]
|
3080
|
+
attr_reader :operator_l
|
3081
|
+
# Location of the operator
|
3082
|
+
#
|
3083
|
+
# ```text
|
3084
|
+
# a.b <<= c
|
3085
|
+
# ~~~~~~~~~
|
3086
|
+
# ```
|
3087
|
+
#
|
3088
|
+
# @return [Loc]
|
3089
|
+
attr_reader :expression_l
|
3090
|
+
end
|
3091
|
+
|
3092
|
+
# Represents optional positional argument (i.e. `foo` in `m(foo = 1)`)
|
3093
|
+
class Optarg < Node
|
3094
|
+
# Name of the argument
|
3095
|
+
#
|
3096
|
+
# @return [String]
|
3097
|
+
attr_reader :name
|
3098
|
+
# Default value of the argument
|
3099
|
+
#
|
3100
|
+
# @return [Node]
|
3101
|
+
attr_reader :default
|
3102
|
+
# Location of the argument name
|
3103
|
+
#
|
3104
|
+
# ```text
|
3105
|
+
# def m(foo = 1); end
|
3106
|
+
# ~~~
|
3107
|
+
# ```
|
3108
|
+
#
|
3109
|
+
# @return [Loc]
|
3110
|
+
attr_reader :name_l
|
3111
|
+
# Location of the `=` operator
|
3112
|
+
#
|
3113
|
+
# ```text
|
3114
|
+
# def m(foo = 1); end
|
3115
|
+
# ~
|
3116
|
+
# ```
|
3117
|
+
#
|
3118
|
+
# @return [Loc]
|
3119
|
+
attr_reader :operator_l
|
3120
|
+
# Location of the full expression
|
3121
|
+
#
|
3122
|
+
# ```text
|
3123
|
+
# def m(foo = 1); end
|
3124
|
+
# ~~~~~~~
|
3125
|
+
# ```
|
3126
|
+
#
|
3127
|
+
# @return [Loc]
|
3128
|
+
attr_reader :expression_l
|
3129
|
+
end
|
3130
|
+
|
3131
|
+
# Represents `foo || bar` (or `foo or bar`) statement.
|
3132
|
+
class Or < Node
|
3133
|
+
# Left hand statement
|
3134
|
+
#
|
3135
|
+
# @return [Node]
|
3136
|
+
attr_reader :lhs
|
3137
|
+
# Right hand statement
|
3138
|
+
#
|
3139
|
+
# @return [Node]
|
3140
|
+
attr_reader :rhs
|
3141
|
+
# Location of the `||`/`or` operator
|
3142
|
+
#
|
3143
|
+
# ```text
|
3144
|
+
# foo || bar
|
3145
|
+
# ~~
|
3146
|
+
# ```
|
3147
|
+
#
|
3148
|
+
# @return [Loc]
|
3149
|
+
attr_reader :operator_l
|
3150
|
+
# Location of the full expression
|
3151
|
+
#
|
3152
|
+
# ```text
|
3153
|
+
# foo || bar
|
3154
|
+
# ~~~~~~~~~~
|
3155
|
+
# ```
|
3156
|
+
#
|
3157
|
+
# @return [Loc]
|
3158
|
+
attr_reader :expression_l
|
3159
|
+
end
|
3160
|
+
|
3161
|
+
# Represents `lhs ||= rhs` assignment
|
3162
|
+
class OrAsgn < Node
|
3163
|
+
# Left hand statement
|
3164
|
+
#
|
3165
|
+
# @return [Node]
|
3166
|
+
attr_reader :recv
|
3167
|
+
# Right hand statement
|
3168
|
+
#
|
3169
|
+
# @return [Node]
|
3170
|
+
attr_reader :value
|
3171
|
+
# Location of the `||=` operator
|
3172
|
+
#
|
3173
|
+
# ```text
|
3174
|
+
# foo ||= bar
|
3175
|
+
# ~~~
|
3176
|
+
# ```
|
3177
|
+
#
|
3178
|
+
# @return [Loc]
|
3179
|
+
attr_reader :operator_l
|
3180
|
+
# Location of the full expression
|
3181
|
+
#
|
3182
|
+
# ```text
|
3183
|
+
# foo ||= bar
|
3184
|
+
# ~~~~~~~~~~~
|
3185
|
+
# ```
|
3186
|
+
#
|
3187
|
+
# @return [Loc]
|
3188
|
+
attr_reader :expression_l
|
3189
|
+
end
|
3190
|
+
|
3191
|
+
# Represents a key/value pair (e.g. a part of the `Hash` node)
|
3192
|
+
class Pair < Node
|
3193
|
+
# Key of the pair
|
3194
|
+
#
|
3195
|
+
# @return [Node]
|
3196
|
+
attr_reader :key
|
3197
|
+
# Value of the pair
|
3198
|
+
#
|
3199
|
+
# @return [Node]
|
3200
|
+
attr_reader :value
|
3201
|
+
# Location of the `:` or `=>` operator
|
3202
|
+
#
|
3203
|
+
# ```text
|
3204
|
+
# { foo: bar }
|
3205
|
+
# ~
|
3206
|
+
#
|
3207
|
+
# { :foo => bar }
|
3208
|
+
# ~~
|
3209
|
+
# ```
|
3210
|
+
#
|
3211
|
+
# @return [Loc]
|
3212
|
+
attr_reader :operator_l
|
3213
|
+
# Location of the full expression
|
3214
|
+
#
|
3215
|
+
# ```text
|
3216
|
+
# { foo: bar }
|
3217
|
+
# ~~~~~~~~
|
3218
|
+
#
|
3219
|
+
# { :foo => bar }
|
3220
|
+
# ~~~~~~~~~~~
|
3221
|
+
# ```
|
3222
|
+
#
|
3223
|
+
# @return [Loc]
|
3224
|
+
attr_reader :expression_l
|
3225
|
+
end
|
3226
|
+
|
3227
|
+
# Represents a pattern based on a "pinned" variable (e.g. `^foo`)
|
3228
|
+
class Pin < Node
|
3229
|
+
# Variable that is pinned
|
3230
|
+
#
|
3231
|
+
# @return [Node]
|
3232
|
+
attr_reader :var
|
3233
|
+
# Location of the `^` operator
|
3234
|
+
#
|
3235
|
+
# ```text
|
3236
|
+
# case foo; in ^bar; end
|
3237
|
+
# ~
|
3238
|
+
# ```
|
3239
|
+
#
|
3240
|
+
# @return [Loc]
|
3241
|
+
attr_reader :selector_l
|
3242
|
+
# Location of the full expression
|
3243
|
+
#
|
3244
|
+
# ```text
|
3245
|
+
# case foo; in ^bar; end
|
3246
|
+
# ~~~~
|
3247
|
+
# ```
|
3248
|
+
#
|
3249
|
+
# @return [Loc]
|
3250
|
+
attr_reader :expression_l
|
3251
|
+
end
|
3252
|
+
|
3253
|
+
# Represents `END { .. }` statement
|
3254
|
+
class Postexe < Node
|
3255
|
+
# Body of the block
|
3256
|
+
#
|
3257
|
+
# @return [Node, nil]
|
3258
|
+
attr_reader :body
|
3259
|
+
# Location of the `END` keyword
|
3260
|
+
#
|
3261
|
+
# ```text
|
3262
|
+
# END { 42 }
|
3263
|
+
# ~~~
|
3264
|
+
# ```
|
3265
|
+
#
|
3266
|
+
# @return [Loc]
|
3267
|
+
attr_reader :keyword_l
|
3268
|
+
# Location of the open parenthesis
|
3269
|
+
#
|
3270
|
+
# ```text
|
3271
|
+
# END { 42 }
|
3272
|
+
# ~
|
3273
|
+
# ```
|
3274
|
+
#
|
3275
|
+
# @return [Loc]
|
3276
|
+
attr_reader :begin_l
|
3277
|
+
# Location of the closing parenthesis
|
3278
|
+
#
|
3279
|
+
# ```text
|
3280
|
+
# END { 42 }
|
3281
|
+
# ~
|
3282
|
+
# ```
|
3283
|
+
#
|
3284
|
+
# @return [Loc]
|
3285
|
+
attr_reader :end_l
|
3286
|
+
# Location of the full expression
|
3287
|
+
#
|
3288
|
+
# ```text
|
3289
|
+
# END { 42 }
|
3290
|
+
# ~~~~~~~~~~
|
3291
|
+
# ```
|
3292
|
+
#
|
3293
|
+
# @return [Loc]
|
3294
|
+
attr_reader :expression_l
|
3295
|
+
end
|
3296
|
+
|
3297
|
+
# Represents `BEGIN { ... }` statement
|
3298
|
+
class Preexe < Node
|
3299
|
+
# Body of the block
|
3300
|
+
#
|
3301
|
+
# @return [Node, nil]
|
3302
|
+
attr_reader :body
|
3303
|
+
# Location of the `BEGIN` keyword
|
3304
|
+
#
|
3305
|
+
# ```text
|
3306
|
+
# BEGIN { 42 }
|
3307
|
+
# ~~~~~
|
3308
|
+
# ```
|
3309
|
+
#
|
3310
|
+
# @return [Loc]
|
3311
|
+
attr_reader :keyword_l
|
3312
|
+
# Location of the open parenthesis
|
3313
|
+
#
|
3314
|
+
# ```text
|
3315
|
+
# BEGIN { 42 }
|
3316
|
+
# ~
|
3317
|
+
# ```
|
3318
|
+
#
|
3319
|
+
# @return [Loc]
|
3320
|
+
attr_reader :begin_l
|
3321
|
+
# Location of the closing parenthesis
|
3322
|
+
#
|
3323
|
+
# ```text
|
3324
|
+
# BEGIN { 42 }
|
3325
|
+
# ~
|
3326
|
+
# ```
|
3327
|
+
#
|
3328
|
+
# @return [Loc]
|
3329
|
+
attr_reader :end_l
|
3330
|
+
# Location of the full expression
|
3331
|
+
#
|
3332
|
+
# ```text
|
3333
|
+
# BEGIN { 42 }
|
3334
|
+
# ~~~~~~~~~~~~
|
3335
|
+
# ```
|
3336
|
+
#
|
3337
|
+
# @return [Loc]
|
3338
|
+
attr_reader :expression_l
|
3339
|
+
end
|
3340
|
+
|
3341
|
+
# Represents a sole block argument (e.g. `|foo|`)
|
3342
|
+
#
|
3343
|
+
# Block that takes a single array argument automatically expands it.
|
3344
|
+
# Adding trailing comma after block argument disables this behavior (and then the only argument is emitted as `Arg`).
|
3345
|
+
class Procarg0 < Node
|
3346
|
+
# Parts of the sole block argument.
|
3347
|
+
#
|
3348
|
+
# `proc { |(a, b)| }` also counts as a sole argument, so this list may contain:
|
3349
|
+
# 1. A single `Arg` node (for `proc { |a| }` case)
|
3350
|
+
# 2. Multiple `Arg` nodes (for `proc { |(a, b, c)| }` case)
|
3351
|
+
#
|
3352
|
+
# @return [::Array<Node>]
|
3353
|
+
attr_reader :args
|
3354
|
+
# Location of the open parenthesis
|
3355
|
+
#
|
3356
|
+
# ```text
|
3357
|
+
# proc { |(foo, bar)| }
|
3358
|
+
# ~
|
3359
|
+
# ```
|
3360
|
+
#
|
3361
|
+
# `None` if there's only one argument
|
3362
|
+
#
|
3363
|
+
# @return [Loc, nil]
|
3364
|
+
attr_reader :begin_l
|
3365
|
+
# Location of the open parenthesis
|
3366
|
+
#
|
3367
|
+
# ```text
|
3368
|
+
# proc { |(foo, bar)| }
|
3369
|
+
# ~
|
3370
|
+
# ```
|
3371
|
+
#
|
3372
|
+
# `None` if there's only one argument
|
3373
|
+
#
|
3374
|
+
# @return [Loc, nil]
|
3375
|
+
attr_reader :end_l
|
3376
|
+
# Location of the full expression
|
3377
|
+
#
|
3378
|
+
# ```text
|
3379
|
+
# proc { |(foo, bar)| }
|
3380
|
+
# ~~~~~~~~~~
|
3381
|
+
# ```
|
3382
|
+
#
|
3383
|
+
# @return [Loc]
|
3384
|
+
attr_reader :expression_l
|
3385
|
+
end
|
3386
|
+
|
3387
|
+
# Represents rational literal (e.g. `1r`)
|
3388
|
+
class Rational < Node
|
3389
|
+
# String value of the literal, `String("1r")` for `1r`
|
3390
|
+
#
|
3391
|
+
# @return [String]
|
3392
|
+
attr_reader :value
|
3393
|
+
# Location of the unary `-` (but not `+`)
|
3394
|
+
#
|
3395
|
+
# ```text
|
3396
|
+
# -1r
|
3397
|
+
# ~
|
3398
|
+
# ```
|
3399
|
+
#
|
3400
|
+
# @return [Loc, nil]
|
3401
|
+
attr_reader :operator_l
|
3402
|
+
# Location of the full expression
|
3403
|
+
#
|
3404
|
+
# ```text
|
3405
|
+
# -1r
|
3406
|
+
# ~~~
|
3407
|
+
# ```
|
3408
|
+
#
|
3409
|
+
# @return [Loc]
|
3410
|
+
attr_reader :expression_l
|
3411
|
+
end
|
3412
|
+
|
3413
|
+
# Represents `redo` keyword
|
3414
|
+
class Redo < Node
|
3415
|
+
# Location of the full expression
|
3416
|
+
#
|
3417
|
+
# ```text
|
3418
|
+
# redo
|
3419
|
+
# ~~~~
|
3420
|
+
# ```
|
3421
|
+
#
|
3422
|
+
# @return [Loc]
|
3423
|
+
attr_reader :expression_l
|
3424
|
+
end
|
3425
|
+
|
3426
|
+
# Represents regex literal (e.g. `/foo/`)
|
3427
|
+
class Regexp < Node
|
3428
|
+
# A list of static and dynamic regex parts
|
3429
|
+
#
|
3430
|
+
# @return [::Array<Node>]
|
3431
|
+
attr_reader :parts
|
3432
|
+
# Regex options.
|
3433
|
+
#
|
3434
|
+
# `None` if regex has no explicit flags
|
3435
|
+
#
|
3436
|
+
# @return [Node, nil]
|
3437
|
+
attr_reader :options
|
3438
|
+
# Location of the regex begin
|
3439
|
+
#
|
3440
|
+
# ```text
|
3441
|
+
# /foo/
|
3442
|
+
# ~
|
3443
|
+
#
|
3444
|
+
# %r{foo}
|
3445
|
+
# ~~
|
3446
|
+
# ```
|
3447
|
+
#
|
3448
|
+
# @return [Loc]
|
3449
|
+
attr_reader :begin_l
|
3450
|
+
# Location of the regex end
|
3451
|
+
#
|
3452
|
+
# ```text
|
3453
|
+
# /foo/
|
3454
|
+
# ~
|
3455
|
+
#
|
3456
|
+
# %r{foo}
|
3457
|
+
# ~
|
3458
|
+
# ```
|
3459
|
+
#
|
3460
|
+
# @return [Loc]
|
3461
|
+
attr_reader :end_l
|
3462
|
+
# Location of the full expression
|
3463
|
+
#
|
3464
|
+
# ```text
|
3465
|
+
# /foo/mix
|
3466
|
+
# ~~~~~~~~
|
3467
|
+
# ```
|
3468
|
+
#
|
3469
|
+
# @return [Loc]
|
3470
|
+
attr_reader :expression_l
|
3471
|
+
end
|
3472
|
+
|
3473
|
+
# Represents flags of the regex literal (i.e. `mix` for `/foo/mix`)
|
3474
|
+
class RegOpt < Node
|
3475
|
+
# A list of flags
|
3476
|
+
#
|
3477
|
+
# @return [String, nil]
|
3478
|
+
attr_reader :options
|
3479
|
+
# Location of the full expression
|
3480
|
+
#
|
3481
|
+
# ```text
|
3482
|
+
# /foo/mix
|
3483
|
+
# ~~~
|
3484
|
+
# ```
|
3485
|
+
#
|
3486
|
+
# @return [Loc]
|
3487
|
+
attr_reader :expression_l
|
3488
|
+
end
|
3489
|
+
|
3490
|
+
# Represents a `rescue` block
|
3491
|
+
class Rescue < Node
|
3492
|
+
# Body of the block that is wrapped into `rescue` (i.e. the part that may throw an error)
|
3493
|
+
#
|
3494
|
+
# @return [Node, nil]
|
3495
|
+
attr_reader :body
|
3496
|
+
# A list of `rescue` handlers (see `RescueBody` node)
|
3497
|
+
#
|
3498
|
+
# @return [::Array<Node>]
|
3499
|
+
attr_reader :rescue_bodies
|
3500
|
+
# Else branch.
|
3501
|
+
#
|
3502
|
+
# `None` if there's no `else` branch
|
3503
|
+
#
|
3504
|
+
# @return [Node, nil]
|
3505
|
+
attr_reader :else
|
3506
|
+
# Location of the `else` keyword
|
3507
|
+
#
|
3508
|
+
# ```text
|
3509
|
+
# begin; 1; rescue StandardError => e; 2; else; 3; end
|
3510
|
+
# ~~~~
|
3511
|
+
# ```
|
3512
|
+
#
|
3513
|
+
# `None` if there's no `else` branch
|
3514
|
+
#
|
3515
|
+
# @return [Loc, nil]
|
3516
|
+
attr_reader :else_l
|
3517
|
+
# Location of the full expression
|
3518
|
+
#
|
3519
|
+
# ```text
|
3520
|
+
# begin; 1; rescue StandardError => e; 2; else; 3; end
|
3521
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
3522
|
+
# ```
|
3523
|
+
#
|
3524
|
+
# **Note**: `begin/end` keywords belong to `KwBegin` node
|
3525
|
+
#
|
3526
|
+
# @return [Loc]
|
3527
|
+
attr_reader :expression_l
|
3528
|
+
end
|
3529
|
+
|
3530
|
+
# Represents a single `rescue` handler (i.e. `rescue E => e ...`)
|
3531
|
+
class RescueBody < Node
|
3532
|
+
# A list of exception classes
|
3533
|
+
#
|
3534
|
+
# `None` if no classes specified (i.e. `rescue => e; ...` or just `rescue; ...`)
|
3535
|
+
#
|
3536
|
+
# @return [Node, nil]
|
3537
|
+
attr_reader :exc_list
|
3538
|
+
# Variable that captures exception
|
3539
|
+
#
|
3540
|
+
# `None` if no variable specified (i.e. `rescue E; ...` or just `rescue; ... `)
|
3541
|
+
#
|
3542
|
+
# @return [Node, nil]
|
3543
|
+
attr_reader :exc_var
|
3544
|
+
# Body of the handler
|
3545
|
+
#
|
3546
|
+
# @return [Node, nil]
|
3547
|
+
attr_reader :body
|
3548
|
+
# Location of the `rescue` keyword
|
3549
|
+
#
|
3550
|
+
# ```text
|
3551
|
+
# begin; 1; rescue E => e; 2; end
|
3552
|
+
# ~~~~~~
|
3553
|
+
# ```
|
3554
|
+
#
|
3555
|
+
# @return [Loc]
|
3556
|
+
attr_reader :keyword_l
|
3557
|
+
# Location of the `=>` operator
|
3558
|
+
#
|
3559
|
+
# ```text
|
3560
|
+
# begin; 1; rescue E => e; 2; end
|
3561
|
+
# ~~
|
3562
|
+
# ```
|
3563
|
+
#
|
3564
|
+
# `None` if exception is not captured.
|
3565
|
+
#
|
3566
|
+
# @return [Loc, nil]
|
3567
|
+
attr_reader :assoc_l
|
3568
|
+
# Location of the `then` keyword
|
3569
|
+
#
|
3570
|
+
# ```text
|
3571
|
+
# begin; 1; rescue E => e then; 2; end
|
3572
|
+
# ~~~~
|
3573
|
+
# ```
|
3574
|
+
#
|
3575
|
+
# `then` is optional, so `begin_l` can be `None`
|
3576
|
+
#
|
3577
|
+
# @return [Loc, nil]
|
3578
|
+
attr_reader :begin_l
|
3579
|
+
# Location of the full expression
|
3580
|
+
#
|
3581
|
+
# ```text
|
3582
|
+
# begin; 1; rescue E => e then; 2; end
|
3583
|
+
# ~~~~~~~~~~~~~~~~~~~~~
|
3584
|
+
# ```
|
3585
|
+
#
|
3586
|
+
# @return [Loc]
|
3587
|
+
attr_reader :expression_l
|
3588
|
+
end
|
3589
|
+
|
3590
|
+
# Represents positional rest argument (i.e. `*foo` in `def m(*foo); end`)
|
3591
|
+
class Restarg < Node
|
3592
|
+
# Name of the argument.
|
3593
|
+
#
|
3594
|
+
# `None` if argument has no name (i.e. `def m(*); end`)
|
3595
|
+
#
|
3596
|
+
# @return [String, nil]
|
3597
|
+
attr_reader :name
|
3598
|
+
# Location of the `*` operator
|
3599
|
+
#
|
3600
|
+
# ```text
|
3601
|
+
# def m(*foo); end
|
3602
|
+
# ~
|
3603
|
+
# ```
|
3604
|
+
#
|
3605
|
+
# @return [Loc]
|
3606
|
+
attr_reader :operator_l
|
3607
|
+
# Location of the argument name
|
3608
|
+
#
|
3609
|
+
# ```text
|
3610
|
+
# def m(*foo); end
|
3611
|
+
# ~~~
|
3612
|
+
# ```
|
3613
|
+
#
|
3614
|
+
# @return [Loc, nil]
|
3615
|
+
attr_reader :name_l
|
3616
|
+
# Location of the full expression
|
3617
|
+
#
|
3618
|
+
# ```text
|
3619
|
+
# def m(*foo); end
|
3620
|
+
# ~~~~
|
3621
|
+
# ```
|
3622
|
+
#
|
3623
|
+
# @return [Loc]
|
3624
|
+
attr_reader :expression_l
|
3625
|
+
end
|
3626
|
+
|
3627
|
+
# Represents `retry` keyword
|
3628
|
+
class Retry < Node
|
3629
|
+
# Location of the `retry` keyword
|
3630
|
+
#
|
3631
|
+
# ```text
|
3632
|
+
# retry
|
3633
|
+
# ~~~~~
|
3634
|
+
# ```
|
3635
|
+
#
|
3636
|
+
# @return [Loc]
|
3637
|
+
attr_reader :expression_l
|
3638
|
+
end
|
3639
|
+
|
3640
|
+
# Represents `return` keyword
|
3641
|
+
class Return < Node
|
3642
|
+
# A list of values that is returned
|
3643
|
+
#
|
3644
|
+
# @return [::Array<Node>]
|
3645
|
+
attr_reader :args
|
3646
|
+
# Location of the `return` keyword
|
3647
|
+
#
|
3648
|
+
# ```text
|
3649
|
+
# return 1, 2
|
3650
|
+
# ~~~~~~
|
3651
|
+
# ```
|
3652
|
+
#
|
3653
|
+
# @return [Loc]
|
3654
|
+
attr_reader :keyword_l
|
3655
|
+
# Location of the full expression
|
3656
|
+
#
|
3657
|
+
# ```text
|
3658
|
+
# return 1, 2
|
3659
|
+
# ~~~~~~~~~~~
|
3660
|
+
# ```
|
3661
|
+
#
|
3662
|
+
# @return [Loc]
|
3663
|
+
attr_reader :expression_l
|
3664
|
+
end
|
3665
|
+
|
3666
|
+
# Represents opening a singleton class (i.e. `class << foo; ... end;`)
|
3667
|
+
class SClass < Node
|
3668
|
+
# Expression that is used to get a singleton class
|
3669
|
+
#
|
3670
|
+
# `Lvar("foo")` for `class << foo; end`
|
3671
|
+
#
|
3672
|
+
# @return [Node]
|
3673
|
+
attr_reader :expr
|
3674
|
+
# Body of the block
|
3675
|
+
#
|
3676
|
+
# @return [Node, nil]
|
3677
|
+
attr_reader :body
|
3678
|
+
# Location of the `class` keyword
|
3679
|
+
#
|
3680
|
+
# ```text
|
3681
|
+
# class << foo; end
|
3682
|
+
# ~~~~~
|
3683
|
+
# ```
|
3684
|
+
#
|
3685
|
+
# @return [Loc]
|
3686
|
+
attr_reader :keyword_l
|
3687
|
+
# Location of the `<<` operator
|
3688
|
+
#
|
3689
|
+
# ```text
|
3690
|
+
# class << foo; end
|
3691
|
+
# ~~
|
3692
|
+
# ```
|
3693
|
+
#
|
3694
|
+
# @return [Loc]
|
3695
|
+
attr_reader :operator_l
|
3696
|
+
# Location of the `end` keyword
|
3697
|
+
#
|
3698
|
+
# ```text
|
3699
|
+
# class << foo; end
|
3700
|
+
# ~~~
|
3701
|
+
# ```
|
3702
|
+
#
|
3703
|
+
# @return [Loc]
|
3704
|
+
attr_reader :end_l
|
3705
|
+
# Location of the full expression
|
3706
|
+
#
|
3707
|
+
# ```text
|
3708
|
+
# class << foo; end
|
3709
|
+
# ~~~~~~~~~~~~~~~~~
|
3710
|
+
# ```
|
3711
|
+
#
|
3712
|
+
# @return [Loc]
|
3713
|
+
attr_reader :expression_l
|
3714
|
+
end
|
3715
|
+
|
3716
|
+
# Represents `self` keyword
|
3717
|
+
class Self_ < Node
|
3718
|
+
# Location of the `self` keyword
|
3719
|
+
#
|
3720
|
+
# ```text
|
3721
|
+
# self
|
3722
|
+
# ~~~~
|
3723
|
+
# ```
|
3724
|
+
#
|
3725
|
+
# @return [Loc]
|
3726
|
+
attr_reader :expression_l
|
3727
|
+
end
|
3728
|
+
|
3729
|
+
# Represents a method call (e.g. `foo.bar(42)`)
|
3730
|
+
class Send < Node
|
3731
|
+
# Receiver of the method call
|
3732
|
+
#
|
3733
|
+
# `None` for implicit method call (e.g. `foo(42)`)
|
3734
|
+
#
|
3735
|
+
# @return [Node, nil]
|
3736
|
+
attr_reader :recv
|
3737
|
+
# Name of the method that is called
|
3738
|
+
#
|
3739
|
+
# @return [String]
|
3740
|
+
attr_reader :method_name
|
3741
|
+
# A list of arguments
|
3742
|
+
#
|
3743
|
+
# @return [::Array<Node>]
|
3744
|
+
attr_reader :args
|
3745
|
+
# Location of the `.` operator
|
3746
|
+
#
|
3747
|
+
# ```text
|
3748
|
+
# foo.bar(42)
|
3749
|
+
# ~
|
3750
|
+
# ```
|
3751
|
+
#
|
3752
|
+
# `None` for implicit method call (e.g. `foo(42)`)
|
3753
|
+
#
|
3754
|
+
# @return [Loc, nil]
|
3755
|
+
attr_reader :dot_l
|
3756
|
+
# Location of the method name
|
3757
|
+
#
|
3758
|
+
# ```text
|
3759
|
+
# foo.bar(42)
|
3760
|
+
# ~~~
|
3761
|
+
# ```
|
3762
|
+
#
|
3763
|
+
# `None` in a very special case when method call is implicit (i.e. `foo.(42)`)
|
3764
|
+
#
|
3765
|
+
# @return [Loc, nil]
|
3766
|
+
attr_reader :selector_l
|
3767
|
+
# Location of open parenthesis
|
3768
|
+
#
|
3769
|
+
# ```text
|
3770
|
+
# foo(42)
|
3771
|
+
# ~
|
3772
|
+
# ```
|
3773
|
+
#
|
3774
|
+
# `None` if there are no parentheses
|
3775
|
+
#
|
3776
|
+
# @return [Loc, nil]
|
3777
|
+
attr_reader :begin_l
|
3778
|
+
# Location of closing parenthesis
|
3779
|
+
#
|
3780
|
+
# ```text
|
3781
|
+
# foo(42)
|
3782
|
+
# ~
|
3783
|
+
# ```
|
3784
|
+
#
|
3785
|
+
# `None` if there are no parentheses
|
3786
|
+
#
|
3787
|
+
# @return [Loc, nil]
|
3788
|
+
attr_reader :end_l
|
3789
|
+
# Location of the operator if method is a setter
|
3790
|
+
#
|
3791
|
+
# ```text
|
3792
|
+
# foo.bar = 42
|
3793
|
+
# ~
|
3794
|
+
# ```
|
3795
|
+
#
|
3796
|
+
# `None` otherwise
|
3797
|
+
#
|
3798
|
+
# @return [Loc, nil]
|
3799
|
+
attr_reader :operator_l
|
3800
|
+
# Location of the full expression
|
3801
|
+
#
|
3802
|
+
# ```text
|
3803
|
+
# foo.bar(42)
|
3804
|
+
# ~~~~~~~~~~~
|
3805
|
+
# ```
|
3806
|
+
#
|
3807
|
+
# @return [Loc]
|
3808
|
+
attr_reader :expression_l
|
3809
|
+
end
|
3810
|
+
|
3811
|
+
# Represents a special block argument that "shadows" outer variable (i.e. `|;foo|`)
|
3812
|
+
class Shadowarg < Node
|
3813
|
+
# Name of the argument
|
3814
|
+
#
|
3815
|
+
# @return [String]
|
3816
|
+
attr_reader :name
|
3817
|
+
# Location of the argument
|
3818
|
+
#
|
3819
|
+
# ```text
|
3820
|
+
# proc { |;foo|}
|
3821
|
+
# ~~~
|
3822
|
+
# ```
|
3823
|
+
#
|
3824
|
+
# @return [Loc]
|
3825
|
+
attr_reader :expression_l
|
3826
|
+
end
|
3827
|
+
|
3828
|
+
# Represents an arguments splat (i.e. `*bar` in a call like `foo(*bar)`)
|
3829
|
+
class Splat < Node
|
3830
|
+
# Value that is converted to array
|
3831
|
+
#
|
3832
|
+
# @return [Node, nil]
|
3833
|
+
attr_reader :value
|
3834
|
+
# Location of the `*` operator
|
3835
|
+
#
|
3836
|
+
# ```text
|
3837
|
+
# foo(*bar)
|
3838
|
+
# ~
|
3839
|
+
# ```
|
3840
|
+
#
|
3841
|
+
# @return [Loc]
|
3842
|
+
attr_reader :operator_l
|
3843
|
+
# Location of the full expression
|
3844
|
+
#
|
3845
|
+
# ```text
|
3846
|
+
# foo(*bar)
|
3847
|
+
# ~~~~
|
3848
|
+
# ```
|
3849
|
+
#
|
3850
|
+
# @return [Loc]
|
3851
|
+
attr_reader :expression_l
|
3852
|
+
end
|
3853
|
+
|
3854
|
+
# Represents a plain non-interpolated string literal (e.g. `"foo"`)
|
3855
|
+
class Str < Node
|
3856
|
+
# Value of the string literal
|
3857
|
+
#
|
3858
|
+
# Note that it's a `StringValue`, not a `String`.
|
3859
|
+
# The reason is that you can get UTF-8 incompatible strings
|
3860
|
+
# from a valid UTF-8 source using escape sequences like `"\xFF"`
|
3861
|
+
#
|
3862
|
+
# These "\", "x", "F", "F" chars are valid separately, but together
|
3863
|
+
# they construct a char with code = 255 that is invalid for UTF-8.
|
3864
|
+
#
|
3865
|
+
# You can use `to_string_lossy` or `to_string` methods to get a raw string value.
|
3866
|
+
#
|
3867
|
+
# @return [String]
|
3868
|
+
attr_reader :value
|
3869
|
+
# Location of the string begin
|
3870
|
+
#
|
3871
|
+
# ```text
|
3872
|
+
# "foo"
|
3873
|
+
# ~
|
3874
|
+
# ```
|
3875
|
+
#
|
3876
|
+
# `None` if string literal is a part of the words array (like `%w[foo bar baz]`)
|
3877
|
+
#
|
3878
|
+
# @return [Loc, nil]
|
3879
|
+
attr_reader :begin_l
|
3880
|
+
# Location of the string begin
|
3881
|
+
#
|
3882
|
+
# ```text
|
3883
|
+
# "foo"
|
3884
|
+
# ~
|
3885
|
+
# ```
|
3886
|
+
#
|
3887
|
+
# `None` if string literal is a part of the words array (like `%w[foo bar baz]`)
|
3888
|
+
#
|
3889
|
+
# @return [Loc, nil]
|
3890
|
+
attr_reader :end_l
|
3891
|
+
# Location of the full expression
|
3892
|
+
#
|
3893
|
+
# ```text
|
3894
|
+
# "foo"
|
3895
|
+
# ~~~~~
|
3896
|
+
# ```
|
3897
|
+
#
|
3898
|
+
# @return [Loc]
|
3899
|
+
attr_reader :expression_l
|
3900
|
+
end
|
3901
|
+
|
3902
|
+
# Represents a `super` keyword
|
3903
|
+
class Super < Node
|
3904
|
+
# A list of arguments given to `super`
|
3905
|
+
#
|
3906
|
+
# @return [::Array<Node>]
|
3907
|
+
attr_reader :args
|
3908
|
+
# Location of the `super` keyword
|
3909
|
+
#
|
3910
|
+
# ```text
|
3911
|
+
# super(1, 2)
|
3912
|
+
# ~~~~~
|
3913
|
+
# ```
|
3914
|
+
#
|
3915
|
+
# @return [Loc]
|
3916
|
+
attr_reader :keyword_l
|
3917
|
+
# Location of the open parenthesis
|
3918
|
+
#
|
3919
|
+
# ```text
|
3920
|
+
# super(1, 2)
|
3921
|
+
# ~
|
3922
|
+
# ```
|
3923
|
+
#
|
3924
|
+
# `None` if there are no parentheses
|
3925
|
+
#
|
3926
|
+
# @return [Loc, nil]
|
3927
|
+
attr_reader :begin_l
|
3928
|
+
# Location of the closing parenthesis
|
3929
|
+
#
|
3930
|
+
# ```text
|
3931
|
+
# super(1, 2)
|
3932
|
+
# ~
|
3933
|
+
# ```
|
3934
|
+
#
|
3935
|
+
# `None` if there are no parentheses
|
3936
|
+
#
|
3937
|
+
# @return [Loc, nil]
|
3938
|
+
attr_reader :end_l
|
3939
|
+
# Location of the full expression
|
3940
|
+
#
|
3941
|
+
# ```text
|
3942
|
+
# super(1, 2)
|
3943
|
+
# ~~~~~~~~~~~
|
3944
|
+
# ```
|
3945
|
+
#
|
3946
|
+
# @return [Loc]
|
3947
|
+
attr_reader :expression_l
|
3948
|
+
end
|
3949
|
+
|
3950
|
+
# Represents a plain symbol literal (i.e. `:foo`)
|
3951
|
+
#
|
3952
|
+
# Note that `:` in `{ foo: bar }` belongs to a `pair` node.
|
3953
|
+
class Sym < Node
|
3954
|
+
# Value of the symbol literal
|
3955
|
+
#
|
3956
|
+
# Note that it's a `StringValue`, not a `String`.
|
3957
|
+
# The reason is that you can get UTF-8 incompatible strings
|
3958
|
+
# from a valid UTF-8 source using escape sequences like `"\xFF"`
|
3959
|
+
#
|
3960
|
+
# These "\", "x", "F", "F" chars are valid separately, but together
|
3961
|
+
# they construct a char with code = 255 that is invalid for UTF-8.
|
3962
|
+
#
|
3963
|
+
# You can use `to_string_lossy` or `to_string` methods to get a raw symbol value.
|
3964
|
+
#
|
3965
|
+
# @return [String]
|
3966
|
+
attr_reader :name
|
3967
|
+
# Location of the symbol begin
|
3968
|
+
#
|
3969
|
+
# ```text
|
3970
|
+
# :foo
|
3971
|
+
# ~
|
3972
|
+
# ```
|
3973
|
+
#
|
3974
|
+
# `None` if symbol is a label (`{ foo: 1 }`) or a part of the symbols array (`%i[foo bar baz]`)
|
3975
|
+
#
|
3976
|
+
# @return [Loc, nil]
|
3977
|
+
attr_reader :begin_l
|
3978
|
+
# Location of the symbol end
|
3979
|
+
#
|
3980
|
+
# ```text
|
3981
|
+
# { 'foo': 1 }
|
3982
|
+
# ~
|
3983
|
+
# ```
|
3984
|
+
#
|
3985
|
+
# `None` if symbol is **not** a string label (`:foo`) or a part of the symbols array (`%i[foo bar baz]`)
|
3986
|
+
#
|
3987
|
+
# @return [Loc, nil]
|
3988
|
+
attr_reader :end_l
|
3989
|
+
# Location of the full expression
|
3990
|
+
#
|
3991
|
+
# ```text
|
3992
|
+
# :foo
|
3993
|
+
# ~~~~
|
3994
|
+
#
|
3995
|
+
# { foo: 1 }
|
3996
|
+
# ~~~~
|
3997
|
+
#
|
3998
|
+
# %i[foo]
|
3999
|
+
# ~~~
|
4000
|
+
# ```
|
4001
|
+
#
|
4002
|
+
# @return [Loc]
|
4003
|
+
attr_reader :expression_l
|
4004
|
+
end
|
4005
|
+
|
4006
|
+
# Represents a `true` literal
|
4007
|
+
class True < Node
|
4008
|
+
# Location of the `true` keyword
|
4009
|
+
#
|
4010
|
+
# ```text
|
4011
|
+
# true
|
4012
|
+
# ~~~~
|
4013
|
+
# ```
|
4014
|
+
#
|
4015
|
+
# @return [Loc]
|
4016
|
+
attr_reader :expression_l
|
4017
|
+
end
|
4018
|
+
|
4019
|
+
# Represents an `undef` keyword (e.g. `undef foo, :bar`)
|
4020
|
+
class Undef < Node
|
4021
|
+
# A list of names to `undef`
|
4022
|
+
#
|
4023
|
+
# @return [::Array<Node>]
|
4024
|
+
attr_reader :names
|
4025
|
+
# Location the `undef` keyword
|
4026
|
+
#
|
4027
|
+
# ```text
|
4028
|
+
# undef foo, :bar
|
4029
|
+
# ~~~~~
|
4030
|
+
# ```
|
4031
|
+
#
|
4032
|
+
# @return [Loc]
|
4033
|
+
attr_reader :keyword_l
|
4034
|
+
# Location of the full expression
|
4035
|
+
#
|
4036
|
+
# ```text
|
4037
|
+
# undef :foo, bar
|
4038
|
+
# ~~~~~~~~~~~~~~~
|
4039
|
+
# ```
|
4040
|
+
#
|
4041
|
+
# @return [Loc]
|
4042
|
+
attr_reader :expression_l
|
4043
|
+
end
|
4044
|
+
|
4045
|
+
# Represents an `unless` guard used in pattern matching (i.e. `in pattern unless guard`)
|
4046
|
+
class UnlessGuard < Node
|
4047
|
+
# Condition of the guard, `Lvar("foo")` in `in pattern unless guard`
|
4048
|
+
#
|
4049
|
+
# @return [Node]
|
4050
|
+
attr_reader :cond
|
4051
|
+
# Location of the `unless` keyword
|
4052
|
+
#
|
4053
|
+
# ```text
|
4054
|
+
# case foo; in pattern unless cond; end
|
4055
|
+
# ~~~~~~
|
4056
|
+
# ```
|
4057
|
+
#
|
4058
|
+
# @return [Loc]
|
4059
|
+
attr_reader :keyword_l
|
4060
|
+
# Location of the full expression
|
4061
|
+
#
|
4062
|
+
# ```text
|
4063
|
+
# case foo; in pattern unless cond; end
|
4064
|
+
# ~~~~~~~~~~~
|
4065
|
+
# ```
|
4066
|
+
#
|
4067
|
+
# @return [Loc]
|
4068
|
+
attr_reader :expression_l
|
4069
|
+
end
|
4070
|
+
|
4071
|
+
# Represents `until` loop
|
4072
|
+
class Until < Node
|
4073
|
+
# Condition of the loop
|
4074
|
+
#
|
4075
|
+
# @return [Node]
|
4076
|
+
attr_reader :cond
|
4077
|
+
# Body of the loop.
|
4078
|
+
#
|
4079
|
+
# `None` if body is empty
|
4080
|
+
#
|
4081
|
+
# @return [Node, nil]
|
4082
|
+
attr_reader :body
|
4083
|
+
# Location of the `until` keyword
|
4084
|
+
#
|
4085
|
+
# ```text
|
4086
|
+
# until cond do; foo; end
|
4087
|
+
# ~~~~~
|
4088
|
+
# ```
|
4089
|
+
#
|
4090
|
+
# @return [Loc]
|
4091
|
+
attr_reader :keyword_l
|
4092
|
+
# Location of the `do` keyword
|
4093
|
+
#
|
4094
|
+
# ```text
|
4095
|
+
# until cond do; foo; end
|
4096
|
+
# ~~
|
4097
|
+
# ```
|
4098
|
+
#
|
4099
|
+
# `do` is optional, and so `begin_l` can be `None`
|
4100
|
+
#
|
4101
|
+
# @return [Loc, nil]
|
4102
|
+
attr_reader :begin_l
|
4103
|
+
# Location of the `end` keyword
|
4104
|
+
#
|
4105
|
+
# ```text
|
4106
|
+
# until cond do; foo; end
|
4107
|
+
# ~~~
|
4108
|
+
# ```
|
4109
|
+
#
|
4110
|
+
# `None` if loop is a modifier (i.e. `foo until bar`)
|
4111
|
+
#
|
4112
|
+
# @return [Loc, nil]
|
4113
|
+
attr_reader :end_l
|
4114
|
+
# Location of the full expression
|
4115
|
+
#
|
4116
|
+
# ```text
|
4117
|
+
# until cond do; foo; end
|
4118
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~
|
4119
|
+
#
|
4120
|
+
# foo until bar
|
4121
|
+
# ~~~~~~~~~~~~~
|
4122
|
+
# ```
|
4123
|
+
#
|
4124
|
+
# @return [Loc]
|
4125
|
+
attr_reader :expression_l
|
4126
|
+
end
|
4127
|
+
|
4128
|
+
# Represents a post-until loop
|
4129
|
+
#
|
4130
|
+
# ```text
|
4131
|
+
# begin
|
4132
|
+
# foo
|
4133
|
+
# end until bar
|
4134
|
+
# ```
|
4135
|
+
class UntilPost < Node
|
4136
|
+
# Condition of the loop
|
4137
|
+
#
|
4138
|
+
# @return [Node]
|
4139
|
+
attr_reader :cond
|
4140
|
+
# Body of the loop
|
4141
|
+
#
|
4142
|
+
# @return [Node]
|
4143
|
+
attr_reader :body
|
4144
|
+
# Location of the `until` keyword
|
4145
|
+
#
|
4146
|
+
# ```text
|
4147
|
+
# begin; foo; end until bar
|
4148
|
+
# ~~~~~
|
4149
|
+
# ```
|
4150
|
+
#
|
4151
|
+
# @return [Loc]
|
4152
|
+
attr_reader :keyword_l
|
4153
|
+
# Location of the `until` keyword
|
4154
|
+
#
|
4155
|
+
# ```text
|
4156
|
+
# begin; foo; end until bar
|
4157
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
|
4158
|
+
# ```
|
4159
|
+
#
|
4160
|
+
# @return [Loc]
|
4161
|
+
attr_reader :expression_l
|
4162
|
+
end
|
4163
|
+
|
4164
|
+
# Represents a branch of the `case` statement (i.e. `when foo`)
|
4165
|
+
class When < Node
|
4166
|
+
# A list of values to compare/match against
|
4167
|
+
#
|
4168
|
+
# @return [::Array<Node>]
|
4169
|
+
attr_reader :patterns
|
4170
|
+
# Body of the `when` branch
|
4171
|
+
#
|
4172
|
+
# @return [Node, nil]
|
4173
|
+
attr_reader :body
|
4174
|
+
# Location of the `when` keyword
|
4175
|
+
#
|
4176
|
+
# ```text
|
4177
|
+
# case foo; when bar; end
|
4178
|
+
# ~~~~
|
4179
|
+
# ```
|
4180
|
+
#
|
4181
|
+
# @return [Loc]
|
4182
|
+
attr_reader :keyword_l
|
4183
|
+
# Location of the `then` keyword
|
4184
|
+
#
|
4185
|
+
# ```text
|
4186
|
+
# case foo; when bar then baz; end
|
4187
|
+
# ~~~~
|
4188
|
+
# ```
|
4189
|
+
#
|
4190
|
+
# `then` is optional, and so `begin_l` can be `None`
|
4191
|
+
#
|
4192
|
+
# @return [Loc]
|
4193
|
+
attr_reader :begin_l
|
4194
|
+
# Location of the full expression
|
4195
|
+
#
|
4196
|
+
# ```text
|
4197
|
+
# case foo; when bar then baz; end
|
4198
|
+
# ~~~~~~~~~~~~~~~~~
|
4199
|
+
# ```
|
4200
|
+
#
|
4201
|
+
# @return [Loc]
|
4202
|
+
attr_reader :expression_l
|
4203
|
+
end
|
4204
|
+
|
4205
|
+
# Represents `while` loop
|
4206
|
+
class While < Node
|
4207
|
+
# Condition of the loop
|
4208
|
+
#
|
4209
|
+
# @return [Node]
|
4210
|
+
attr_reader :cond
|
4211
|
+
# Body of the loop.
|
4212
|
+
#
|
4213
|
+
# `None` if body is empty
|
4214
|
+
#
|
4215
|
+
# @return [Node, nil]
|
4216
|
+
attr_reader :body
|
4217
|
+
# Location of the `while` keyword
|
4218
|
+
#
|
4219
|
+
# ```text
|
4220
|
+
# while cond do; foo; end
|
4221
|
+
# ~~~~~
|
4222
|
+
# ```
|
4223
|
+
#
|
4224
|
+
# @return [Loc]
|
4225
|
+
attr_reader :keyword_l
|
4226
|
+
# Location of the `do` keyword
|
4227
|
+
#
|
4228
|
+
# ```text
|
4229
|
+
# while cond do; foo; end
|
4230
|
+
# ~~
|
4231
|
+
# ```
|
4232
|
+
#
|
4233
|
+
# `do` is optional, and so `begin_l` can be `None`
|
4234
|
+
#
|
4235
|
+
# @return [Loc, nil]
|
4236
|
+
attr_reader :begin_l
|
4237
|
+
# Location of the `end` keyword
|
4238
|
+
#
|
4239
|
+
# ```text
|
4240
|
+
# while cond do; foo; end
|
4241
|
+
# ~~~
|
4242
|
+
# ```
|
4243
|
+
#
|
4244
|
+
# `None` if loop is a modifier (i.e. `foo while bar`)
|
4245
|
+
#
|
4246
|
+
# @return [Loc, nil]
|
4247
|
+
attr_reader :end_l
|
4248
|
+
# Location of the full expression
|
4249
|
+
#
|
4250
|
+
# ```text
|
4251
|
+
# while cond do; foo; end
|
4252
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~
|
4253
|
+
#
|
4254
|
+
# foo while bar
|
4255
|
+
# ~~~~~~~~~~~~~
|
4256
|
+
# ```
|
4257
|
+
#
|
4258
|
+
# @return [Loc]
|
4259
|
+
attr_reader :expression_l
|
4260
|
+
end
|
4261
|
+
|
4262
|
+
# Represents a post-while loop
|
4263
|
+
#
|
4264
|
+
# ```text
|
4265
|
+
# begin
|
4266
|
+
# foo
|
4267
|
+
# end while bar
|
4268
|
+
# ```
|
4269
|
+
class WhilePost < Node
|
4270
|
+
# Condition of the loop
|
4271
|
+
#
|
4272
|
+
# @return [Node]
|
4273
|
+
attr_reader :cond
|
4274
|
+
# Body of the loop
|
4275
|
+
#
|
4276
|
+
# @return [Node]
|
4277
|
+
attr_reader :body
|
4278
|
+
# Location of the `while` keyword
|
4279
|
+
#
|
4280
|
+
# ```text
|
4281
|
+
# begin; foo; end while bar
|
4282
|
+
# ~~~~~
|
4283
|
+
# ```
|
4284
|
+
#
|
4285
|
+
# @return [Loc]
|
4286
|
+
attr_reader :keyword_l
|
4287
|
+
# Location of the `while` keyword
|
4288
|
+
#
|
4289
|
+
# ```text
|
4290
|
+
# begin; foo; end while bar
|
4291
|
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~
|
4292
|
+
# ```
|
4293
|
+
#
|
4294
|
+
# @return [Loc]
|
4295
|
+
attr_reader :expression_l
|
4296
|
+
end
|
4297
|
+
|
4298
|
+
# Represents a executable here-document literal (both with and without interpolation)
|
4299
|
+
#
|
4300
|
+
# It's similar to `Xstr` in terms of abstract syntax tree, but has different source maps.
|
4301
|
+
class XHeredoc < Node
|
4302
|
+
# A list of string parts (static literals and interpolated expressions)
|
4303
|
+
#
|
4304
|
+
# @return [::Array<Node>]
|
4305
|
+
attr_reader :parts
|
4306
|
+
# Location of the executable here-document body
|
4307
|
+
#
|
4308
|
+
# ```text
|
4309
|
+
# <<-`HERE`\n a\n #{42}\nHERE
|
4310
|
+
# ~~~~~~~~~~~~~~~
|
4311
|
+
# ```
|
4312
|
+
#
|
4313
|
+
# @return [Loc]
|
4314
|
+
attr_reader :heredoc_body_l
|
4315
|
+
# Location of the executable here-document end
|
4316
|
+
#
|
4317
|
+
# ```text
|
4318
|
+
# <<-`HERE`\n a\n #{42}\nHERE
|
4319
|
+
# ~~~~
|
4320
|
+
# ```
|
4321
|
+
#
|
4322
|
+
# @return [Loc]
|
4323
|
+
attr_reader :heredoc_end_l
|
4324
|
+
# Location of the executable here-document identifier
|
4325
|
+
#
|
4326
|
+
# ```text
|
4327
|
+
# <<-`HERE`\n a\n #{42}\nHERE
|
4328
|
+
# ~~~~~~~
|
4329
|
+
# ```
|
4330
|
+
#
|
4331
|
+
# **Note**: This is the only node (with `Heredoc`) that has `expression_l` smaller that all other sub-locations merged.
|
4332
|
+
# The reason for that is that it's possible to add more code after here-document ID:
|
4333
|
+
#
|
4334
|
+
# ```text
|
4335
|
+
# <<-`HERE` + "rest"
|
4336
|
+
# content
|
4337
|
+
# HERE
|
4338
|
+
# ```
|
4339
|
+
#
|
4340
|
+
# @return [Loc]
|
4341
|
+
attr_reader :expression_l
|
4342
|
+
end
|
4343
|
+
|
4344
|
+
# Represents an executable string (i.e. `` `sh #{script_name}` ``)
|
4345
|
+
class Xstr < Node
|
4346
|
+
# A list of string parts (static literals and interpolated expressions)
|
4347
|
+
#
|
4348
|
+
# @return [::Array<Node>]
|
4349
|
+
attr_reader :parts
|
4350
|
+
# Location of the string begin
|
4351
|
+
#
|
4352
|
+
# ```text
|
4353
|
+
# `#{foo}`
|
4354
|
+
# ~
|
4355
|
+
#
|
4356
|
+
# %X{#{foo}}
|
4357
|
+
# ~~~
|
4358
|
+
# ```
|
4359
|
+
#
|
4360
|
+
# @return [Loc]
|
4361
|
+
attr_reader :begin_l
|
4362
|
+
# Location of the string end
|
4363
|
+
#
|
4364
|
+
# ```text
|
4365
|
+
# `#{foo}`
|
4366
|
+
# ~
|
4367
|
+
#
|
4368
|
+
# %X{#{foo}}
|
4369
|
+
# ~
|
4370
|
+
# ```
|
4371
|
+
#
|
4372
|
+
# @return [Loc]
|
4373
|
+
attr_reader :end_l
|
4374
|
+
# Location of the full expression
|
4375
|
+
#
|
4376
|
+
# ```text
|
4377
|
+
# `#{foo}`
|
4378
|
+
# ~~~~~~~~
|
4379
|
+
#
|
4380
|
+
# %X{#{foo}}
|
4381
|
+
# ~~~~~~~~~~
|
4382
|
+
# ```
|
4383
|
+
#
|
4384
|
+
# @return [Loc]
|
4385
|
+
attr_reader :expression_l
|
4386
|
+
end
|
4387
|
+
|
4388
|
+
# Represents an `yield` keyword
|
4389
|
+
class Yield < Node
|
4390
|
+
# A list of arguments given to `yield`
|
4391
|
+
#
|
4392
|
+
# @return [::Array<Node>]
|
4393
|
+
attr_reader :args
|
4394
|
+
# Location of the `yield` keyword
|
4395
|
+
#
|
4396
|
+
# ```text
|
4397
|
+
# yield 1, 2
|
4398
|
+
# ~~~~~
|
4399
|
+
# ```
|
4400
|
+
#
|
4401
|
+
# @return [Loc]
|
4402
|
+
attr_reader :keyword_l
|
4403
|
+
# Location of the open parenthesis
|
4404
|
+
#
|
4405
|
+
# ```text
|
4406
|
+
# yield(1, 2)
|
4407
|
+
# ~
|
4408
|
+
# ```
|
4409
|
+
#
|
4410
|
+
# `None` if there are no parentheses
|
4411
|
+
#
|
4412
|
+
# @return [Loc, nil]
|
4413
|
+
attr_reader :begin_l
|
4414
|
+
# Location of the closing parenthesis
|
4415
|
+
#
|
4416
|
+
# ```text
|
4417
|
+
# yield(1, 2)
|
4418
|
+
# ~
|
4419
|
+
# ```
|
4420
|
+
#
|
4421
|
+
# `None` if there are no parentheses
|
4422
|
+
#
|
4423
|
+
# @return [Loc, nil]
|
4424
|
+
attr_reader :end_l
|
4425
|
+
# Location of the full expression
|
4426
|
+
#
|
4427
|
+
# ```text
|
4428
|
+
# yield(1, 2)
|
4429
|
+
# ~~~~~~~~~~~
|
4430
|
+
# ```
|
4431
|
+
#
|
4432
|
+
# @return [Loc]
|
4433
|
+
attr_reader :expression_l
|
4434
|
+
end
|
4435
|
+
|
4436
|
+
# Represents a `super` call without arguments and parentheses
|
4437
|
+
#
|
4438
|
+
# It's different from `super()` as it implicitly forwards current arguments
|
4439
|
+
class ZSuper < Node
|
4440
|
+
# Location of the `super` keyword
|
4441
|
+
#
|
4442
|
+
# ```text
|
4443
|
+
# super
|
4444
|
+
# ~~~~~
|
4445
|
+
# ```
|
4446
|
+
#
|
4447
|
+
# @return [Loc]
|
4448
|
+
attr_reader :expression_l
|
4449
|
+
end
|
4450
|
+
|
4451
|
+
end
|
4452
|
+
end
|