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