parser 2.6.5.0 → 2.7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/lib/parser.rb +4 -1
  3. data/lib/parser/all.rb +1 -0
  4. data/lib/parser/ast/processor.rb +21 -0
  5. data/lib/parser/base.rb +25 -5
  6. data/lib/parser/builders/default.rb +394 -24
  7. data/lib/parser/context.rb +5 -0
  8. data/lib/parser/current.rb +16 -7
  9. data/lib/parser/current_arg_stack.rb +43 -0
  10. data/lib/parser/diagnostic.rb +1 -1
  11. data/lib/parser/diagnostic/engine.rb +1 -2
  12. data/lib/parser/lexer.rb +23770 -0
  13. data/lib/parser/lexer/dedenter.rb +52 -49
  14. data/lib/parser/macruby.rb +6149 -0
  15. data/lib/parser/{lexer/max_numparam_stack.rb → max_numparam_stack.rb} +10 -4
  16. data/lib/parser/messages.rb +52 -29
  17. data/lib/parser/meta.rb +10 -5
  18. data/lib/parser/ruby18.rb +5663 -0
  19. data/lib/parser/ruby19.rb +6092 -0
  20. data/lib/parser/ruby20.rb +6527 -0
  21. data/lib/parser/ruby21.rb +6578 -0
  22. data/lib/parser/ruby22.rb +6613 -0
  23. data/lib/parser/ruby23.rb +6624 -0
  24. data/lib/parser/ruby24.rb +6694 -0
  25. data/lib/parser/ruby25.rb +6662 -0
  26. data/lib/parser/ruby26.rb +6676 -0
  27. data/lib/parser/ruby27.rb +7803 -0
  28. data/lib/parser/ruby28.rb +8047 -0
  29. data/lib/parser/ruby30.rb +8052 -0
  30. data/lib/parser/rubymotion.rb +6086 -0
  31. data/lib/parser/runner.rb +26 -2
  32. data/lib/parser/runner/ruby_rewrite.rb +2 -2
  33. data/lib/parser/source/buffer.rb +3 -1
  34. data/lib/parser/source/comment.rb +1 -1
  35. data/lib/parser/source/comment/associator.rb +14 -4
  36. data/lib/parser/source/map/method_definition.rb +25 -0
  37. data/lib/parser/source/range.rb +19 -3
  38. data/lib/parser/source/tree_rewriter.rb +115 -12
  39. data/lib/parser/source/tree_rewriter/action.rb +137 -28
  40. data/lib/parser/static_environment.rb +10 -0
  41. data/lib/parser/tree_rewriter.rb +1 -2
  42. data/lib/parser/variables_stack.rb +32 -0
  43. data/lib/parser/version.rb +1 -1
  44. data/parser.gemspec +10 -18
  45. metadata +22 -99
  46. data/.gitignore +0 -33
  47. data/.travis.yml +0 -45
  48. data/.yardopts +0 -21
  49. data/CHANGELOG.md +0 -997
  50. data/CONTRIBUTING.md +0 -17
  51. data/Gemfile +0 -10
  52. data/LICENSE.txt +0 -25
  53. data/README.md +0 -301
  54. data/Rakefile +0 -166
  55. data/ci/run_rubocop_specs +0 -14
  56. data/doc/AST_FORMAT.md +0 -1816
  57. data/doc/CUSTOMIZATION.md +0 -37
  58. data/doc/INTERNALS.md +0 -21
  59. data/doc/css/.gitkeep +0 -0
  60. data/doc/css/common.css +0 -68
  61. data/lib/parser/lexer.rl +0 -2533
  62. data/lib/parser/macruby.y +0 -2198
  63. data/lib/parser/ruby18.y +0 -1934
  64. data/lib/parser/ruby19.y +0 -2175
  65. data/lib/parser/ruby20.y +0 -2353
  66. data/lib/parser/ruby21.y +0 -2357
  67. data/lib/parser/ruby22.y +0 -2364
  68. data/lib/parser/ruby23.y +0 -2370
  69. data/lib/parser/ruby24.y +0 -2408
  70. data/lib/parser/ruby25.y +0 -2405
  71. data/lib/parser/ruby26.y +0 -2413
  72. data/lib/parser/ruby27.y +0 -2470
  73. data/lib/parser/rubymotion.y +0 -2182
  74. data/test/bug_163/fixtures/input.rb +0 -5
  75. data/test/bug_163/fixtures/output.rb +0 -5
  76. data/test/bug_163/rewriter.rb +0 -20
  77. data/test/helper.rb +0 -59
  78. data/test/parse_helper.rb +0 -316
  79. data/test/racc_coverage_helper.rb +0 -133
  80. data/test/test_base.rb +0 -31
  81. data/test/test_current.rb +0 -29
  82. data/test/test_diagnostic.rb +0 -96
  83. data/test/test_diagnostic_engine.rb +0 -62
  84. data/test/test_encoding.rb +0 -99
  85. data/test/test_lexer.rb +0 -3667
  86. data/test/test_lexer_stack_state.rb +0 -78
  87. data/test/test_parse_helper.rb +0 -80
  88. data/test/test_parser.rb +0 -7644
  89. data/test/test_runner_parse.rb +0 -35
  90. data/test/test_runner_rewrite.rb +0 -47
  91. data/test/test_source_buffer.rb +0 -162
  92. data/test/test_source_comment.rb +0 -36
  93. data/test/test_source_comment_associator.rb +0 -367
  94. data/test/test_source_map.rb +0 -15
  95. data/test/test_source_range.rb +0 -172
  96. data/test/test_source_rewriter.rb +0 -541
  97. data/test/test_source_rewriter_action.rb +0 -46
  98. data/test/test_source_tree_rewriter.rb +0 -173
  99. data/test/test_static_environment.rb +0 -45
  100. data/test/using_tree_rewriter/fixtures/input.rb +0 -3
  101. data/test/using_tree_rewriter/fixtures/output.rb +0 -3
  102. data/test/using_tree_rewriter/using_tree_rewriter.rb +0 -9
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- set -eux
4
-
5
- bundle install
6
- rake generate
7
-
8
- git clone https://github.com/rubocop-hq/rubocop.git --depth=1
9
- cd rubocop
10
- export BUNDLE_GEMFILE=Gemfile
11
- echo "gem 'parser', path: '../'" > Gemfile.local
12
-
13
- bundle install
14
- bundle exec rake spec
@@ -1,1816 +0,0 @@
1
- AST and Source Location
2
- =======================
3
-
4
- ## Literals
5
-
6
- ### Singletons
7
-
8
- Format:
9
-
10
- ~~~
11
- (true)
12
- "true"
13
- ~~~~ expression
14
-
15
- (false)
16
- "false"
17
- ~~~~~ expression
18
-
19
- (nil)
20
- "nil"
21
- ~~~ expression
22
- ~~~
23
-
24
- ### Integer
25
-
26
- Format:
27
-
28
- ~~~
29
- (int 123)
30
- "123"
31
- ~~~ expression
32
-
33
- (int -123)
34
- "-123"
35
- ^ operator
36
- ~~~ expression
37
-
38
- (int 1)
39
- "__LINE__"
40
- ~~~~~~~~ expression
41
- ~~~
42
-
43
- ### Float
44
-
45
- Format:
46
-
47
- ~~~
48
- (float 1.0)
49
- "1.0"
50
- ~~~ expression
51
-
52
- (float -1.0)
53
- "-1.0"
54
- ^ operator
55
- ~~~~ expression
56
- ~~~
57
-
58
- ### Complex
59
-
60
- Format:
61
-
62
- ~~~
63
- (complex (0+1i))
64
- "1i"
65
- ~~ expression
66
-
67
- (complex (0+(1/1)*i))
68
- "1ri"
69
- ~~~ expression
70
- ~~~
71
-
72
- ### Rational
73
-
74
- Format:
75
-
76
- ~~~
77
- (rational (2/1))
78
- "2.0r"
79
- ~~~~ expression
80
- ~~~
81
-
82
- ### String
83
-
84
- #### Plain
85
-
86
- Format:
87
-
88
- ~~~
89
- (str "foo")
90
- "'foo'"
91
- ^ begin
92
- ^ end
93
- ~~~~~ expresion
94
-
95
- (string "foo.rb")
96
- "__FILE__"
97
- ~~~~~~~~ expression
98
- ~~~
99
-
100
- #### With interpolation
101
-
102
- Format:
103
-
104
- ~~~
105
- (dstr (str "foo") (begin (lvar bar)) (str "baz"))
106
- '"foo#{bar}baz"'
107
- ^ begin ^ end
108
- ~~~~~~~~~~~~~~ expression
109
- ^^ begin (begin)
110
- ^ end (begin)
111
- ^^^^^^ expression (begin)
112
- ~~~
113
-
114
- #### Here document
115
-
116
- Format:
117
-
118
- ~~~
119
- (str "foo\nbar\n")
120
- '<<HERE␊foo␊bar␊HERE'
121
- ~~~~~~ expression
122
- ~~~~~~~~ heredoc_body
123
- ~~~~ heredoc_end
124
- ~~~
125
-
126
- ### Symbol
127
-
128
- #### Plain
129
-
130
- Format:
131
-
132
- ~~~
133
- (sym :foo)
134
- ":foo"
135
- ~~~~ expresion
136
-
137
- ":'foo'"
138
- ^ begin
139
- ^ end
140
- ~~~~~~ expression
141
- ~~~
142
-
143
- #### With interpolation
144
-
145
- Format:
146
-
147
- ~~~
148
- (dsym (str "foo") (lvar bar) (str "baz"))
149
- ':"foo#{bar}baz"'
150
- ^ begin ^ end
151
- ~~~~~~~~~~~~~~~ expression
152
- ~~~
153
-
154
- ### Execute-string
155
-
156
- #### Plain
157
-
158
- Format:
159
-
160
- ~~~
161
- (xstr (str "foo") (lvar bar))
162
- "`foo#{bar}`"
163
- ^ begin ^ end
164
- ~~~~~~~~~~~ expression
165
- ~~~
166
-
167
- #### Here document
168
-
169
- Format:
170
-
171
- ~~~
172
- (xstr (str "foo\nbar\n"))
173
- "<<`HERE`␊foo␊bar␊HERE"
174
- ~~~~~~~~ expression
175
- ~~~~~~~~ heredoc_body
176
- ~~~~ heredoc_end
177
- ~~~
178
-
179
- ### Regexp
180
-
181
- #### Options
182
-
183
- Format:
184
-
185
- ~~~
186
- (regopt :i :m)
187
- "im"
188
- ~~ expression
189
- ~~~
190
-
191
- #### Regexp
192
-
193
- Format:
194
-
195
- ~~~
196
- (regexp (str "foo") (lvar :bar) (regopt :i))
197
- "/foo#{bar}/i"
198
- ^ begin ^ end
199
- ~~~~~~~~~~~ expression
200
- ~~~
201
-
202
- ### Array
203
-
204
- #### Plain
205
-
206
- Format:
207
-
208
- ~~~
209
- (array (int 1) (int 2))
210
-
211
- "[1, 2]"
212
- ^ begin
213
- ^ end
214
- ~~~~~~ expression
215
- ~~~
216
-
217
- #### Splat
218
-
219
- Can also be used in argument lists: `foo(bar, *baz)`
220
-
221
- Format:
222
-
223
- ~~~
224
- (splat (lvar :foo))
225
- "*foo"
226
- ^ operator
227
- ~~~~ expression
228
- ~~~
229
-
230
- #### With interpolation
231
-
232
- Format:
233
-
234
- ~~~
235
- (array (int 1) (splat (lvar :foo)) (int 2))
236
-
237
- "[1, *foo, 2]"
238
- ^ begin ^ end
239
- ~~~~~~~~~~~~ expression
240
- ~~~
241
-
242
- ### Hash
243
-
244
- #### Pair
245
-
246
- ##### With hashrocket
247
-
248
- Format:
249
-
250
- ~~~
251
- (pair (int 1) (int 2))
252
- "1 => 2"
253
- ~~ operator
254
- ~~~~~~ expression
255
- ~~~
256
-
257
- ##### With label (1.9)
258
-
259
- Format:
260
-
261
- ~~~
262
- (pair (sym :answer) (int 42))
263
- "answer: 42"
264
- ^ operator (pair)
265
- ~~~~~~ expression (sym)
266
- ~~~~~~~~~~ expression (pair)
267
- ~~~
268
-
269
- #### Plain
270
-
271
- Format:
272
-
273
- ~~~
274
- (hash (pair (int 1) (int 2)) (pair (int 3) (int 4)))
275
- "{1 => 2, 3 => 4}"
276
- ^ begin ^ end
277
- ~~~~~~~~~~~~~~~~ expression
278
- ~~~
279
-
280
- #### Keyword splat (2.0)
281
-
282
- Can also be used in argument lists: `foo(bar, **baz)`
283
-
284
- Format:
285
-
286
- ~~~
287
- (kwsplat (lvar :foo))
288
- "**foo"
289
- ~~ operator
290
- ~~~~~ expression
291
- ~~~
292
-
293
- #### With interpolation (2.0)
294
-
295
- Format:
296
-
297
- ~~~
298
- (hash (pair (sym :foo) (int 2)) (kwsplat (lvar :bar)))
299
- "{ foo: 2, **bar }"
300
- ^ begin ^ end
301
- ~~~~~~~~~~~~~~~~~ expression
302
- ~~~
303
-
304
- ### Range
305
-
306
- #### Inclusive
307
-
308
- Format:
309
-
310
- ~~~
311
- (irange (int 1) (int 2))
312
- "1..2"
313
- ~~ operator
314
- ~~~~ expression
315
- ~~~
316
-
317
- #### Exclusive
318
-
319
- Format:
320
-
321
- ~~~
322
- (erange (int 1) (int 2))
323
- "1...2"
324
- ~~~ operator
325
- ~~~~~ expression
326
- ~~~
327
-
328
-
329
- ### Endless (2.6)
330
-
331
- Format:
332
-
333
- ~~~
334
- (irange (int 1) nil)
335
- "1.."
336
- ~~ operator
337
- ~~~ expression
338
-
339
- (erange (int 1) nil)
340
- "1..."
341
- ~~~ operator
342
- ~~~~ expression
343
- ~~~
344
-
345
- ### Beginless (2.7)
346
-
347
- Format:
348
-
349
- ~~~
350
- (irange nil (int 1))
351
- "..1"
352
- ~~ operator
353
- ~~~ expression
354
-
355
- (erange nil (int 1))
356
- "...1"
357
- ~~~ operator
358
- ~~~~ expression
359
- ~~~
360
-
361
- ## Access
362
-
363
- ### Self
364
-
365
- Format:
366
-
367
- ~~~
368
- (self)
369
- "self"
370
- ~~~~ expression
371
- ~~~
372
-
373
- ### Local variable
374
-
375
- Format:
376
-
377
- ~~~
378
- (lvar :foo)
379
- "foo"
380
- ~~~ expression
381
- ~~~
382
-
383
- ### Instance variable
384
-
385
- Format:
386
-
387
- ~~~
388
- (ivar :@foo)
389
- "@foo"
390
- ~~~~ expression
391
- ~~~
392
-
393
- ### Class variable
394
-
395
- Format:
396
-
397
- ~~~
398
- (cvar :@@foo)
399
- "@@foo"
400
- ~~~~~ expression
401
- ~~~
402
-
403
- ### Global variable
404
-
405
- #### Regular global variable
406
-
407
- Format:
408
-
409
- ~~~
410
- (gvar :$foo)
411
- "$foo"
412
- ~~~~ expression
413
- ~~~
414
-
415
- #### Regular expression capture groups
416
-
417
- Format:
418
-
419
- ~~~
420
- (nth-ref 1)
421
- "$1"
422
- ~~ expression
423
- ~~~
424
-
425
- #### Regular expression back-references
426
-
427
- Format:
428
-
429
- ~~~
430
- (back-ref :$&)
431
- "$&"
432
- ~~ expression
433
- (back-ref :$`)
434
- "$`"
435
- (back-ref :$')
436
- "$'"
437
- (back-ref :$+)
438
- "$+"
439
- ~~~
440
-
441
- ### Constant
442
-
443
- #### Top-level constant
444
-
445
- Format:
446
-
447
- ~~~
448
- (const (cbase) :Foo)
449
- "::Foo"
450
- ~~~ name
451
- ~~ double_colon
452
- ~~~~~ expression
453
- ~~~
454
-
455
- #### Scoped constant
456
-
457
- Format:
458
-
459
- ~~~
460
- (const (lvar :a) :Foo)
461
- "a::Foo"
462
- ~~~ name
463
- ~~ double_colon
464
- ~~~~~~ expression
465
- ~~~
466
-
467
- #### Unscoped constant
468
-
469
- Format:
470
-
471
- ~~~
472
- (const nil :Foo)
473
- "Foo"
474
- ~~~ name
475
- ~~~ expression
476
- ~~~
477
-
478
- ### defined?
479
-
480
- Format:
481
-
482
- ~~~
483
- (defined? (lvar :a))
484
- "defined? a"
485
- ~~~~~~~~ keyword
486
- ~~~~~~~~~~ expression
487
-
488
- "defined?(a)"
489
- ~~~~~~~~ keyword
490
- ^ begin
491
- ^ end
492
- ~~~~~~~~~~~ expression
493
- ~~~
494
-
495
- ## Assignment
496
-
497
- ### To local variable
498
-
499
- Format:
500
-
501
- ~~~
502
- (lvasgn :foo (lvar :bar))
503
- "foo = bar"
504
- ^ operator
505
- ~~~~~~~~~ expression
506
- ~~~
507
-
508
- ### To instance variable
509
-
510
- Format:
511
-
512
- ~~~
513
- (ivasgn :@foo (lvar :bar))
514
- "@foo = bar"
515
- ^ operator
516
- ~~~~~~~~~~ expression
517
- ~~~
518
-
519
- ### To class variable
520
-
521
- Format:
522
-
523
- ~~~
524
- (cvasgn :@@foo (lvar :bar))
525
- "@@foo = bar"
526
- ^ operator
527
- ~~~~~~~~~~~ expression
528
- ~~~
529
-
530
- ### To global variable
531
-
532
- Format:
533
-
534
- ~~~
535
- (gvasgn :$foo (lvar :bar))
536
- "$foo = bar"
537
- ^ operator
538
- ~~~~~~~~~~ expression
539
- ~~~
540
-
541
- ### To constant
542
-
543
- #### Top-level constant
544
-
545
- Format:
546
-
547
- ~~~
548
- (casgn (cbase) :Foo (int 1))
549
- "::Foo = 1"
550
- ~~~ name
551
- ~ operator
552
- ~~~~~~~ expression
553
- ~~~
554
-
555
- #### Scoped constant
556
-
557
- Format:
558
-
559
- ~~~
560
- (casgn (lvar :a) :Foo (int 1))
561
- "a::Foo = 1"
562
- ~~~ name
563
- ~ operator
564
- ~~~~~~~~ expression
565
- ~~~
566
-
567
- #### Unscoped constant
568
-
569
- Format:
570
-
571
- ~~~
572
- (casgn nil :Foo (int 1))
573
- "Foo = 1"
574
- ~~~ name
575
- ~ operator
576
- ~~~~~~~ expression
577
- ~~~
578
-
579
- ### To attribute
580
-
581
- Format:
582
-
583
- ~~~
584
- (send (self) :foo= (int 1))
585
- "self.foo = 1"
586
- ^ dot
587
- ~~~ selector
588
- ^ operator
589
- ~~~~~~~~~~~~ expression
590
- ~~~
591
-
592
- ### To attribute, using "safe navigation operator"
593
-
594
- Format:
595
-
596
- ~~~
597
- (csend (self) :foo= (int 1))
598
- "self&.foo = 1"
599
- ^^ dot
600
- ~~~ selector
601
- ^ operator
602
- ~~~~~~~~~~~~~ expression
603
- ~~~
604
-
605
- ### Method reference operator
606
-
607
- Format:
608
-
609
- ~~~
610
- (meth-ref (self) :foo)
611
- "self.:foo"
612
- ^^ dot
613
- ^^^ selector
614
- ^^^^^^^^^ expression
615
- ~~~
616
-
617
- ### Multiple assignment
618
-
619
- #### Multiple left hand side
620
-
621
- Format:
622
-
623
- ~~~
624
- (mlhs (lvasgn :a) (lvasgn :b))
625
- "a, b"
626
- ~~~~ expression
627
- "(a, b)"
628
- ^ begin
629
- ^ end
630
- ~~~~~~ expression
631
- ~~~
632
-
633
- #### Assignment
634
-
635
- Rule of thumb: every node inside `(mlhs)` is "incomplete"; to make
636
- it "complete", one could imagine that a corresponding node from the
637
- mrhs is "appended" to the node in question. This applies both to
638
- side-effect free assignments (`lvasgn`, etc) and side-effectful
639
- assignments (`send`).
640
-
641
- Format:
642
-
643
- ~~~
644
- (masgn (mlhs (lvasgn :foo) (lvasgn :bar)) (array (int 1) (int 2)))
645
- "foo, bar = 1, 2"
646
- ^ operator
647
- ~~~~~~~~~~~~~~~ expression
648
-
649
- (masgn (mlhs (ivasgn :@a) (cvasgn :@@b)) (array (splat (lvar :c))))
650
- "@a, @@b = *c"
651
-
652
- (masgn (mlhs (mlhs (lvasgn :a) (lvasgn :b)) (lvasgn :c)) (lvar :d))
653
- "a, (b, c) = d"
654
-
655
- (masgn (mlhs (send (self) :a=) (send (self) :[]= (int 1))) (lvar :a))
656
- "self.a, self[1] = a"
657
- ~~~
658
-
659
- ### Binary operator-assignment
660
-
661
- Binary operator-assignment features the same "incomplete assignments" and "incomplete calls" as [multiple assignment](#assignment-1).
662
-
663
- #### Variable binary operator-assignment
664
-
665
- Format:
666
-
667
- ~~~
668
- (op-asgn (lvasgn :a) :+ (int 1))
669
- "a += 1"
670
- ~~ operator
671
- ~~~~~~ expression
672
-
673
- (op-asgn (ivasgn :a) :+ (int 1))
674
- "@a += 1"
675
- ~~~
676
-
677
- #### Method binary operator-assignment
678
-
679
- Format:
680
-
681
- ~~~
682
- (op-asgn (send (ivar :@a) :b) :+ (int 1))
683
- "@a.b += 1"
684
- ~ selector (send)
685
- ~~~~ expression (send)
686
- ~~ operator (op-asgn)
687
- ~~~~~~~~~ expression (op-asgn)
688
-
689
- (op-asgn (send (ivar :@a) :[] (int 0) (int 1))) :+ (int 1))
690
- "@a[0, 1] += 1"
691
- ~~~~~~ selector (send)
692
- ~~~~~~~~ expression (send)
693
- ~~ operator (op-asgn)
694
- ~~~~~~~~~~~~~ expression (op-asgn)
695
- ~~~
696
-
697
- ### Logical operator-assignment
698
-
699
- Logical operator-assignment features the same "incomplete assignments" and "incomplete calls" as [multiple assignment](#assignment-1).
700
-
701
- #### Variable logical operator-assignment
702
-
703
- Format:
704
-
705
- ~~~
706
- (or-asgn (ivasgn :@a) (int 1))
707
- "@a ||= 1"
708
- ~~~ operator
709
- ~~~~~~~~ expression
710
-
711
- (and-asgn (lvasgn :a) (int 1))
712
- "a &&= 1"
713
- ~~~ operator
714
- ~~~~~~~ expression
715
- ~~~
716
-
717
- #### Method logical operator-assignment
718
-
719
- Format:
720
-
721
- ~~~
722
- (or-asgn (send (ivar :@foo) :bar) (int 1))
723
- "@foo.bar ||= 1"
724
- ~~~ selector (send)
725
- ~~~~~~~~ expr (send)
726
- ~~~ operator (or-asgn)
727
- ~~~~~~~~~~~~~~ expression (or-asgn)
728
-
729
- (and-asgn (send (lvar :@foo) :bar) (int 1))
730
- "foo.bar &&= 1"
731
- ~~~ selector (send)
732
- ~~~~~~~ expr (send)
733
- ~~~ operator (and-asgn)
734
- ~~~~~~~~~~~~~ expression (and-asgn)
735
-
736
- (or-asgn (send (ivar :@foo) :[] (int 1) (int 2)) (int 1))
737
- "@foo[1, 2] ||= 1"
738
- ~~~~~~ selector (send)
739
- ~~~~~~~~~~ expr (send)
740
- ~~~ operator (or-asgn)
741
- ~~~~~~~~~~~~~~~~ expression (or-asgn)
742
-
743
- ~~~
744
-
745
- ## Class and module definition
746
-
747
- ### Module
748
-
749
- Format:
750
-
751
- ~~~
752
- (module (const nil :Foo) (nil))
753
- "module Foo; end"
754
- ~~~~~~ keyword
755
- ~~~ end
756
- ~~~
757
-
758
- ### Class
759
-
760
- Format:
761
-
762
- ~~~
763
- (class (const nil :Foo) (const nil :Bar) (nil))
764
- "class Foo < Bar; end"
765
- ~~~~~ keyword ~~~ end
766
- ~ operator
767
- ~~~~~~~~~~~~~~~~~~~~ expression
768
-
769
- (class (const nil :Foo) nil (nil))
770
- "class Foo; end"
771
- ~~~~~ keyword
772
- ~~~ end
773
- ~~~~~~~~~~~~~~ expression
774
- ~~~
775
-
776
- ### Singleton class
777
-
778
- Format:
779
-
780
- ~~~
781
- (sclass (lvar :a) (nil))
782
- "class << a; end"
783
- ~~~~~ keyword
784
- ~~ operator
785
- ~~~ end
786
- ~~~~~~~~~~~~~~~ expression
787
- ~~~
788
-
789
- ## Method (un)definition
790
-
791
- ### Instance methods
792
-
793
- Format:
794
-
795
- ~~~
796
- (def :foo (args) nil)
797
- "def foo; end"
798
- ~~~ keyword
799
- ~~~ name
800
- ~~~ end
801
- ~~~~~~~~~~~~ expression
802
- ~~~
803
-
804
- ### Singleton methods
805
-
806
- Format:
807
-
808
- ~~~
809
- (defs (self) :foo (args) nil)
810
- "def self.foo; end"
811
- ~~~ keyword
812
- ~~~ name
813
- ~~~ end
814
- ~~~~~~~~~~~~~~~~~ expression
815
- ~~~
816
-
817
- ### Undefinition
818
-
819
- Format:
820
-
821
- ~~~
822
- (undef (sym :foo) (sym :bar) (dsym (str "foo") (int 1)))
823
- "undef foo :bar :"foo#{1}""
824
- ~~~~~ keyword
825
- ~~~~~~~~~~~~~~~~~~~~~~~~~ expression
826
- ~~~
827
-
828
- ## Aliasing
829
-
830
- ### Method aliasing
831
-
832
- Format:
833
-
834
- ~~~
835
- (alias (sym :foo) (dsym (str "foo") (int 1)))
836
- "alias foo :"foo#{1}""
837
- ~~~~~ keyword
838
- ~~~~~~~~~~~~~~~~~~~~ expression
839
- ~~~
840
-
841
- ### Global variable aliasing
842
-
843
- Format:
844
-
845
- ~~~
846
- (alias (gvar :$foo) (gvar :$bar))
847
- "alias $foo $bar"
848
- ~~~~~ keyword
849
- ~~~~~~~~~~~~~~~ expression
850
-
851
- (alias (gvar :$foo) (back-ref :$&))
852
- "alias $foo $&"
853
- ~~~~~ keyword
854
- ~~~~~~~~~~~~~~~ expression
855
- ~~~
856
-
857
- ## Formal arguments
858
-
859
- Format:
860
-
861
- ~~~
862
- (args (arg :foo))
863
- "(foo)"
864
- ~~~~~ expression
865
- ~~~
866
-
867
- ### Required argument
868
-
869
- Format:
870
-
871
- ~~~
872
- (arg :foo)
873
- "foo"
874
- ~~~ expression
875
- ~~~ name
876
- ~~~
877
-
878
- ### Optional argument
879
-
880
- Format:
881
-
882
- ~~~
883
- (optarg :foo (int 1))
884
- "foo = 1"
885
- ~~~~~~~ expression
886
- ^ operator
887
- ~~~ name
888
- ~~~
889
-
890
- ### Named splat argument
891
-
892
- Format:
893
-
894
- ~~~
895
- (restarg :foo)
896
- "*foo"
897
- ~~~~ expression
898
- ~~~ name
899
- ~~~
900
-
901
- Begin of the `expression` points to `*`.
902
-
903
- ### Unnamed splat argument
904
-
905
- Format:
906
-
907
- ~~~
908
- (restarg)
909
- "*"
910
- ^ expression
911
- ~~~
912
-
913
- ### Block argument
914
-
915
- Format:
916
-
917
- ~~~
918
- (blockarg :foo)
919
- "&foo"
920
- ~~~ name
921
- ~~~~ expression
922
- ~~~
923
-
924
- Begin of the `expression` points to `&`.
925
-
926
- ### Auto-expanding proc argument (1.9)
927
-
928
- In Ruby 1.9 and later, when a proc-like closure (i.e. a closure
929
- created by capturing a block or with the `proc` method, but not
930
- with the `->{}` syntax or the `lambda` method) has exactly one
931
- argument, and it is called with more than one argument, the behavior
932
- is as if the array of all arguments was instead passed as the sole
933
- argument. This behavior can be prevented by adding a comma after
934
- the sole argument (e.g. `|foo,|`).
935
-
936
- Format:
937
-
938
- ~~~
939
- (procarg0 (arg :foo))
940
- "|foo|"
941
- ~~~ expression
942
-
943
- (procarg0 (arg :foo) (arg :bar))
944
- "|(foo, bar)|"
945
- ~ begin
946
- ~ end
947
- ~~~~~~~~~~ expression
948
- ~~~
949
-
950
- ### Expression arguments
951
-
952
- Ruby 1.8 allows to use arbitrary expressions as block arguments,
953
- such as `@var` or `foo.bar`. Such expressions should be treated as
954
- if they were on the lhs of a multiple assignment.
955
-
956
- Format:
957
-
958
- ~~~
959
- (args (arg_expr (ivasgn :@bar)))
960
- "|@bar|"
961
-
962
- (args (arg_expr (send (send nil :foo) :a=)))
963
- "|foo.a|"
964
-
965
- (args (restarg_expr (ivasgn :@bar)))
966
- "|*@bar|"
967
-
968
- (args (blockarg_expr (ivasgn :@bar)))
969
- "|&@bar|"
970
- ~~~
971
-
972
- ### Block shadow arguments
973
-
974
- Format:
975
-
976
- ~~~
977
- (args (shadowarg :foo) (shadowarg :bar))
978
- "|; foo, bar|"
979
- ~~~
980
-
981
- ### Decomposition
982
-
983
- Format:
984
-
985
- ~~~
986
- (def :f (args (arg :a) (mlhs (arg :foo) (restarg :bar))))
987
- "def f(a, (foo, *bar)); end"
988
- ^ begin ^ end
989
- ~~~~~~~~~~~ expression
990
- ~~~
991
-
992
- ### Required keyword argument
993
-
994
- Format:
995
-
996
- ~~~
997
- (kwarg :foo)
998
- "foo:"
999
- ~~~~ expression
1000
- ~~~~ name
1001
- ~~~
1002
-
1003
- ### Optional keyword argument
1004
-
1005
- Format:
1006
-
1007
- ~~~
1008
- (kwoptarg :foo (int 1))
1009
- "foo: 1"
1010
- ~~~~~~ expression
1011
- ~~~~ name
1012
- ~~~
1013
-
1014
- ### Named keyword splat argument
1015
-
1016
- Format:
1017
-
1018
- ~~~
1019
- (kwrestarg :foo)
1020
- "**foo"
1021
- ~~~~~ expression
1022
- ~~~ name
1023
- ~~~
1024
-
1025
- ### Unnamed keyword splat argument
1026
-
1027
- Format:
1028
-
1029
- ~~~
1030
- (kwrestarg)
1031
- "**"
1032
- ~~ expression
1033
- ~~~
1034
-
1035
- ### Keyword nil argument
1036
-
1037
- Format:
1038
-
1039
- ~~~
1040
- (kwnilarg)
1041
- "**nil"
1042
- ~~~ name
1043
- ~~~~~ expression
1044
- ~~~
1045
-
1046
- ### Objective-C arguments
1047
-
1048
- MacRuby includes a few more syntactic "arguments" whose name becomes
1049
- the part of the Objective-C method name, despite looking like Ruby 2.0
1050
- keyword arguments, and are thus treated differently.
1051
-
1052
- #### Objective-C label-like keyword argument
1053
-
1054
- Format:
1055
-
1056
- ~~~
1057
- (objc-kwarg :a :b)
1058
- "a: b"
1059
- ~ keyword
1060
- ~ operator
1061
- ~ argument
1062
- ~~~~ expression
1063
- ~~~
1064
-
1065
- #### Objective-C pair-like keyword argument
1066
-
1067
- Format:
1068
-
1069
- ~~~
1070
- (objc-kwarg :a :b)
1071
- "a => b"
1072
- ~ keyword
1073
- ~~ operator
1074
- ~ argument
1075
- ~~~~~~ expression
1076
- ~~~
1077
-
1078
- #### Objective-C keyword splat argument
1079
-
1080
- Format:
1081
-
1082
- ~~~
1083
- (objc-restarg (objc-kwarg :foo))
1084
- "(*a: b)"
1085
- ~ objc-kwarg.keyword
1086
- ~ objc-kwarg.operator
1087
- ~ objc-kwarg.argument
1088
- ~ operator
1089
- ~~~~~ expression
1090
- ~~~
1091
-
1092
- Note that these splat arguments will only be parsed inside parentheses,
1093
- e.g. in the following code:
1094
-
1095
- ~~~
1096
- def f((*a: b)); end
1097
- ~~~
1098
-
1099
- However, the following code results in a parse error:
1100
-
1101
- ~~~
1102
- def f(*a: b); end
1103
- ~~~
1104
-
1105
- ## Numbered parameters
1106
-
1107
- ### Block with numbered parameters
1108
-
1109
- Ruby 2.7 introduced a feature called "numbered parameters".
1110
- Numbered and ordinal parameters are mutually exclusive, so if the block
1111
- has only numbered parameters it also has a different AST node.
1112
-
1113
- Note that the second child represents a total number of numbered parameters.
1114
-
1115
- Format:
1116
-
1117
- ~~~
1118
- s(:numblock,
1119
- s(:send, nil, :proc), 3,
1120
- s(:send,
1121
- s(:numparam, 1), :+,
1122
- s(:numparam, 3)))
1123
- "proc { @1 + @3 }"
1124
- ~ begin ~ end
1125
- ~~~~~~~~~~~~~~~~ expression
1126
- ~~~
1127
-
1128
- ### Numbered parameter
1129
-
1130
- Format:
1131
-
1132
- ~~~
1133
- (numparam 10)
1134
- "@10"
1135
- ~~~ name
1136
- ~~~ expression
1137
- ~~~
1138
-
1139
- ## Send
1140
-
1141
- ### To self
1142
-
1143
- Format:
1144
-
1145
- ~~~
1146
- (send nil :foo (lvar :bar))
1147
- "foo(bar)"
1148
- ~~~ selector
1149
- ^ begin
1150
- ^ end
1151
- ~~~~~~~~ expression
1152
- ~~~
1153
-
1154
- ### To receiver
1155
-
1156
- Format:
1157
-
1158
- ~~~
1159
- (send (lvar :foo) :bar (int 1))
1160
- "foo.bar(1)"
1161
- ^ dot
1162
- ~~~ selector
1163
- ^ begin
1164
- ^ end
1165
- ~~~~~~~~~~ expression
1166
-
1167
- (send (lvar :foo) :+ (int 1))
1168
- "foo + 1"
1169
- ^ selector
1170
- ~~~~~~~ expression
1171
-
1172
- (send (lvar :foo) :-@)
1173
- "-foo"
1174
- ^ selector
1175
- ~~~~ expression
1176
-
1177
- (send (lvar :foo) :a= (int 1))
1178
- "foo.a = 1"
1179
- ~ selector
1180
- ^ operator
1181
- ~~~~~~~~~ expression
1182
- ~~~
1183
-
1184
- ### To superclass
1185
-
1186
- Format of super with arguments:
1187
-
1188
- ~~~
1189
- (super (lvar :a))
1190
- "super a"
1191
- ~~~~~ keyword
1192
- ~~~~~~~ expression
1193
-
1194
- (super)
1195
- "super()"
1196
- ^ begin
1197
- ^ end
1198
- ~~~~~ keyword
1199
- ~~~~~~~ expression
1200
- ~~~
1201
-
1202
- Format of super without arguments (**z**ero-arity):
1203
-
1204
- ~~~
1205
- (zsuper)
1206
- "super"
1207
- ~~~~~ keyword
1208
- ~~~~~ expression
1209
- ~~~
1210
-
1211
- ### To block argument
1212
-
1213
- Format:
1214
-
1215
- ~~~
1216
- (yield (lvar :foo))
1217
- "yield(foo)"
1218
- ~~~~~ keyword
1219
- ^ begin
1220
- ^ end
1221
- ~~~~~~~~~~ expression
1222
- ~~~
1223
-
1224
- ### Indexing
1225
-
1226
- Format:
1227
-
1228
- ~~~
1229
- (index (lvar :foo) (int 1))
1230
- "foo[1]"
1231
- ^ begin
1232
- ^ end
1233
- ~~~~~~ expression
1234
-
1235
- (indexasgn (lvar :bar) (int 1) (int 2) (lvar :baz))
1236
- "bar[1, 2] = baz"
1237
- ^ begin
1238
- ^ end
1239
- ^ operator
1240
- ~~~~~~~~~~~~~~~ expression
1241
-
1242
- ~~~
1243
-
1244
- ### Passing a literal block
1245
-
1246
- ~~~
1247
- (block (send nil :foo) (args (arg :bar)) (begin ...))
1248
- "foo do |bar|; end"
1249
- ~~ begin
1250
- ~~~ end
1251
- ~~~~~~~~~~~~~ expression
1252
- ~~~
1253
-
1254
- ### Passing expression as block
1255
-
1256
- Used when passing expression as block `foo(&bar)`
1257
-
1258
- ~~~
1259
- (send nil :foo (int 1) (block-pass (lvar :foo)))
1260
- "foo(1, &foo)"
1261
- ^ operator
1262
- ~~~~ expression
1263
- ~~~
1264
-
1265
- ### "Stabby lambda"
1266
-
1267
- ~~~
1268
- (block (lambda) (args) nil)
1269
- "-> {}"
1270
- ~~ lambda.expression
1271
- ~~~
1272
-
1273
- ### "Safe navigation operator"
1274
-
1275
- ~~~
1276
- (csend (send nil :foo) :bar)
1277
- "foo&.bar"
1278
- ~~ dot
1279
- ~~~
1280
-
1281
- ### Objective-C variadic send
1282
-
1283
- MacRuby allows to pass a variadic amount of arguments via the last
1284
- keyword "argument". Semantically, these, together with the pair value
1285
- of the last pair in the hash implicitly passed as the last argument,
1286
- form an array, which replaces the pair value. Despite that, the node
1287
- is called `objc-varargs` to distinguish it from a literal array passed
1288
- as a value.
1289
-
1290
- ~~~
1291
- (send nil :foo (int 1) (hash (pair (sym :bar) (objc-varargs (int 1) (int 2) (nil)))))
1292
- "foo(1, bar: 2, 3, nil)"
1293
- ~~~~~~~~~ expression (array)
1294
- ~~~
1295
-
1296
- ## Control flow
1297
-
1298
- ### Logical operators
1299
-
1300
- #### Binary (and or && ||)
1301
-
1302
- Format:
1303
-
1304
- ~~~
1305
- (and (lvar :foo) (lvar :bar))
1306
- "foo and bar"
1307
- ~~~ operator
1308
- ~~~~~~~~~~~ expression
1309
- ~~~
1310
-
1311
- ~~~
1312
- (or (lvar :foo) (lvar :bar))
1313
- "foo or bar"
1314
- ~~ operator
1315
- ~~~~~~~~~~ expression
1316
- ~~~
1317
-
1318
- #### Unary (! not) (1.8)
1319
-
1320
- Format:
1321
-
1322
- ~~~
1323
- (not (lvar :foo))
1324
- "!foo"
1325
- ^ operator
1326
- "not foo"
1327
- ~~~ operator
1328
- ~~~
1329
-
1330
- ### Branching
1331
-
1332
- #### Without else
1333
-
1334
- Format:
1335
-
1336
- ~~~
1337
- (if (lvar :cond) (lvar :iftrue) nil)
1338
- "if cond then iftrue; end"
1339
- ~~ keyword
1340
- ~~~~ begin
1341
- ~~~ end
1342
- ~~~~~~~~~~~~~~~~~~~~~~~~ expression
1343
-
1344
- "if cond; iftrue; end"
1345
- ~~ keyword
1346
- ~~~ end
1347
- ~~~~~~~~~~~~~~~~~~~~ expression
1348
-
1349
- "iftrue if cond"
1350
- ~~ keyword
1351
- ~~~~~~~~~~~~~~ expression
1352
-
1353
- (if (lvar :cond) nil (lvar :iftrue))
1354
- "unless cond then iftrue; end"
1355
- ~~~~~~ keyword
1356
- ~~~~ begin
1357
- ~~~ end
1358
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1359
-
1360
- "unless cond; iftrue; end"
1361
- ~~~~~~ keyword
1362
- ~~~ end
1363
- ~~~~~~~~~~~~~~~~~~~~~~~~ expression
1364
-
1365
- "iftrue unless cond"
1366
- ~~~~~~ keyword
1367
- ~~~~~~~~~~~~~~~~~~ expression
1368
- ~~~
1369
-
1370
- #### With else
1371
-
1372
- Format:
1373
-
1374
- ~~~
1375
- (if (lvar :cond) (lvar :iftrue) (lvar :iffalse))
1376
- "if cond then iftrue; else; iffalse; end"
1377
- ~~ keyword
1378
- ~~~~ begin
1379
- ~~~~ else
1380
- ~~~ end
1381
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1382
-
1383
- "if cond; iftrue; else; iffalse; end"
1384
- ~~ keyword
1385
- ~~~~ else
1386
- ~~~ end
1387
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1388
-
1389
- (if (lvar :cond) (lvar :iffalse) (lvar :iftrue))
1390
- "unless cond then iftrue; else; iffalse; end"
1391
- ~~~~~~ keyword
1392
- ~~~~ begin
1393
- ~~~~ else
1394
- ~~~ end
1395
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1396
-
1397
- "unless cond; iftrue; else; iffalse; end"
1398
- ~~~~~~ keyword
1399
- ~~~~ else
1400
- ~~~ end
1401
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1402
- ~~~
1403
-
1404
- #### With elsif
1405
-
1406
- Format:
1407
-
1408
- ~~~
1409
- (if (lvar :cond1) (int 1) (if (lvar :cond2 (int 2) (int 3))))
1410
- "if cond1; 1; elsif cond2; 2; else 3; end"
1411
- ~~ keyword (left)
1412
- ~~~~~ else (left)
1413
- ~~~ end (left)
1414
- ~~~~~ keyword (right)
1415
- ~~~~ else (right)
1416
- ~~~ end (right)
1417
- ~~~
1418
-
1419
- #### Ternary
1420
-
1421
- Format:
1422
-
1423
- ~~~
1424
- (if (lvar :cond) (lvar :iftrue) (lvar :iffalse))
1425
- "cond ? iftrue : iffalse"
1426
- ^ question
1427
- ^ colon
1428
- ~~~~~~~~~~~~~~~~~~~~~~~ expression
1429
- ~~~
1430
-
1431
- ### Case matching
1432
-
1433
- #### When clause
1434
-
1435
- Format:
1436
-
1437
- ~~~
1438
- (when (regexp "foo" (regopt)) (begin (lvar :bar)))
1439
- "when /foo/ then bar"
1440
- ~~~~ keyword
1441
- ~~~~ begin
1442
- ~~~~~~~~~~~~~~~~~~~ expression
1443
-
1444
- (when (int 1) (int 2) (send nil :meth))
1445
- "when 1, 2; meth"
1446
-
1447
- (when (int 1) (splat (lvar :foo)) (send nil :meth))
1448
- "when 1, *foo; meth"
1449
-
1450
- (when (splat (lvar :foo)) (send nil :meth))
1451
- "when *foo; meth"
1452
- ~~~
1453
-
1454
- #### Case-expression clause
1455
-
1456
- ##### Without else
1457
-
1458
- Format:
1459
-
1460
- ~~~
1461
- (case (lvar :foo) (when (str "bar") (lvar :bar)) nil)
1462
- "case foo; when "bar"; bar; end"
1463
- ~~~~ keyword ~~~ end
1464
- ~~~
1465
-
1466
- ##### With else
1467
-
1468
- Format:
1469
-
1470
- ~~~
1471
- (case (lvar :foo) (when (str "bar") (lvar :bar)) (lvar :baz))
1472
- "case foo; when "bar"; bar; else baz; end"
1473
- ~~~~ keyword ~~~~ else ~~~ end
1474
- ~~~
1475
-
1476
- #### Case-conditions clause
1477
-
1478
- ##### Without else
1479
-
1480
- Format:
1481
-
1482
- ~~~
1483
- (case nil (when (lvar :bar) (lvar :bar)) nil)
1484
- "case; when bar; bar; end"
1485
- ~~~~ keyword ~~~ end
1486
- ~~~
1487
-
1488
- ##### With else
1489
-
1490
- Format:
1491
-
1492
- ~~~
1493
- (case nil (when (lvar :bar) (lvar :bar)) (lvar :baz))
1494
- "case; when bar; bar; else baz; end"
1495
- ~~~~ keyword ~~~~ else ~~~ end
1496
-
1497
- (case nil (lvar :baz))
1498
- "case; else baz; end"
1499
- ~~~~ keyword
1500
- ~~~~ else
1501
- ~~~ end
1502
- ~~~
1503
-
1504
- ### Looping
1505
-
1506
- #### With precondition
1507
-
1508
- Format:
1509
-
1510
- ~~~
1511
- (while (lvar :condition) (send nil :foo))
1512
- "while condition do foo; end"
1513
- ~~~~~ keyword
1514
- ~~ begin
1515
- ~~~ end
1516
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1517
-
1518
- "while condition; foo; end"
1519
- ~~~~~ keyword
1520
- ~~~ end
1521
- ~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1522
-
1523
- "foo while condition"
1524
- ~~~~~ keyword
1525
- ~~~~~~~~~~~~~~~~~~~ expression
1526
-
1527
- (until (lvar :condition) (send nil :foo))
1528
- "until condition do foo; end"
1529
- ~~~~~ keyword
1530
- ~~ begin
1531
- ~~~ end
1532
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1533
-
1534
- (until (lvar :condition) (send nil :foo))
1535
- "until condition; foo; end"
1536
- ~~~~~ keyword
1537
- ~~~ end
1538
- ~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1539
-
1540
- "foo until condition"
1541
- ~~~~~ keyword
1542
- ~~~~~~~~~~~~~~~~~~~ expression
1543
- ~~~
1544
-
1545
- #### With postcondition
1546
-
1547
- Format:
1548
-
1549
- ~~~
1550
- (while-post (lvar :condition) (kwbegin (send nil :foo)))
1551
- "begin; foo; end while condition"
1552
- ~~~~~ begin (begin)
1553
- ~~~ end (begin)
1554
- ~~~~~ keyword (while-post)
1555
-
1556
- (until-post (lvar :condition) (kwbegin (send nil :foo)))
1557
- "begin; foo; end until condition"
1558
- ~~~~~ begin (begin)
1559
- ~~~ end (begin)
1560
- ~~~~~ keyword (until-post)
1561
- ~~~
1562
-
1563
- #### For-in
1564
-
1565
- Format:
1566
-
1567
- ~~~
1568
- (for (lvasgn :a) (lvar :array) (send nil :p (lvar :a)))
1569
- "for a in array do p a; end"
1570
- ~~~ keyword
1571
- ~~ in
1572
- ~~ begin
1573
- ~~~ end
1574
-
1575
- "for a in array; p a; end"
1576
- ~~~ keyword
1577
- ~~ in
1578
- ~~~ end
1579
-
1580
- (for
1581
- (mlhs (lvasgn :a) (lvasgn :b)) (lvar :array)
1582
- (send nil :p (lvar :a) (lvar :b)))
1583
- "for a, b in array; p a, b; end"
1584
- ~~~
1585
-
1586
- #### Break
1587
-
1588
- Format:
1589
-
1590
- ~~~
1591
- (break (int 1))
1592
- "break 1"
1593
- ~~~~~ keyword
1594
- ~~~~~~~ expression
1595
- ~~~
1596
-
1597
- #### Next
1598
-
1599
- Format:
1600
-
1601
- ~~~
1602
- (next (int 1))
1603
- "next 1"
1604
- ~~~~ keyword
1605
- ~~~~~~ expression
1606
- ~~~
1607
-
1608
- #### Redo
1609
-
1610
- Format:
1611
-
1612
- ~~~
1613
- (redo)
1614
- "redo"
1615
- ~~~~ keyword
1616
- ~~~~ expression
1617
- ~~~
1618
-
1619
- ### Return
1620
-
1621
- Format:
1622
-
1623
- ~~~
1624
- (return (lvar :foo))
1625
- "return(foo)"
1626
- ~~~~~~ keyword
1627
- ~~~~~~~~~~~ expression
1628
- ~~~
1629
-
1630
- ### Exception handling
1631
-
1632
- #### Rescue body
1633
-
1634
- Format:
1635
-
1636
- ~~~
1637
- (resbody (array (const nil :Exception) (const nil :A)) (lvasgn :bar) (int 1))
1638
- "rescue Exception, A => bar; 1"
1639
- ~~~~~~ keyword ~~ assoc
1640
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression
1641
-
1642
- "rescue Exception, A => bar then 1"
1643
- ~~~~~~ keyword ~~ assoc
1644
- ~~~~ begin
1645
-
1646
- (resbody (array (const nil :Exception)) (ivasgn :bar) (int 1))
1647
- "rescue Exception => @bar; 1"
1648
- ~~~~~~ keyword ~~ assoc
1649
-
1650
- (resbody nil (lvasgn :bar) (int 1))
1651
- "rescue => bar; 1"
1652
- ~~~~~~ keyword
1653
- ~~ assoc
1654
-
1655
- (resbody nil nil (int 1))
1656
- "rescue; 1"
1657
- ~~~~~~ keyword
1658
- ~~~
1659
-
1660
- #### Rescue statement
1661
-
1662
- ##### Without else
1663
-
1664
- Format:
1665
-
1666
- ~~~
1667
- (begin
1668
- (rescue (send nil :foo) (resbody ...) (resbody ...) nil))
1669
- "begin; foo; rescue Exception; rescue; end"
1670
- ~~~~~ begin ~~~ end
1671
- ~~~~~~~~~~~~~~~~~ expression (rescue.resbody/1)
1672
- ~~~~~~~ expression (rescue.resbody/2)
1673
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (rescue)
1674
- ~~~
1675
-
1676
- ##### With else
1677
-
1678
- Format:
1679
-
1680
- ~~~
1681
- (begin
1682
- (rescue (send nil :foo) (resbody ...) (resbody ...) (true)))
1683
- "begin; foo; rescue Exception; rescue; else true end"
1684
- ~~~~~ begin ~~~~ else (rescue)
1685
- ~~~ end
1686
- ~~~
1687
-
1688
- #### Ensure statement
1689
-
1690
- Format:
1691
-
1692
- ~~~
1693
- (begin
1694
- (ensure (send nil :foo) (send nil :bar))
1695
- "begin; foo; ensure; bar; end"
1696
- ~~~~~ begin ~~~~~~ keyword (ensure)
1697
- ~~~ end
1698
- ~~~
1699
-
1700
- #### Rescue with ensure
1701
-
1702
- Format:
1703
-
1704
- ~~~
1705
- (begin
1706
- (ensure
1707
- (rescue (send nil :foo) (resbody ...) (int 1))
1708
- (send nil :bar))
1709
- "begin; foo; rescue; nil; else; 1; ensure; bar; end"
1710
- ~~~~~ begin
1711
- ~~~~ else (ensure.rescue)
1712
- ~~~~~~~~~~~~~~~~~~~~~ expression (rescue)
1713
- ~~~~~~ keyword (ensure)
1714
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ expression (ensure)
1715
- ~~~ end
1716
- ~~~
1717
-
1718
- #### Retry
1719
-
1720
- Format:
1721
-
1722
- ~~~
1723
- (retry)
1724
- "retry"
1725
- ~~~~~ keyword
1726
- ~~~~~ expression
1727
- ~~~
1728
-
1729
- ### BEGIN and END
1730
-
1731
- Format:
1732
-
1733
- ~~~
1734
- (preexe (send nil :puts (str "foo")))
1735
- "BEGIN { puts "foo" }"
1736
- ~~~~~ keyword
1737
- ^ begin ^ end
1738
- ~~~~~~~~~~~~~~~~~~~~ expression
1739
-
1740
- (postexe (send nil :puts (str "bar")))
1741
- "END { puts "bar" }"
1742
- ~~~ keyword
1743
- ^ begin ^ end
1744
- ~~~~~~~~~~~~~~~~~~ expression
1745
- ~~~
1746
-
1747
- ## Miscellanea
1748
-
1749
- ### Flip-flops
1750
-
1751
- Format:
1752
-
1753
- ~~~
1754
- (iflipflop (lvar :a) (lvar :b))
1755
- "if a..b; end"
1756
- ~~ operator
1757
- ~~~~ expression
1758
-
1759
- (eflipflop (lvar :a) (lvar :b))
1760
- "if a...b; end"
1761
- ~~~ operator
1762
- ~~~~~ expression
1763
- ~~~
1764
-
1765
- ### Implicit matches
1766
-
1767
- Format:
1768
-
1769
- ~~~
1770
- (match-current-line (regexp (str "a") (regopt)))
1771
- "if /a/; end"
1772
- ~~~ expression
1773
- ~~~
1774
-
1775
- ### Local variable injecting matches
1776
-
1777
- Format:
1778
-
1779
- ~~~
1780
- (match-with-lvasgn (regexp (str "(?<match>bar)") (regopt)) (lvar :baz))
1781
- "/(?<match>bar)/ =~ baz"
1782
- ~~ selector
1783
- ~~~~~~~~~~~~~~~~~~~~~~ expression
1784
- ~~~
1785
-
1786
- ## Special constants
1787
-
1788
- ### File
1789
-
1790
- Format:
1791
-
1792
- ~~~
1793
- (__FILE__)
1794
- "__FILE__"
1795
- ~~~~~~~~ expression
1796
- ~~~
1797
-
1798
- ### Line
1799
-
1800
- Format:
1801
-
1802
- ~~~
1803
- (__LINE__)
1804
- "__LINE__"
1805
- ~~~~~~~~ expression
1806
- ~~~
1807
-
1808
- ### Encoding
1809
-
1810
- Format:
1811
-
1812
- ~~~
1813
- (__ENCODING__)
1814
- "__ENCODING__"
1815
- ~~~~~~~~~~~~ expression
1816
- ~~~