parser 2.5.1.0 → 3.0.1.1

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