parser 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.jrubyrc +1 -0
- data/.yardopts +4 -0
- data/Gemfile +2 -0
- data/README.md +3 -1
- data/doc/AST_FORMAT.md +93 -1
- data/lib/parser.rb +5 -0
- data/lib/parser/builders/default.rb +29 -19
- data/lib/parser/lexer.rl +3 -2
- data/lib/parser/lexer/explanation.rb +2 -2
- data/lib/parser/rewriter.rb +34 -0
- data/lib/parser/runner.rb +4 -5
- data/lib/parser/runner/ruby_parse.rb +76 -26
- data/lib/parser/runner/ruby_rewrite.rb +80 -0
- data/lib/parser/source/map.rb +4 -0
- data/lib/parser/source/range.rb +23 -4
- data/lib/parser/source/rewriter.rb +89 -0
- data/lib/parser/source/rewriter/action.rb +27 -0
- data/lib/parser/version.rb +1 -1
- data/parser.gemspec +3 -0
- data/test/parse_helper.rb +1 -1
- data/test/test_diagnostic.rb +5 -5
- data/test/test_parse_helper.rb +9 -9
- data/test/test_source_range.rb +2 -2
- data/test/test_source_rewriter.rb +81 -0
- data/test/test_source_rewriter_action.rb +44 -0
- metadata +40 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23913ce91aee27e303077bef4f422f30ac9bc50c
|
4
|
+
data.tar.gz: 2fb3c11a836c677360f7b17a9590e3a41c30abdc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b845aa3300fa99c75a726c41d81b33fc1019b6dc937d6eba139602c0c7f75b216344482f6ac57f288e1f1abb804a0ffdf315fc352f3d66ef680622cc7b8566
|
7
|
+
data.tar.gz: 72ce1310df9f19d5c16f7e4f61287ce187c250898cf15b70c4150e1315f7b57a78189feb48fc71448e9a16966cb44d0abb9d65cd95cba173c8297252a74e76fa
|
data/.gitignore
CHANGED
data/.jrubyrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-Xcext.enabled=true
|
data/.yardopts
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,7 @@ _Parser_ is a Ruby parser written in pure Ruby.
|
|
13
13
|
## Usage
|
14
14
|
|
15
15
|
Parse a chunk of code:
|
16
|
+
|
16
17
|
``` ruby
|
17
18
|
require 'parser/ruby20'
|
18
19
|
|
@@ -23,7 +24,8 @@ p Parser::Ruby20.parse("2 + 2")
|
|
23
24
|
```
|
24
25
|
|
25
26
|
Parse a chunk of code and display all diagnostics:
|
26
|
-
|
27
|
+
|
28
|
+
```ruby
|
27
29
|
parser = Parser::Ruby20.new
|
28
30
|
parser.diagnostics.consumer = lambda do |diag|
|
29
31
|
puts diag.render
|
data/doc/AST_FORMAT.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
AST and Source Location RFC
|
2
2
|
===========================
|
3
3
|
|
4
|
-
|
4
|
+
## Open questions:
|
5
5
|
|
6
6
|
* Should we handle these cases at all? They do not have special syntax associated.
|
7
7
|
1. How to handle lvar-injecting match (`if /(?<a>foo)/ =~ bar`)?
|
@@ -14,6 +14,7 @@ AST and Source Location RFC
|
|
14
14
|
### Singletons
|
15
15
|
|
16
16
|
Format:
|
17
|
+
|
17
18
|
```
|
18
19
|
(true)
|
19
20
|
"true"
|
@@ -31,6 +32,7 @@ Format:
|
|
31
32
|
### Integer
|
32
33
|
|
33
34
|
Format:
|
35
|
+
|
34
36
|
```
|
35
37
|
(int 123)
|
36
38
|
"123"
|
@@ -40,6 +42,7 @@ Format:
|
|
40
42
|
### Float
|
41
43
|
|
42
44
|
Format:
|
45
|
+
|
43
46
|
```
|
44
47
|
(float 1.0)
|
45
48
|
"1.0"
|
@@ -51,6 +54,7 @@ Format:
|
|
51
54
|
#### Plain
|
52
55
|
|
53
56
|
Format:
|
57
|
+
|
54
58
|
```
|
55
59
|
(str "foo")
|
56
60
|
"'foo'"
|
@@ -62,6 +66,7 @@ Format:
|
|
62
66
|
#### With interpolation
|
63
67
|
|
64
68
|
Format:
|
69
|
+
|
65
70
|
```
|
66
71
|
(dstr (str "foo") (lvar bar) (str "baz"))
|
67
72
|
'"foo#{bar}baz"'
|
@@ -74,6 +79,7 @@ Format:
|
|
74
79
|
#### Plain
|
75
80
|
|
76
81
|
Format:
|
82
|
+
|
77
83
|
```
|
78
84
|
(sym :foo)
|
79
85
|
":foo"
|
@@ -88,6 +94,7 @@ Format:
|
|
88
94
|
#### With interpolation
|
89
95
|
|
90
96
|
Format:
|
97
|
+
|
91
98
|
```
|
92
99
|
(dsym (str "foo") (lvar bar) (str "baz"))
|
93
100
|
':"foo#{bar}baz"'
|
@@ -98,6 +105,7 @@ Format:
|
|
98
105
|
### Execute-string
|
99
106
|
|
100
107
|
Format:
|
108
|
+
|
101
109
|
```
|
102
110
|
(xstr (str "foo") (lvar bar))
|
103
111
|
"`foo#{bar}`"
|
@@ -110,6 +118,7 @@ Format:
|
|
110
118
|
#### Options
|
111
119
|
|
112
120
|
Format:
|
121
|
+
|
113
122
|
```
|
114
123
|
(regopt :i :m)
|
115
124
|
"im"
|
@@ -119,6 +128,7 @@ Format:
|
|
119
128
|
#### Regexp
|
120
129
|
|
121
130
|
Format:
|
131
|
+
|
122
132
|
```
|
123
133
|
(regexp (str "foo") (lvar :bar) (regopt :i))
|
124
134
|
"/foo#{bar}/i"
|
@@ -131,6 +141,7 @@ Format:
|
|
131
141
|
#### Plain
|
132
142
|
|
133
143
|
Format:
|
144
|
+
|
134
145
|
```
|
135
146
|
(array (int 1) (int 2))
|
136
147
|
|
@@ -143,6 +154,7 @@ Format:
|
|
143
154
|
Can also be used in argument lists: `foo(bar, *baz)`
|
144
155
|
|
145
156
|
Format:
|
157
|
+
|
146
158
|
```
|
147
159
|
(splat (lvar :foo))
|
148
160
|
"*foo"
|
@@ -153,6 +165,7 @@ Format:
|
|
153
165
|
#### With interpolation
|
154
166
|
|
155
167
|
Format:
|
168
|
+
|
156
169
|
```
|
157
170
|
(array (int 1) (splat (lvar :foo)) (int 2))
|
158
171
|
|
@@ -168,6 +181,7 @@ Format:
|
|
168
181
|
##### With hashrocket
|
169
182
|
|
170
183
|
Format:
|
184
|
+
|
171
185
|
```
|
172
186
|
(pair (int 1) (int 2))
|
173
187
|
"1 => 2"
|
@@ -178,6 +192,7 @@ Format:
|
|
178
192
|
##### With label (1.9)
|
179
193
|
|
180
194
|
Format:
|
195
|
+
|
181
196
|
```
|
182
197
|
(pair (sym :answer) (int 42))
|
183
198
|
"answer: 42"
|
@@ -189,6 +204,7 @@ Format:
|
|
189
204
|
#### Plain
|
190
205
|
|
191
206
|
Format:
|
207
|
+
|
192
208
|
```
|
193
209
|
(hash (pair (int 1) (int 2)) (pair (int 3) (int 4)))
|
194
210
|
"{1 => 2, 3 => 4}"
|
@@ -201,6 +217,7 @@ Format:
|
|
201
217
|
Can also be used in argument lists: `foo(bar, **baz)`
|
202
218
|
|
203
219
|
Format:
|
220
|
+
|
204
221
|
```
|
205
222
|
(kwsplat (lvar :foo))
|
206
223
|
"**foo"
|
@@ -211,6 +228,7 @@ Format:
|
|
211
228
|
#### With interpolation (2.0)
|
212
229
|
|
213
230
|
Format:
|
231
|
+
|
214
232
|
```
|
215
233
|
(hash (pair (sym :foo) (int 2)) (kwsplat (lvar :bar)))
|
216
234
|
"{ foo: 2, **bar }"
|
@@ -223,6 +241,7 @@ Format:
|
|
223
241
|
#### Inclusive
|
224
242
|
|
225
243
|
Format:
|
244
|
+
|
226
245
|
```
|
227
246
|
(irange (int 1) (int 2))
|
228
247
|
"1..2"
|
@@ -233,6 +252,7 @@ Format:
|
|
233
252
|
#### Exclusive
|
234
253
|
|
235
254
|
Format:
|
255
|
+
|
236
256
|
```
|
237
257
|
(erange (int 1) (int 2))
|
238
258
|
"1...2"
|
@@ -245,6 +265,7 @@ Format:
|
|
245
265
|
### Self
|
246
266
|
|
247
267
|
Format:
|
268
|
+
|
248
269
|
```
|
249
270
|
(self)
|
250
271
|
"self"
|
@@ -254,6 +275,7 @@ Format:
|
|
254
275
|
### Local variable
|
255
276
|
|
256
277
|
Format:
|
278
|
+
|
257
279
|
```
|
258
280
|
(lvar :foo)
|
259
281
|
"foo"
|
@@ -263,6 +285,7 @@ Format:
|
|
263
285
|
### Instance variable
|
264
286
|
|
265
287
|
Format:
|
288
|
+
|
266
289
|
```
|
267
290
|
(ivar :@foo)
|
268
291
|
"@foo"
|
@@ -272,6 +295,7 @@ Format:
|
|
272
295
|
### Class variable
|
273
296
|
|
274
297
|
Format:
|
298
|
+
|
275
299
|
```
|
276
300
|
(cvar :$foo)
|
277
301
|
"$foo"
|
@@ -281,6 +305,7 @@ Format:
|
|
281
305
|
### Global variable
|
282
306
|
|
283
307
|
Format:
|
308
|
+
|
284
309
|
```
|
285
310
|
(gvar :$foo)
|
286
311
|
"$foo"
|
@@ -292,6 +317,7 @@ Format:
|
|
292
317
|
#### Top-level constant
|
293
318
|
|
294
319
|
Format:
|
320
|
+
|
295
321
|
```
|
296
322
|
(const (cbase) :Foo)
|
297
323
|
"::Foo"
|
@@ -303,6 +329,7 @@ Format:
|
|
303
329
|
#### Scoped constant
|
304
330
|
|
305
331
|
Format:
|
332
|
+
|
306
333
|
```
|
307
334
|
(const (lvar :a) :Foo)
|
308
335
|
"a::Foo"
|
@@ -314,6 +341,7 @@ Format:
|
|
314
341
|
#### Unscoped constant
|
315
342
|
|
316
343
|
Format:
|
344
|
+
|
317
345
|
```
|
318
346
|
(const nil :Foo)
|
319
347
|
"Foo"
|
@@ -324,6 +352,7 @@ Format:
|
|
324
352
|
### defined?
|
325
353
|
|
326
354
|
Format:
|
355
|
+
|
327
356
|
```
|
328
357
|
(defined? (lvar :a))
|
329
358
|
"defined? a"
|
@@ -342,6 +371,7 @@ Format:
|
|
342
371
|
### To local variable
|
343
372
|
|
344
373
|
Format:
|
374
|
+
|
345
375
|
```
|
346
376
|
(lvasgn :foo (lvar :bar))
|
347
377
|
"foo = bar"
|
@@ -352,6 +382,7 @@ Format:
|
|
352
382
|
### To instance variable
|
353
383
|
|
354
384
|
Format:
|
385
|
+
|
355
386
|
```
|
356
387
|
(ivasgn :@foo (lvar :bar))
|
357
388
|
"@foo = bar"
|
@@ -364,6 +395,7 @@ Format:
|
|
364
395
|
#### Inside a class scope
|
365
396
|
|
366
397
|
Format:
|
398
|
+
|
367
399
|
```
|
368
400
|
(cvdecl :@@foo (lvar :bar))
|
369
401
|
"@@foo = bar"
|
@@ -374,6 +406,7 @@ Format:
|
|
374
406
|
#### Inside a method scope
|
375
407
|
|
376
408
|
Format:
|
409
|
+
|
377
410
|
```
|
378
411
|
(cvasgn :@@foo (lvar :bar))
|
379
412
|
"@@foo = bar"
|
@@ -384,6 +417,7 @@ Format:
|
|
384
417
|
### To global variable
|
385
418
|
|
386
419
|
Format:
|
420
|
+
|
387
421
|
```
|
388
422
|
(gvasgn :$foo (lvar :bar))
|
389
423
|
"$foo = bar"
|
@@ -396,6 +430,7 @@ Format:
|
|
396
430
|
#### Top-level constant
|
397
431
|
|
398
432
|
Format:
|
433
|
+
|
399
434
|
```
|
400
435
|
(cdecl (cbase) :Foo (int 1))
|
401
436
|
"::Foo = 1"
|
@@ -407,6 +442,7 @@ Format:
|
|
407
442
|
#### Scoped constant
|
408
443
|
|
409
444
|
Format:
|
445
|
+
|
410
446
|
```
|
411
447
|
(cdecl (lvar :a) :Foo (int 1))
|
412
448
|
"a::Foo = 1"
|
@@ -418,6 +454,7 @@ Format:
|
|
418
454
|
#### Unscoped constant
|
419
455
|
|
420
456
|
Format:
|
457
|
+
|
421
458
|
```
|
422
459
|
(cdecl nil :Foo (int 1))
|
423
460
|
"Foo = 1"
|
@@ -432,6 +469,7 @@ Format:
|
|
432
469
|
#### Multiple left hand side
|
433
470
|
|
434
471
|
Format:
|
472
|
+
|
435
473
|
```
|
436
474
|
(mlhs (lvasgn :a) (lvasgn :b))
|
437
475
|
"a, b"
|
@@ -451,6 +489,7 @@ side-effect free assignments (`lvasgn`, etc) and side-effectful
|
|
451
489
|
assignments (`send`).
|
452
490
|
|
453
491
|
Format:
|
492
|
+
|
454
493
|
```
|
455
494
|
(masgn (mlhs (lvasgn :foo) (lvasgn :bar)) (array (int 1) (int 2)))
|
456
495
|
"foo, bar = 1, 2"
|
@@ -474,6 +513,7 @@ Binary operator-assignment features the same "incomplete assignments" and "incom
|
|
474
513
|
#### Variable binary operator-assignment
|
475
514
|
|
476
515
|
Format:
|
516
|
+
|
477
517
|
```
|
478
518
|
(op-asgn (lvasgn :a) :+ (int 1))
|
479
519
|
"a += 1"
|
@@ -496,6 +536,7 @@ s(:iasgn, :@a, s(:call, s(:ivar, :@a), :+, s(:int, 1)))
|
|
496
536
|
#### Method binary operator-assignment
|
497
537
|
|
498
538
|
Format:
|
539
|
+
|
499
540
|
```
|
500
541
|
(op-asgn (send (ivar :@a) :b) :+ (int 1))
|
501
542
|
"@a.b += 1"
|
@@ -528,6 +569,7 @@ Logical operator-assignment features the same "incomplete assignments" and "inco
|
|
528
569
|
#### Variable logical operator-assignment
|
529
570
|
|
530
571
|
Format:
|
572
|
+
|
531
573
|
```
|
532
574
|
(or-asgn (iasgn :@a) (int 1))
|
533
575
|
"@a ||= 1"
|
@@ -552,6 +594,7 @@ s(:op_asgn_and, s(:lvar, :a), s(:lasgn, :a, s(:int, 1)))
|
|
552
594
|
#### Method logical operator-assignment
|
553
595
|
|
554
596
|
Format:
|
597
|
+
|
555
598
|
```
|
556
599
|
(or-asgn (send (ivar :@foo) :bar) (int 1))
|
557
600
|
"@foo.bar ||= 1"
|
@@ -591,6 +634,7 @@ s(:op_asgn1, s(:ivar, :@foo), s(:arglist, s(:int, 0)), :"||", s(:int, 1))
|
|
591
634
|
### Module
|
592
635
|
|
593
636
|
Format:
|
637
|
+
|
594
638
|
```
|
595
639
|
(module (const nil :Foo) (nil))
|
596
640
|
"module Foo; end"
|
@@ -601,6 +645,7 @@ Format:
|
|
601
645
|
### Class
|
602
646
|
|
603
647
|
Format:
|
648
|
+
|
604
649
|
```
|
605
650
|
(class (const nil :Foo) (const nil :Bar) (nil))
|
606
651
|
"class Foo < Bar; end"
|
@@ -618,6 +663,7 @@ Format:
|
|
618
663
|
### Singleton class
|
619
664
|
|
620
665
|
Format:
|
666
|
+
|
621
667
|
```
|
622
668
|
(sclass (lvar :a) (nil))
|
623
669
|
"class << a; end"
|
@@ -632,6 +678,7 @@ Format:
|
|
632
678
|
### Instance methods
|
633
679
|
|
634
680
|
Format:
|
681
|
+
|
635
682
|
```
|
636
683
|
(def :foo (args) nil)
|
637
684
|
"def foo; end"
|
@@ -644,6 +691,7 @@ Format:
|
|
644
691
|
### Singleton methods
|
645
692
|
|
646
693
|
Format:
|
694
|
+
|
647
695
|
```
|
648
696
|
(defs (self) (args) nil)
|
649
697
|
"def self.foo; end"
|
@@ -656,6 +704,7 @@ Format:
|
|
656
704
|
### Undefinition
|
657
705
|
|
658
706
|
Format:
|
707
|
+
|
659
708
|
```
|
660
709
|
(undef (sym :foo) (sym :bar) (dsym (str "foo") (int 1)))
|
661
710
|
"undef foo :bar :"foo#{1}""
|
@@ -668,6 +717,7 @@ Format:
|
|
668
717
|
### Method aliasing
|
669
718
|
|
670
719
|
Format:
|
720
|
+
|
671
721
|
```
|
672
722
|
(alias (sym :foo) (dsym (str "foo") (int 1)))
|
673
723
|
"alias foo :"foo#{1}""
|
@@ -678,6 +728,7 @@ Format:
|
|
678
728
|
### Global variable aliasing
|
679
729
|
|
680
730
|
Format:
|
731
|
+
|
681
732
|
```
|
682
733
|
(alias (gvar :$foo) (gvar :$bar))
|
683
734
|
"alias $foo $bar"
|
@@ -693,6 +744,7 @@ Format:
|
|
693
744
|
## Formal arguments
|
694
745
|
|
695
746
|
Format:
|
747
|
+
|
696
748
|
```
|
697
749
|
(args (arg :foo))
|
698
750
|
"(foo)"
|
@@ -702,6 +754,7 @@ Format:
|
|
702
754
|
### Required argument
|
703
755
|
|
704
756
|
Format:
|
757
|
+
|
705
758
|
```
|
706
759
|
(arg :foo)
|
707
760
|
"foo"
|
@@ -712,6 +765,7 @@ Format:
|
|
712
765
|
### Optional argument
|
713
766
|
|
714
767
|
Format:
|
768
|
+
|
715
769
|
```
|
716
770
|
(optarg :foo (int 1))
|
717
771
|
"foo = 1"
|
@@ -723,6 +777,7 @@ Format:
|
|
723
777
|
### Named splat argument
|
724
778
|
|
725
779
|
Format:
|
780
|
+
|
726
781
|
```
|
727
782
|
(restarg :foo)
|
728
783
|
"*foo"
|
@@ -735,6 +790,7 @@ Begin of the `expression` points to `*`.
|
|
735
790
|
### Unnamed splat argument
|
736
791
|
|
737
792
|
Format:
|
793
|
+
|
738
794
|
```
|
739
795
|
(restarg)
|
740
796
|
"*"
|
@@ -744,6 +800,7 @@ Format:
|
|
744
800
|
### Block argument
|
745
801
|
|
746
802
|
Format:
|
803
|
+
|
747
804
|
```
|
748
805
|
(blockarg :foo)
|
749
806
|
"&foo"
|
@@ -760,6 +817,7 @@ such as `@var` or `foo.bar`. Such expressions should be treated as
|
|
760
817
|
if they were on the lhs of a multiple assignment.
|
761
818
|
|
762
819
|
Format:
|
820
|
+
|
763
821
|
```
|
764
822
|
(args (arg_expr (ivasgn :@bar)))
|
765
823
|
"|@bar|"
|
@@ -777,6 +835,7 @@ Format:
|
|
777
835
|
### Block shadow arguments
|
778
836
|
|
779
837
|
Format:
|
838
|
+
|
780
839
|
```
|
781
840
|
(args (shadowarg :foo) (shadowarg :bar))
|
782
841
|
"|; foo, bar|"
|
@@ -785,6 +844,7 @@ Format:
|
|
785
844
|
### Decomposition
|
786
845
|
|
787
846
|
Format:
|
847
|
+
|
788
848
|
```
|
789
849
|
(def :f (args (arg :a) (mlhs (arg :foo) (restarg :bar))))
|
790
850
|
"def f(a, (foo, *bar)); end"
|
@@ -795,6 +855,7 @@ Format:
|
|
795
855
|
### Required keyword argument
|
796
856
|
|
797
857
|
Format:
|
858
|
+
|
798
859
|
```
|
799
860
|
(kwarg :foo (int 1))
|
800
861
|
"foo:"
|
@@ -805,6 +866,7 @@ Format:
|
|
805
866
|
### Optional keyword argument
|
806
867
|
|
807
868
|
Format:
|
869
|
+
|
808
870
|
```
|
809
871
|
(kwoptarg :foo (int 1))
|
810
872
|
"foo: 1"
|
@@ -815,6 +877,7 @@ Format:
|
|
815
877
|
### Named keyword splat argument
|
816
878
|
|
817
879
|
Format:
|
880
|
+
|
818
881
|
```
|
819
882
|
(kwrestarg :foo)
|
820
883
|
"**foo"
|
@@ -825,6 +888,7 @@ Format:
|
|
825
888
|
### Unnamed keyword splat argument
|
826
889
|
|
827
890
|
Format:
|
891
|
+
|
828
892
|
```
|
829
893
|
(kwrestarg)
|
830
894
|
"**"
|
@@ -836,6 +900,7 @@ Format:
|
|
836
900
|
### To self
|
837
901
|
|
838
902
|
Format:
|
903
|
+
|
839
904
|
```
|
840
905
|
(send nil :foo (lvar :bar))
|
841
906
|
"foo(bar)"
|
@@ -848,6 +913,7 @@ Format:
|
|
848
913
|
### To receiver
|
849
914
|
|
850
915
|
Format:
|
916
|
+
|
851
917
|
```
|
852
918
|
(send (lvar :foo) :bar (int 1))
|
853
919
|
"foo.bar(1)"
|
@@ -913,6 +979,7 @@ Format of super without arguments (**z**ero-arity):
|
|
913
979
|
### To block argument
|
914
980
|
|
915
981
|
Format:
|
982
|
+
|
916
983
|
```
|
917
984
|
(yield (lvar :foo))
|
918
985
|
"yield(foo)"
|
@@ -950,6 +1017,7 @@ Used when passing expression as block `foo(&bar)`
|
|
950
1017
|
#### Binary (and or && ||)
|
951
1018
|
|
952
1019
|
Format:
|
1020
|
+
|
953
1021
|
```
|
954
1022
|
(and (lvar :foo) (lvar :bar))
|
955
1023
|
"foo and bar"
|
@@ -960,6 +1028,7 @@ Format:
|
|
960
1028
|
#### Unary (! not) (1.8)
|
961
1029
|
|
962
1030
|
Format:
|
1031
|
+
|
963
1032
|
```
|
964
1033
|
(not (lvar :foo))
|
965
1034
|
"!foo"
|
@@ -973,6 +1042,7 @@ Format:
|
|
973
1042
|
#### Without else
|
974
1043
|
|
975
1044
|
Format:
|
1045
|
+
|
976
1046
|
```
|
977
1047
|
(if (lvar :cond) (lvar :iftrue) nil)
|
978
1048
|
"if cond then iftrue; end"
|
@@ -1010,6 +1080,7 @@ Format:
|
|
1010
1080
|
#### With else
|
1011
1081
|
|
1012
1082
|
Format:
|
1083
|
+
|
1013
1084
|
```
|
1014
1085
|
(if (lvar :cond) (lvar :iftrue) (lvar :iffalse))
|
1015
1086
|
"if cond then iftrue; else; iffalse; end"
|
@@ -1043,6 +1114,7 @@ Format:
|
|
1043
1114
|
#### With elsif
|
1044
1115
|
|
1045
1116
|
Format:
|
1117
|
+
|
1046
1118
|
```
|
1047
1119
|
(if (lvar :cond1) (int 1) (if (lvar :cond2 (int 2) (int 3))))
|
1048
1120
|
"if cond1; 1; elsif cond2; 2; else 3; end"
|
@@ -1057,6 +1129,7 @@ Format:
|
|
1057
1129
|
#### Ternary
|
1058
1130
|
|
1059
1131
|
Format:
|
1132
|
+
|
1060
1133
|
```
|
1061
1134
|
(if (lvar :cond) (lvar :iftrue) (lvar :iffalse))
|
1062
1135
|
"cond ? iftrue : iffalse"
|
@@ -1070,6 +1143,7 @@ Format:
|
|
1070
1143
|
#### When clause
|
1071
1144
|
|
1072
1145
|
Format:
|
1146
|
+
|
1073
1147
|
```
|
1074
1148
|
(when (regexp "foo" (regopt)) (begin (lvar :bar)))
|
1075
1149
|
"when /foo/ then bar"
|
@@ -1092,6 +1166,7 @@ Format:
|
|
1092
1166
|
##### Without else
|
1093
1167
|
|
1094
1168
|
Format:
|
1169
|
+
|
1095
1170
|
```
|
1096
1171
|
(case (lvar :foo) (when (str "bar") (lvar :bar)) nil)
|
1097
1172
|
"case foo; when "bar"; bar; end"
|
@@ -1101,6 +1176,7 @@ Format:
|
|
1101
1176
|
##### With else
|
1102
1177
|
|
1103
1178
|
Format:
|
1179
|
+
|
1104
1180
|
```
|
1105
1181
|
(case (lvar :foo) (when (str "bar") (lvar :bar)) (lvar :baz))
|
1106
1182
|
"case foo; when "bar"; bar; else baz; end"
|
@@ -1112,6 +1188,7 @@ Format:
|
|
1112
1188
|
##### Without else
|
1113
1189
|
|
1114
1190
|
Format:
|
1191
|
+
|
1115
1192
|
```
|
1116
1193
|
(case nil (when (lvar :bar) (lvar :bar)) nil)
|
1117
1194
|
"case; when bar; bar; end"
|
@@ -1121,6 +1198,7 @@ Format:
|
|
1121
1198
|
##### With else
|
1122
1199
|
|
1123
1200
|
Format:
|
1201
|
+
|
1124
1202
|
```
|
1125
1203
|
(case nil (when (lvar :bar) (lvar :bar)) (lvar :baz))
|
1126
1204
|
"case; when bar; bar; else baz; end"
|
@@ -1138,6 +1216,7 @@ Format:
|
|
1138
1216
|
#### With precondition
|
1139
1217
|
|
1140
1218
|
Format:
|
1219
|
+
|
1141
1220
|
```
|
1142
1221
|
(while (lvar :condition) (send nil :foo))
|
1143
1222
|
"while condition do foo; end"
|
@@ -1176,6 +1255,7 @@ Format:
|
|
1176
1255
|
#### With postcondition
|
1177
1256
|
|
1178
1257
|
Format:
|
1258
|
+
|
1179
1259
|
```
|
1180
1260
|
(while-post (lvar :condition) (begin (send nil :foo)))
|
1181
1261
|
"begin; foo; end while condition"
|
@@ -1193,6 +1273,7 @@ Format:
|
|
1193
1273
|
#### For-in
|
1194
1274
|
|
1195
1275
|
Format:
|
1276
|
+
|
1196
1277
|
```
|
1197
1278
|
(for (lasgn :a) (lvar :array) (send nil :p (lvar :a)))
|
1198
1279
|
"for a in array do p a; end"
|
@@ -1215,6 +1296,7 @@ Format:
|
|
1215
1296
|
#### Break
|
1216
1297
|
|
1217
1298
|
Format:
|
1299
|
+
|
1218
1300
|
```
|
1219
1301
|
(break (int 1))
|
1220
1302
|
"break 1"
|
@@ -1225,6 +1307,7 @@ Format:
|
|
1225
1307
|
#### Next
|
1226
1308
|
|
1227
1309
|
Format:
|
1310
|
+
|
1228
1311
|
```
|
1229
1312
|
(next (int 1))
|
1230
1313
|
"next 1"
|
@@ -1235,6 +1318,7 @@ Format:
|
|
1235
1318
|
#### Redo
|
1236
1319
|
|
1237
1320
|
Format:
|
1321
|
+
|
1238
1322
|
```
|
1239
1323
|
(redo)
|
1240
1324
|
"redo"
|
@@ -1245,6 +1329,7 @@ Format:
|
|
1245
1329
|
### Return
|
1246
1330
|
|
1247
1331
|
Format:
|
1332
|
+
|
1248
1333
|
```
|
1249
1334
|
(return (lvar :foo))
|
1250
1335
|
"return(foo)"
|
@@ -1257,6 +1342,7 @@ Format:
|
|
1257
1342
|
#### Rescue body
|
1258
1343
|
|
1259
1344
|
Format:
|
1345
|
+
|
1260
1346
|
```
|
1261
1347
|
(resbody (array (const nil :Exception) (const nil :A)) (lvasgn :bar) (int 1))
|
1262
1348
|
"rescue Exception, A => bar; 1"
|
@@ -1286,6 +1372,7 @@ Format:
|
|
1286
1372
|
##### Without else
|
1287
1373
|
|
1288
1374
|
Format:
|
1375
|
+
|
1289
1376
|
```
|
1290
1377
|
(begin
|
1291
1378
|
(rescue (send nil :foo) (resbody ...) (resbody ...) nil))
|
@@ -1299,6 +1386,7 @@ Format:
|
|
1299
1386
|
##### With else
|
1300
1387
|
|
1301
1388
|
Format:
|
1389
|
+
|
1302
1390
|
```
|
1303
1391
|
(begin
|
1304
1392
|
(rescue (send nil :foo) (resbody ...) (resbody ...) (true)))
|
@@ -1310,6 +1398,7 @@ Format:
|
|
1310
1398
|
#### Ensure statement
|
1311
1399
|
|
1312
1400
|
Format:
|
1401
|
+
|
1313
1402
|
```
|
1314
1403
|
(begin
|
1315
1404
|
(ensure (send nil :foo) (send nil :bar))
|
@@ -1321,6 +1410,7 @@ Format:
|
|
1321
1410
|
#### Rescue with ensure
|
1322
1411
|
|
1323
1412
|
Format:
|
1413
|
+
|
1324
1414
|
```
|
1325
1415
|
(begin
|
1326
1416
|
(ensure
|
@@ -1338,6 +1428,7 @@ Format:
|
|
1338
1428
|
#### Retry
|
1339
1429
|
|
1340
1430
|
Format:
|
1431
|
+
|
1341
1432
|
```
|
1342
1433
|
(retry)
|
1343
1434
|
"retry"
|
@@ -1348,6 +1439,7 @@ Format:
|
|
1348
1439
|
### BEGIN and END
|
1349
1440
|
|
1350
1441
|
Format:
|
1442
|
+
|
1351
1443
|
```
|
1352
1444
|
(preexe (send nil :puts (str "foo")))
|
1353
1445
|
"BEGIN { puts "foo" }"
|