parser 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2352 @@
1
+ class Parser::Ruby21
2
+
3
+ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
4
+ kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
5
+ kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
6
+ kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
7
+ kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
8
+ k__FILE__ k__ENCODING__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT
9
+ tLABEL tCVAR tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT
10
+ tREGEXP_END tUPLUS tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ
11
+ tGEQ tLEQ tANDOP tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF
12
+ tASET tLSHFT tRSHFT tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN
13
+ tLPAREN2 tRPAREN tLPAREN_ARG tLBRACK tLBRACK2 tRBRACK tLBRACE
14
+ tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2 tTILDE tPERCENT tDIVIDE
15
+ tDSTAR tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
16
+ tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG tREGEXP_OPT
17
+ tWORDS_BEG tQWORDS_BEG tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DBEG
18
+ tSTRING_DVAR tSTRING_END tSTRING_DEND tSTRING tSYMBOL
19
+ tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA tLAMBEG
20
+
21
+ prechigh
22
+ right tBANG tTILDE tUPLUS
23
+ right tPOW
24
+ right tUMINUS_NUM tUMINUS
25
+ left tSTAR2 tDIVIDE tPERCENT
26
+ left tPLUS tMINUS
27
+ left tLSHFT tRSHFT
28
+ left tAMPER2
29
+ left tPIPE tCARET
30
+ left tGT tGEQ tLT tLEQ
31
+ nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
32
+ left tANDOP
33
+ left tOROP
34
+ nonassoc tDOT2 tDOT3
35
+ right tEH tCOLON
36
+ left kRESCUE_MOD
37
+ right tEQL tOP_ASGN
38
+ nonassoc kDEFINED
39
+ right kNOT
40
+ left kOR kAND
41
+ nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
42
+ nonassoc tLBRACE_ARG
43
+ nonassoc tLOWEST
44
+ preclow
45
+
46
+ rule
47
+
48
+ program: top_compstmt
49
+
50
+ top_compstmt: top_stmts opt_terms
51
+ {
52
+ result = @builder.compstmt(val[0])
53
+ }
54
+
55
+ top_stmts: # nothing
56
+ {
57
+ result = []
58
+ }
59
+ | top_stmt
60
+ {
61
+ result = [ val[0] ]
62
+ }
63
+ | top_stmts terms top_stmt
64
+ {
65
+ result = val[0] << val[2]
66
+ }
67
+ | error top_stmt
68
+ {
69
+ result = [ val[1] ]
70
+ }
71
+
72
+ top_stmt: stmt
73
+ | klBEGIN tLCURLY top_compstmt tRCURLY
74
+ {
75
+ result = @builder.preexe(val[0], val[1], val[2], val[3])
76
+ }
77
+
78
+ bodystmt: compstmt opt_rescue opt_else opt_ensure
79
+ {
80
+ rescue_bodies = val[1]
81
+ else_, t_else = val[2]
82
+ ensure_, t_ensure = val[3]
83
+
84
+ if rescue_bodies.empty? && !else_.nil?
85
+ diagnostic :warning, :useless_else, t_else
86
+ end
87
+
88
+ result = @builder.begin_body(val[0],
89
+ rescue_bodies,
90
+ else_, t_else,
91
+ ensure_, t_ensure)
92
+ }
93
+
94
+ compstmt: stmts opt_terms
95
+ {
96
+ result = @builder.compstmt(val[0])
97
+ }
98
+
99
+ stmts: # nothing
100
+ {
101
+ result = []
102
+ }
103
+ | stmt_or_begin
104
+ {
105
+ result = [ val[0] ]
106
+ }
107
+ | stmts terms stmt_or_begin
108
+ {
109
+ result = val[0] << val[2]
110
+ }
111
+ | error stmt
112
+ {
113
+ result = [ val[1] ]
114
+ }
115
+
116
+ stmt_or_begin: stmt
117
+ | klBEGIN tLCURLY top_compstmt tRCURLY
118
+ {
119
+ if in_def?
120
+ diagnostic(:error, :begin_in_method, val[0])
121
+ end
122
+
123
+ result = @builder.preexe(val[0], val[1], val[2], val[3])
124
+ }
125
+
126
+ stmt: kALIAS fitem
127
+ {
128
+ @lexer.state = :expr_fname
129
+ }
130
+ fitem
131
+ {
132
+ result = @builder.alias(val[0], val[1], val[3])
133
+ }
134
+ | kALIAS tGVAR tGVAR
135
+ {
136
+ result = @builder.alias(val[0],
137
+ @builder.gvar(val[1]),
138
+ @builder.gvar(val[2]))
139
+ }
140
+ | kALIAS tGVAR tBACK_REF
141
+ {
142
+ result = @builder.alias(val[0],
143
+ @builder.gvar(val[1]),
144
+ @builder.back_ref(val[2]))
145
+ }
146
+ | kALIAS tGVAR tNTH_REF
147
+ {
148
+ diagnostic(:error, :nth_ref_alias, val[2])
149
+ }
150
+ | kUNDEF undef_list
151
+ {
152
+ result = @builder.undef_method(val[0], val[1])
153
+ }
154
+ | stmt kIF_MOD expr_value
155
+ {
156
+ result = @builder.condition_mod(val[0], nil,
157
+ val[1], val[2])
158
+ }
159
+ | stmt kUNLESS_MOD expr_value
160
+ {
161
+ result = @builder.condition_mod(nil, val[0],
162
+ val[1], val[2])
163
+ }
164
+ | stmt kWHILE_MOD expr_value
165
+ {
166
+ result = @builder.loop_mod(val[0], val[1], val[2])
167
+ }
168
+ | stmt kUNTIL_MOD expr_value
169
+ {
170
+ result = @builder.loop_mod(val[0], val[1], val[2])
171
+ }
172
+ | stmt kRESCUE_MOD stmt
173
+ {
174
+ rescue_body = @builder.rescue_body(val[1],
175
+ nil, nil, nil,
176
+ nil, val[2])
177
+
178
+ result = @builder.begin_body(val[0], [ rescue_body ])
179
+ }
180
+ | klEND tLCURLY compstmt tRCURLY
181
+ {
182
+ if in_def?
183
+ diagnostic(:warning, :end_in_method, val[0])
184
+ end
185
+
186
+ result = @builder.postexe(val[0], val[1], val[2], val[3])
187
+ }
188
+ | command_asgn
189
+ | mlhs tEQL command_call
190
+ {
191
+ result = @builder.multi_assign(val[0], val[1], val[2])
192
+ }
193
+ | var_lhs tOP_ASGN command_call
194
+ {
195
+ result = @builder.op_assign(val[0], val[1], val[2])
196
+ }
197
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_call
198
+ {
199
+ result = @builder.op_assign(
200
+ @builder.index(
201
+ val[0], val[1], val[2], val[3]),
202
+ val[4], val[5])
203
+ }
204
+ | primary_value tDOT tIDENTIFIER tOP_ASGN command_call
205
+ {
206
+ result = @builder.op_assign(
207
+ @builder.call_method(
208
+ val[0], val[1], val[2]),
209
+ val[3], val[4])
210
+ }
211
+ | primary_value tDOT tCONSTANT tOP_ASGN command_call
212
+ {
213
+ result = @builder.op_assign(
214
+ @builder.call_method(
215
+ val[0], val[1], val[2]),
216
+ val[3], val[4])
217
+ }
218
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
219
+ {
220
+ result = @builder.op_assign(
221
+ @builder.call_method(
222
+ val[0], val[1], val[2]),
223
+ val[3], val[4])
224
+ }
225
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
226
+ {
227
+ result = @builder.op_assign(
228
+ @builder.call_method(
229
+ val[0], val[1], val[2]),
230
+ val[3], val[4])
231
+ }
232
+ | backref tOP_ASGN command_call
233
+ {
234
+ @builder.op_assign(val[0], val[1], val[2])
235
+ }
236
+ | lhs tEQL mrhs
237
+ {
238
+ result = @builder.assign(val[0], val[1],
239
+ @builder.array(nil, val[2], nil))
240
+ }
241
+ | mlhs tEQL mrhs_arg
242
+ {
243
+ result = @builder.multi_assign(val[0], val[1], val[2])
244
+ }
245
+ | expr
246
+
247
+ command_asgn: lhs tEQL command_call
248
+ {
249
+ result = @builder.assign(val[0], val[1], val[2])
250
+ }
251
+ | lhs tEQL command_asgn
252
+ {
253
+ result = @builder.assign(val[0], val[1], val[2])
254
+ }
255
+
256
+ expr: command_call
257
+ | expr kAND expr
258
+ {
259
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
260
+ }
261
+ | expr kOR expr
262
+ {
263
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
264
+ }
265
+ | kNOT opt_nl expr
266
+ {
267
+ result = @builder.not_op(val[0], val[2])
268
+ }
269
+ | tBANG command_call
270
+ {
271
+ result = @builder.not_op(val[0], val[1])
272
+ }
273
+ | arg
274
+
275
+ expr_value: expr
276
+ {
277
+ result = value_expr(val[0])
278
+ }
279
+
280
+ command_call: command
281
+ | block_command
282
+
283
+ block_command: block_call
284
+ | block_call dot_or_colon operation2 command_args
285
+ {
286
+ result = @builder.call_method(val[0], val[1], val[2],
287
+ nil, val[3], nil)
288
+ }
289
+
290
+ cmd_brace_block: tLBRACE_ARG
291
+ {
292
+ @static_env.extend_dynamic
293
+ }
294
+ opt_block_param compstmt tRCURLY
295
+ {
296
+ result = [ val[0], val[2], val[3], val[4] ]
297
+
298
+ @static_env.unextend
299
+ }
300
+
301
+ fcall: operation
302
+
303
+ command: fcall command_args =tLOWEST
304
+ {
305
+ result = @builder.call_method(nil, nil, val[0],
306
+ nil, val[1], nil)
307
+ }
308
+ | fcall command_args cmd_brace_block
309
+ {
310
+ method_call = @builder.call_method(nil, nil, val[0],
311
+ nil, val[1], nil)
312
+
313
+ begin_t, args, body, end_t = val[2]
314
+ result = @builder.block(method_call,
315
+ begin_t, args, body, end_t)
316
+ }
317
+ | primary_value tDOT operation2 command_args =tLOWEST
318
+ {
319
+ result = @builder.call_method(val[0], val[1], val[2],
320
+ nil, val[3], nil)
321
+ }
322
+ | primary_value tDOT operation2 command_args cmd_brace_block
323
+ {
324
+ method_call = @builder.call_method(val[0], val[1], val[2],
325
+ nil, val[3], nil)
326
+
327
+ begin_t, args, body, end_t = val[4]
328
+ result = @builder.block(method_call,
329
+ begin_t, args, body, end_t)
330
+ }
331
+ | primary_value tCOLON2 operation2 command_args =tLOWEST
332
+ {
333
+ result = @builder.call_method(val[0], val[1], val[2],
334
+ nil, val[3], nil)
335
+ }
336
+ | primary_value tCOLON2 operation2 command_args cmd_brace_block
337
+ {
338
+ method_call = @builder.call_method(val[0], val[1], val[2],
339
+ nil, val[3], nil)
340
+
341
+ begin_t, args, body, end_t = val[4]
342
+ result = @builder.block(method_call,
343
+ begin_t, args, body, end_t)
344
+ }
345
+ | kSUPER command_args
346
+ {
347
+ result = @builder.keyword_cmd(:super, val[0],
348
+ nil, val[1], nil)
349
+ }
350
+ | kYIELD command_args
351
+ {
352
+ result = @builder.keyword_cmd(:yield, val[0],
353
+ nil, val[1], nil)
354
+ }
355
+ | kRETURN call_args
356
+ {
357
+ result = @builder.keyword_cmd(:return, val[0],
358
+ nil, val[1], nil)
359
+ }
360
+ | kBREAK call_args
361
+ {
362
+ result = @builder.keyword_cmd(:break, val[0],
363
+ nil, val[1], nil)
364
+ }
365
+ | kNEXT call_args
366
+ {
367
+ result = @builder.keyword_cmd(:next, val[0],
368
+ nil, val[1], nil)
369
+ }
370
+
371
+ mlhs: mlhs_basic
372
+ {
373
+ result = @builder.multi_lhs(nil, val[0], nil)
374
+ }
375
+ | tLPAREN mlhs_inner rparen
376
+ {
377
+ result = @builder.parenthesize(val[0], val[1], val[2])
378
+ }
379
+
380
+ mlhs_inner: mlhs_basic
381
+ {
382
+ result = @builder.multi_lhs(nil, val[0], nil)
383
+ }
384
+ | tLPAREN mlhs_inner rparen
385
+ {
386
+ result = @builder.multi_lhs(val[0], val[1], val[2])
387
+ }
388
+
389
+ mlhs_basic: mlhs_head
390
+ | mlhs_head mlhs_item
391
+ {
392
+ result = val[0].
393
+ push(val[1])
394
+ }
395
+ | mlhs_head tSTAR mlhs_node
396
+ {
397
+ result = val[0].
398
+ push(@builder.splat(val[1], val[2]))
399
+ }
400
+ | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
401
+ {
402
+ result = val[0].
403
+ push(@builder.splat(val[1], val[2])).
404
+ concat(val[4])
405
+ }
406
+ | mlhs_head tSTAR
407
+ {
408
+ result = val[0].
409
+ push(@builder.splat(val[1]))
410
+ }
411
+ | mlhs_head tSTAR tCOMMA mlhs_post
412
+ {
413
+ result = val[0].
414
+ push(@builder.splat(val[1])).
415
+ concat(val[3])
416
+ }
417
+ | tSTAR mlhs_node
418
+ {
419
+ result = [ @builder.splat(val[0], val[1]) ]
420
+ }
421
+ | tSTAR mlhs_node tCOMMA mlhs_post
422
+ {
423
+ result = [ @builder.splat(val[0], val[1]),
424
+ *val[3] ]
425
+ }
426
+ | tSTAR
427
+ {
428
+ result = [ @builder.splat(val[0]) ]
429
+ }
430
+ | tSTAR tCOMMA mlhs_post
431
+ {
432
+ result = [ @builder.splat(val[0]),
433
+ *val[2] ]
434
+ }
435
+
436
+ mlhs_item: mlhs_node
437
+ | tLPAREN mlhs_inner rparen
438
+ {
439
+ result = @builder.parenthesize(val[0], val[1], val[2])
440
+ }
441
+
442
+ mlhs_head: mlhs_item tCOMMA
443
+ {
444
+ result = [ val[0] ]
445
+ }
446
+ | mlhs_head mlhs_item tCOMMA
447
+ {
448
+ result = val[0] << val[1]
449
+ }
450
+
451
+ mlhs_post: mlhs_item
452
+ {
453
+ result = [ val[0] ]
454
+ }
455
+ | mlhs_post tCOMMA mlhs_item
456
+ {
457
+ result = val[0] << val[2]
458
+ }
459
+
460
+ mlhs_node: user_variable
461
+ {
462
+ result = @builder.assignable(val[0])
463
+ }
464
+ | keyword_variable
465
+ {
466
+ result = @builder.assignable(val[0])
467
+ }
468
+ | primary_value tLBRACK2 opt_call_args rbracket
469
+ {
470
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
471
+ }
472
+ | primary_value tDOT tIDENTIFIER
473
+ {
474
+ result = @builder.attr_asgn(val[0], val[1], val[2])
475
+ }
476
+ | primary_value tCOLON2 tIDENTIFIER
477
+ {
478
+ result = @builder.attr_asgn(val[0], val[1], val[2])
479
+ }
480
+ | primary_value tDOT tCONSTANT
481
+ {
482
+ result = @builder.attr_asgn(val[0], val[1], val[2])
483
+ }
484
+ | primary_value tCOLON2 tCONSTANT
485
+ {
486
+ if in_def?
487
+ diagnostic(:error, :dynamic_const, val[2])
488
+ end
489
+
490
+ result = @builder.assignable(
491
+ @builder.const_fetch(val[0], val[1], val[2]))
492
+ }
493
+ | tCOLON3 tCONSTANT
494
+ {
495
+ if in_def?
496
+ diagnostic(:error, :dynamic_const, val[1])
497
+ end
498
+
499
+ result = @builder.assignable(
500
+ @builder.const_global(val[0], val[1]))
501
+ }
502
+ | backref
503
+ {
504
+ result = @builder.assignable(val[0])
505
+ }
506
+
507
+ lhs: user_variable
508
+ {
509
+ result = @builder.assignable(val[0])
510
+ }
511
+ | keyword_variable
512
+ {
513
+ result = @builder.assignable(val[0])
514
+ }
515
+ | primary_value tLBRACK2 opt_call_args rbracket
516
+ {
517
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
518
+ }
519
+ | primary_value tDOT tIDENTIFIER
520
+ {
521
+ result = @builder.attr_asgn(val[0], val[1], val[2])
522
+ }
523
+ | primary_value tCOLON2 tIDENTIFIER
524
+ {
525
+ result = @builder.attr_asgn(val[0], val[1], val[2])
526
+ }
527
+ | primary_value tDOT tCONSTANT
528
+ {
529
+ result = @builder.attr_asgn(val[0], val[1], val[2])
530
+ }
531
+ | primary_value tCOLON2 tCONSTANT
532
+ {
533
+ if in_def?
534
+ diagnostic(:error, :dynamic_const, val[2])
535
+ end
536
+
537
+ result = @builder.assignable(
538
+ @builder.const_fetch(val[0], val[1], val[2]))
539
+ }
540
+ | tCOLON3 tCONSTANT
541
+ {
542
+ if in_def?
543
+ diagnostic(:error, :dynamic_const, val[1])
544
+ end
545
+
546
+ result = @builder.assignable(
547
+ @builder.const_global(val[0], val[1]))
548
+ }
549
+ | backref
550
+ {
551
+ result = @builder.assignable(val[0])
552
+ }
553
+
554
+ cname: tIDENTIFIER
555
+ {
556
+ diagnostic(:error, :module_name_const, val[0])
557
+ }
558
+ | tCONSTANT
559
+
560
+ cpath: tCOLON3 cname
561
+ {
562
+ result = @builder.const_global(val[0], val[1])
563
+ }
564
+ | cname
565
+ {
566
+ result = @builder.const(val[0])
567
+ }
568
+ | primary_value tCOLON2 cname
569
+ {
570
+ result = @builder.const_fetch(val[0], val[1], val[2])
571
+ }
572
+
573
+ fname: tIDENTIFIER | tCONSTANT | tFID
574
+ | op
575
+ | reswords
576
+
577
+ fsym: fname
578
+ {
579
+ result = @builder.symbol(val[0])
580
+ }
581
+ | symbol
582
+
583
+ fitem: fsym
584
+ | dsym
585
+
586
+ undef_list: fitem
587
+ {
588
+ result = [ val[0] ]
589
+ }
590
+ | undef_list tCOMMA
591
+ {
592
+ @lexer.state = :expr_fname
593
+ }
594
+ fitem
595
+ {
596
+ result = val[0] << val[3]
597
+ }
598
+
599
+ op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
600
+ | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
601
+ | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
602
+ | tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
603
+ | tUPLUS | tUMINUS | tAREF | tASET | tDSTAR | tBACK_REF2
604
+
605
+ reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
606
+ | kALIAS | kAND | kBEGIN | kBREAK | kCASE
607
+ | kCLASS | kDEF | kDEFINED | kDO | kELSE
608
+ | kELSIF | kEND | kENSURE | kFALSE | kFOR
609
+ | kIN | kMODULE | kNEXT | kNIL | kNOT
610
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN
611
+ | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
612
+ | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
613
+ | kUNTIL
614
+
615
+ arg: lhs tEQL arg
616
+ {
617
+ result = @builder.assign(val[0], val[1], val[2])
618
+ }
619
+ | lhs tEQL arg kRESCUE_MOD arg
620
+ {
621
+ rescue_body = @builder.rescue_body(val[3],
622
+ nil, nil, nil,
623
+ nil, val[4])
624
+
625
+ rescue_ = @builder.begin_body(val[2], [ rescue_body ])
626
+
627
+ result = @builder.assign(val[0], val[1], rescue_)
628
+ }
629
+ | var_lhs tOP_ASGN arg
630
+ {
631
+ result = @builder.op_assign(val[0], val[1], val[2])
632
+ }
633
+ | var_lhs tOP_ASGN arg kRESCUE_MOD arg
634
+ {
635
+ rescue_body = @builder.rescue_body(val[3],
636
+ nil, nil, nil,
637
+ nil, val[4])
638
+
639
+ rescue_ = @builder.begin_body(val[2], [ rescue_body ])
640
+
641
+ result = @builder.op_assign(val[0], val[1], rescue_)
642
+ }
643
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
644
+ {
645
+ result = @builder.op_assign(
646
+ @builder.index(
647
+ val[0], val[1], val[2], val[3]),
648
+ val[4], val[5])
649
+ }
650
+ | primary_value tDOT tIDENTIFIER tOP_ASGN arg
651
+ {
652
+ result = @builder.op_assign(
653
+ @builder.call_method(
654
+ val[0], val[1], val[2]),
655
+ val[3], val[4])
656
+ }
657
+ | primary_value tDOT tCONSTANT tOP_ASGN arg
658
+ {
659
+ result = @builder.op_assign(
660
+ @builder.call_method(
661
+ val[0], val[1], val[2]),
662
+ val[3], val[4])
663
+ }
664
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
665
+ {
666
+ result = @builder.op_assign(
667
+ @builder.call_method(
668
+ val[0], val[1], val[2]),
669
+ val[3], val[4])
670
+ }
671
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
672
+ {
673
+ if in_def?
674
+ diagnostic(:error, :dynamic_const, val[2], [ val[3] ])
675
+ end
676
+
677
+ const = @builder.assignable(
678
+ @builder.const_fetch(val[0], val[1], val[2]))
679
+ result = @builder.op_assign(const, val[3], val[4])
680
+ }
681
+ | tCOLON3 tCONSTANT tOP_ASGN arg
682
+ {
683
+ if in_def?
684
+ diagnostic(:error, :dynamic_const, val[1], [ val[2] ])
685
+ end
686
+
687
+ const = @builder.assignable(
688
+ @builder.const_global(val[0], val[1]))
689
+ result = @builder.op_assign(const, val[2], val[3])
690
+ }
691
+ | backref tOP_ASGN arg
692
+ {
693
+ result = @builder.op_assign(val[0], val[1], val[2])
694
+ }
695
+ | arg tDOT2 arg
696
+ {
697
+ result = @builder.range_inclusive(val[0], val[1], val[2])
698
+ }
699
+ | arg tDOT3 arg
700
+ {
701
+ result = @builder.range_exclusive(val[0], val[1], val[2])
702
+ }
703
+ | arg tPLUS arg
704
+ {
705
+ result = @builder.binary_op(val[0], val[1], val[2])
706
+ }
707
+ | arg tMINUS arg
708
+ {
709
+ result = @builder.binary_op(val[0], val[1], val[2])
710
+ }
711
+ | arg tSTAR2 arg
712
+ {
713
+ result = @builder.binary_op(val[0], val[1], val[2])
714
+ }
715
+ | arg tDIVIDE arg
716
+ {
717
+ result = @builder.binary_op(val[0], val[1], val[2])
718
+ }
719
+ | arg tPERCENT arg
720
+ {
721
+ result = @builder.binary_op(val[0], val[1], val[2])
722
+ }
723
+ | arg tPOW arg
724
+ {
725
+ result = @builder.binary_op(val[0], val[1], val[2])
726
+ }
727
+ | tUMINUS_NUM tINTEGER tPOW arg
728
+ {
729
+ result = @builder.unary_op(val[0],
730
+ @builder.binary_op(
731
+ @builder.integer(val[1]),
732
+ val[2], val[3]))
733
+ }
734
+ | tUMINUS_NUM tFLOAT tPOW arg
735
+ {
736
+ result = @builder.unary_op(val[0],
737
+ @builder.binary_op(
738
+ @builder.float(val[1]),
739
+ val[2], val[3]))
740
+ }
741
+ | tUPLUS arg
742
+ {
743
+ result = @builder.unary_op(val[0], val[1])
744
+ }
745
+ | tUMINUS arg
746
+ {
747
+ result = @builder.unary_op(val[0], val[1])
748
+ }
749
+ | arg tPIPE arg
750
+ {
751
+ result = @builder.binary_op(val[0], val[1], val[2])
752
+ }
753
+ | arg tCARET arg
754
+ {
755
+ result = @builder.binary_op(val[0], val[1], val[2])
756
+ }
757
+ | arg tAMPER2 arg
758
+ {
759
+ result = @builder.binary_op(val[0], val[1], val[2])
760
+ }
761
+ | arg tCMP arg
762
+ {
763
+ result = @builder.binary_op(val[0], val[1], val[2])
764
+ }
765
+ | arg tGT arg
766
+ {
767
+ result = @builder.binary_op(val[0], val[1], val[2])
768
+ }
769
+ | arg tGEQ arg
770
+ {
771
+ result = @builder.binary_op(val[0], val[1], val[2])
772
+ }
773
+ | arg tLT arg
774
+ {
775
+ result = @builder.binary_op(val[0], val[1], val[2])
776
+ }
777
+ | arg tLEQ arg
778
+ {
779
+ result = @builder.binary_op(val[0], val[1], val[2])
780
+ }
781
+ | arg tEQ arg
782
+ {
783
+ result = @builder.binary_op(val[0], val[1], val[2])
784
+ }
785
+ | arg tEQQ arg
786
+ {
787
+ result = @builder.binary_op(val[0], val[1], val[2])
788
+ }
789
+ | arg tNEQ arg
790
+ {
791
+ result = @builder.binary_op(val[0], val[1], val[2])
792
+ }
793
+ | arg tMATCH arg
794
+ {
795
+ result = @builder.binary_op(val[0], val[1], val[2])
796
+ }
797
+ | arg tNMATCH arg
798
+ {
799
+ result = @builder.binary_op(val[0], val[1], val[2])
800
+ }
801
+ | tBANG arg
802
+ {
803
+ result = @builder.not_op(val[0], val[1])
804
+ }
805
+ | tTILDE arg
806
+ {
807
+ result = @builder.unary_op(val[0], val[1])
808
+ }
809
+ | arg tLSHFT arg
810
+ {
811
+ result = @builder.binary_op(val[0], val[1], val[2])
812
+ }
813
+ | arg tRSHFT arg
814
+ {
815
+ result = @builder.binary_op(val[0], val[1], val[2])
816
+ }
817
+ | arg tANDOP arg
818
+ {
819
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
820
+ }
821
+ | arg tOROP arg
822
+ {
823
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
824
+ }
825
+ | kDEFINED opt_nl arg
826
+ {
827
+ result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
828
+ }
829
+
830
+ | arg tEH arg opt_nl tCOLON arg
831
+ {
832
+ result = @builder.ternary(val[0], val[1],
833
+ val[2], val[4], val[5])
834
+ }
835
+ | primary
836
+
837
+ arg_value: arg
838
+ {
839
+ result = value_expr(val[0])
840
+ }
841
+
842
+ aref_args: none
843
+ | args trailer
844
+ | args tCOMMA assocs trailer
845
+ {
846
+ result = val[0] << @builder.associate(nil, val[2], nil)
847
+ }
848
+ | assocs trailer
849
+ {
850
+ result = [ @builder.associate(nil, val[0], nil) ]
851
+ }
852
+
853
+ paren_args: tLPAREN2 opt_call_args rparen
854
+ {
855
+ result = val
856
+ }
857
+
858
+ opt_paren_args: # nothing
859
+ {
860
+ result = [ nil, [], nil ]
861
+ }
862
+ | paren_args
863
+
864
+ opt_call_args: # nothing
865
+ {
866
+ result = []
867
+ }
868
+ | call_args
869
+ | args tCOMMA
870
+ | args tCOMMA assocs tCOMMA
871
+ {
872
+ result = val[0] << @builder.associate(nil, val[2], nil)
873
+ }
874
+ | assocs tCOMMA
875
+ {
876
+ result = [ @builder.associate(nil, val[0], nil) ]
877
+ }
878
+
879
+ call_args: command
880
+ {
881
+ result = [ val[0] ]
882
+ }
883
+ | args opt_block_arg
884
+ {
885
+ result = val[0].concat(val[1])
886
+ }
887
+ | assocs opt_block_arg
888
+ {
889
+ result = [ @builder.associate(nil, val[0], nil) ]
890
+ result.concat(val[1])
891
+ }
892
+ | args tCOMMA assocs opt_block_arg
893
+ {
894
+ assocs = @builder.associate(nil, val[2], nil)
895
+ result = val[0] << assocs
896
+ result.concat(val[3])
897
+ }
898
+ | block_arg
899
+ {
900
+ result = [ val[0] ]
901
+ }
902
+
903
+ command_args: {
904
+ result = @lexer.cmdarg.dup
905
+ @lexer.cmdarg.push(true)
906
+ }
907
+ call_args
908
+ {
909
+ @lexer.cmdarg = val[0]
910
+
911
+ result = val[1]
912
+ }
913
+
914
+ block_arg: tAMPER arg_value
915
+ {
916
+ result = @builder.block_pass(val[0], val[1])
917
+ }
918
+
919
+ opt_block_arg: tCOMMA block_arg
920
+ {
921
+ result = [ val[1] ]
922
+ }
923
+ | # nothing
924
+ {
925
+ result = []
926
+ }
927
+
928
+ args: arg_value
929
+ {
930
+ result = [ val[0] ]
931
+ }
932
+ | tSTAR arg_value
933
+ {
934
+ result = [ @builder.splat(val[0], val[1]) ]
935
+ }
936
+ | args tCOMMA arg_value
937
+ {
938
+ result = val[0] << val[2]
939
+ }
940
+ | args tCOMMA tSTAR arg_value
941
+ {
942
+ result = val[0] << @builder.splat(val[2], val[3])
943
+ }
944
+
945
+ mrhs_arg: mrhs
946
+ {
947
+ result = @builder.array(nil, val[0], nil)
948
+ }
949
+ | arg_value
950
+
951
+ mrhs: args tCOMMA arg_value
952
+ {
953
+ result = val[0] << val[2]
954
+ }
955
+ | args tCOMMA tSTAR arg_value
956
+ {
957
+ result = val[0] << @builder.splat(val[2], val[3])
958
+ }
959
+ | tSTAR arg_value
960
+ {
961
+ result = [ @builder.splat(val[0], val[1]) ]
962
+ }
963
+
964
+ primary: literal
965
+ | strings
966
+ | xstring
967
+ | regexp
968
+ | words
969
+ | qwords
970
+ | symbols
971
+ | qsymbols
972
+ | var_ref
973
+ | backref
974
+ | tFID
975
+ {
976
+ result = @builder.call_method(nil, nil, val[0])
977
+ }
978
+ | kBEGIN
979
+ {
980
+ result = @lexer.cmdarg.dup
981
+ @lexer.cmdarg.clear
982
+ }
983
+ bodystmt kEND
984
+ {
985
+ @lexer.cmdarg = val[1]
986
+
987
+ result = @builder.begin(val[0], val[2], val[3])
988
+ }
989
+ | tLPAREN_ARG expr
990
+ {
991
+ @lexer.state = :expr_endarg
992
+ }
993
+ opt_nl tRPAREN
994
+ {
995
+ result = @builder.parenthesize(val[0], val[1], val[4])
996
+ }
997
+ | tLPAREN_ARG
998
+ {
999
+ @lexer.state = :expr_endarg
1000
+ }
1001
+ opt_nl tRPAREN
1002
+ {
1003
+ result = @builder.parenthesize(val[0], nil, val[3])
1004
+ }
1005
+ | tLPAREN compstmt tRPAREN
1006
+ {
1007
+ result = @builder.parenthesize(val[0], val[1], val[2])
1008
+ }
1009
+ | primary_value tCOLON2 tCONSTANT
1010
+ {
1011
+ result = @builder.const_fetch(val[0], val[1], val[2])
1012
+ }
1013
+ | tCOLON3 tCONSTANT
1014
+ {
1015
+ result = @builder.const_global(val[0], val[1])
1016
+ }
1017
+ | tLBRACK aref_args tRBRACK
1018
+ {
1019
+ result = @builder.array(val[0], val[1], val[2])
1020
+ }
1021
+ | tLBRACE assoc_list tRCURLY
1022
+ {
1023
+ result = @builder.associate(val[0], val[1], val[2])
1024
+ }
1025
+ | kRETURN
1026
+ {
1027
+ result = @builder.keyword_cmd(:return, val[0])
1028
+ }
1029
+ | kYIELD tLPAREN2 call_args rparen
1030
+ {
1031
+ result = @builder.keyword_cmd(:yield, val[0], val[1], val[2], val[3])
1032
+ }
1033
+ | kYIELD tLPAREN2 rparen
1034
+ {
1035
+ result = @builder.keyword_cmd(:yield, val[0], val[1], [], val[2])
1036
+ }
1037
+ | kYIELD
1038
+ {
1039
+ result = @builder.keyword_cmd(:yield, val[0])
1040
+ }
1041
+ | kDEFINED opt_nl tLPAREN2 expr rparen
1042
+ {
1043
+ result = @builder.keyword_cmd(:defined?, val[0],
1044
+ val[2], [ val[3] ], val[4])
1045
+ }
1046
+ | kNOT tLPAREN2 expr rparen
1047
+ {
1048
+ result = @builder.not_op(val[0], val[2])
1049
+ }
1050
+ | kNOT tLPAREN2 rparen
1051
+ {
1052
+ result = @builder.not_op(val[0])
1053
+ }
1054
+ | fcall brace_block
1055
+ {
1056
+ method_call = @builder.call_method(nil, nil, val[0])
1057
+
1058
+ begin_t, args, body, end_t = val[1]
1059
+ result = @builder.block(method_call,
1060
+ begin_t, args, body, end_t)
1061
+ }
1062
+ | method_call
1063
+ | method_call brace_block
1064
+ {
1065
+ begin_t, args, body, end_t = val[1]
1066
+ result = @builder.block(val[0],
1067
+ begin_t, args, body, end_t)
1068
+ }
1069
+ | tLAMBDA lambda
1070
+ {
1071
+ lambda_call = @builder.call_lambda(val[0])
1072
+
1073
+ args, (begin_t, body, end_t) = val[1]
1074
+ result = @builder.block(lambda_call,
1075
+ begin_t, args, body, end_t)
1076
+ }
1077
+ | kIF expr_value then compstmt if_tail kEND
1078
+ {
1079
+ else_t, else_ = val[4]
1080
+ result = @builder.condition(val[0], val[1], val[2],
1081
+ val[3], else_t,
1082
+ else_, val[5])
1083
+ }
1084
+ | kUNLESS expr_value then compstmt opt_else kEND
1085
+ {
1086
+ else_t, else_ = val[4]
1087
+ result = @builder.condition(val[0], val[1], val[2],
1088
+ else_, else_t,
1089
+ val[3], val[5])
1090
+ }
1091
+ | kWHILE
1092
+ {
1093
+ @lexer.cond.push(true)
1094
+ }
1095
+ expr_value do
1096
+ {
1097
+ @lexer.cond.pop
1098
+ }
1099
+ compstmt kEND
1100
+ {
1101
+ result = @builder.loop(val[0], val[2], val[3],
1102
+ val[5], val[6])
1103
+ }
1104
+ | kUNTIL
1105
+ {
1106
+ @lexer.cond.push(true)
1107
+ }
1108
+ expr_value do
1109
+ {
1110
+ @lexer.cond.pop
1111
+ }
1112
+ compstmt kEND
1113
+ {
1114
+ result = @builder.loop(val[0], val[2], val[3],
1115
+ val[5], val[6])
1116
+ }
1117
+ | kCASE expr_value opt_terms case_body kEND
1118
+ {
1119
+ result = @builder.case(val[0], val[1], val[3], val[4])
1120
+ }
1121
+ | kCASE opt_terms case_body kEND
1122
+ {
1123
+ result = @builder.case(val[0], nil, val[2], val[3])
1124
+ }
1125
+ | kFOR for_var kIN
1126
+ {
1127
+ @lexer.cond.push(true)
1128
+ }
1129
+ expr_value do
1130
+ {
1131
+ @lexer.cond.pop
1132
+ }
1133
+ compstmt kEND
1134
+ {
1135
+ result = @builder.for(val[0], val[1],
1136
+ val[2], val[4],
1137
+ val[5], val[7], val[8])
1138
+ }
1139
+ | kCLASS cpath superclass
1140
+ {
1141
+ if in_def?
1142
+ diagnostic(:error, :class_in_def, val[0])
1143
+ end
1144
+
1145
+ @comments.push @lexer.clear_comments
1146
+ @static_env.extend_static
1147
+ }
1148
+ bodystmt kEND
1149
+ {
1150
+ lt_t, superclass = val[2]
1151
+ result = @builder.def_class(val[0], val[1],
1152
+ lt_t, superclass,
1153
+ val[4], val[5])
1154
+
1155
+ @static_env.unextend
1156
+ @lexer.clear_comments
1157
+ }
1158
+ | kCLASS tLSHFT expr term
1159
+ {
1160
+ result = @def_level
1161
+ @def_level = 0
1162
+
1163
+ @static_env.extend_static
1164
+ }
1165
+ bodystmt kEND
1166
+ {
1167
+ result = @builder.def_sclass(val[0], val[1], val[2],
1168
+ val[5], val[6])
1169
+
1170
+ @static_env.unextend
1171
+ @lexer.clear_comments
1172
+
1173
+ @def_level = val[4]
1174
+ }
1175
+ | kMODULE cpath
1176
+ {
1177
+ if in_def?
1178
+ diagnostic(:error, :module_in_def, val[0])
1179
+ end
1180
+
1181
+ @comments.push @lexer.clear_comments
1182
+ @static_env.extend_static
1183
+ }
1184
+ bodystmt kEND
1185
+ {
1186
+ result = @builder.def_module(val[0], val[1],
1187
+ val[3], val[4])
1188
+
1189
+ @static_env.unextend
1190
+ @lexer.clear_comments
1191
+ }
1192
+ | kDEF fname
1193
+ {
1194
+ @comments.push @lexer.clear_comments
1195
+ @def_level += 1
1196
+ @static_env.extend_static
1197
+ }
1198
+ f_arglist bodystmt kEND
1199
+ {
1200
+ result = @builder.def_method(val[0], val[1],
1201
+ val[3], val[4], val[5], @comments.pop)
1202
+
1203
+ @static_env.unextend
1204
+ @def_level -= 1
1205
+ @lexer.clear_comments
1206
+ }
1207
+ | kDEF singleton dot_or_colon
1208
+ {
1209
+ @comments.push @lexer.clear_comments
1210
+ @lexer.state = :expr_fname
1211
+ }
1212
+ fname
1213
+ {
1214
+ @def_level += 1
1215
+ @static_env.extend_static
1216
+ }
1217
+ f_arglist bodystmt kEND
1218
+ {
1219
+ result = @builder.def_singleton(val[0], val[1], val[2],
1220
+ val[4], val[6], val[7], val[8], @comments.pop)
1221
+
1222
+ @static_env.unextend
1223
+ @def_level -= 1
1224
+ @lexer.clear_comments
1225
+ }
1226
+ | kBREAK
1227
+ {
1228
+ result = @builder.keyword_cmd(:break, val[0])
1229
+ }
1230
+ | kNEXT
1231
+ {
1232
+ result = @builder.keyword_cmd(:next, val[0])
1233
+ }
1234
+ | kREDO
1235
+ {
1236
+ result = @builder.keyword_cmd(:redo, val[0])
1237
+ }
1238
+ | kRETRY
1239
+ {
1240
+ result = @builder.keyword_cmd(:retry, val[0])
1241
+ }
1242
+
1243
+ primary_value: primary
1244
+ {
1245
+ result = value_expr(val[0])
1246
+ }
1247
+
1248
+ then: term
1249
+ | kTHEN
1250
+ | term kTHEN
1251
+
1252
+ do: term
1253
+ | kDO_COND
1254
+
1255
+ if_tail: opt_else
1256
+ | kELSIF expr_value then compstmt if_tail
1257
+ {
1258
+ else_t, else_ = val[4]
1259
+ result = [ val[0],
1260
+ @builder.condition(val[0], val[1], val[2],
1261
+ val[3], else_t,
1262
+ else_, nil),
1263
+ ]
1264
+ }
1265
+
1266
+ opt_else: none
1267
+ | kELSE compstmt
1268
+ {
1269
+ result = val
1270
+ }
1271
+
1272
+ for_var: lhs
1273
+ | mlhs
1274
+
1275
+ f_marg: f_norm_arg
1276
+ {
1277
+ @static_env.declare val[0][0]
1278
+
1279
+ result = @builder.arg(val[0])
1280
+ }
1281
+ | tLPAREN f_margs rparen
1282
+ {
1283
+ result = @builder.multi_lhs(val[0], val[1], val[2])
1284
+ }
1285
+
1286
+ f_marg_list: f_marg
1287
+ {
1288
+ result = [ val[0] ]
1289
+ }
1290
+ | f_marg_list tCOMMA f_marg
1291
+ {
1292
+ result = val[0] << val[2]
1293
+ }
1294
+
1295
+ f_margs: f_marg_list
1296
+ | f_marg_list tCOMMA tSTAR f_norm_arg
1297
+ {
1298
+ @static_env.declare val[3][0]
1299
+
1300
+ result = val[0].
1301
+ push(@builder.restarg(val[2], val[3]))
1302
+ }
1303
+ | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1304
+ {
1305
+ @static_env.declare val[3][0]
1306
+
1307
+ result = val[0].
1308
+ push(@builder.restarg(val[2], val[3])).
1309
+ concat(val[5])
1310
+ }
1311
+ | f_marg_list tCOMMA tSTAR
1312
+ {
1313
+ result = val[0].
1314
+ push(@builder.restarg(val[2]))
1315
+ }
1316
+ | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1317
+ {
1318
+ result = val[0].
1319
+ push(@builder.restarg(val[2])).
1320
+ concat(val[4])
1321
+ }
1322
+ | tSTAR f_norm_arg
1323
+ {
1324
+ @static_env.declare val[1][0]
1325
+
1326
+ result = [ @builder.restarg(val[0], val[1]) ]
1327
+ }
1328
+ | tSTAR f_norm_arg tCOMMA f_marg_list
1329
+ {
1330
+ @static_env.declare val[1][0]
1331
+
1332
+ result = [ @builder.restarg(val[0], val[1]),
1333
+ *val[3] ]
1334
+ }
1335
+ | tSTAR
1336
+ {
1337
+ result = [ @builder.restarg(val[0]) ]
1338
+ }
1339
+ | tSTAR tCOMMA f_marg_list
1340
+ {
1341
+ result = [ @builder.restarg(val[0]),
1342
+ *val[2] ]
1343
+ }
1344
+
1345
+ block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1346
+ {
1347
+ result = val[0].concat(val[2]).concat(val[3])
1348
+ }
1349
+ | f_block_kwarg opt_f_block_arg
1350
+ {
1351
+ result = val[0].concat(val[1])
1352
+ }
1353
+ | f_kwrest opt_f_block_arg
1354
+ {
1355
+ result = val[0].concat(val[1])
1356
+ }
1357
+ | f_block_arg
1358
+ {
1359
+ result = [ val[0] ]
1360
+ }
1361
+
1362
+ opt_block_args_tail:
1363
+ tCOMMA block_args_tail
1364
+ {
1365
+ result = val[1]
1366
+ }
1367
+ | # nothing
1368
+ {
1369
+ result = []
1370
+ }
1371
+
1372
+ block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1373
+ {
1374
+ result = val[0].
1375
+ concat(val[2]).
1376
+ concat(val[4]).
1377
+ concat(val[5])
1378
+ }
1379
+ | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1380
+ {
1381
+ result = val[0].
1382
+ concat(val[2]).
1383
+ concat(val[4]).
1384
+ concat(val[6]).
1385
+ concat(val[7])
1386
+ }
1387
+ | f_arg tCOMMA f_block_optarg opt_block_args_tail
1388
+ {
1389
+ result = val[0].
1390
+ concat(val[2]).
1391
+ concat(val[3])
1392
+ }
1393
+ | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1394
+ {
1395
+ result = val[0].
1396
+ concat(val[2]).
1397
+ concat(val[4]).
1398
+ concat(val[5])
1399
+ }
1400
+ | f_arg tCOMMA f_rest_arg opt_block_args_tail
1401
+ {
1402
+ result = val[0].
1403
+ concat(val[2]).
1404
+ concat(val[3])
1405
+ }
1406
+ | f_arg tCOMMA
1407
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1408
+ {
1409
+ result = val[0].
1410
+ concat(val[2]).
1411
+ concat(val[4]).
1412
+ concat(val[5])
1413
+ }
1414
+ | f_arg opt_block_args_tail
1415
+ {
1416
+ result = val[0].concat(val[1])
1417
+ }
1418
+ | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1419
+ {
1420
+ result = val[0].
1421
+ concat(val[2]).
1422
+ concat(val[3])
1423
+ }
1424
+ | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1425
+ {
1426
+ result = val[0].
1427
+ concat(val[2]).
1428
+ concat(val[4]).
1429
+ concat(val[5])
1430
+ }
1431
+ | f_block_optarg opt_block_args_tail
1432
+ {
1433
+ result = val[0].
1434
+ concat(val[1])
1435
+ }
1436
+ | f_block_optarg tCOMMA f_arg opt_block_args_tail
1437
+ {
1438
+ result = val[0].
1439
+ concat(val[2]).
1440
+ concat(val[3])
1441
+ }
1442
+ | f_rest_arg opt_block_args_tail
1443
+ {
1444
+ result = val[0].
1445
+ concat(val[1])
1446
+ }
1447
+ | f_rest_arg tCOMMA f_arg opt_block_args_tail
1448
+ {
1449
+ result = val[0].
1450
+ concat(val[2]).
1451
+ concat(val[3])
1452
+ }
1453
+ | block_args_tail
1454
+
1455
+ opt_block_param: # nothing
1456
+ {
1457
+ result = @builder.args(nil, [], nil)
1458
+ }
1459
+ | block_param_def
1460
+ {
1461
+ @lexer.state = :expr_value
1462
+ }
1463
+
1464
+ block_param_def: tPIPE opt_bv_decl tPIPE
1465
+ {
1466
+ result = @builder.args(val[0], val[1], val[2])
1467
+ }
1468
+ | tOROP
1469
+ {
1470
+ result = @builder.args(val[0], [], val[0])
1471
+ }
1472
+ | tPIPE block_param opt_bv_decl tPIPE
1473
+ {
1474
+ result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1475
+ }
1476
+
1477
+ opt_bv_decl: opt_nl
1478
+ {
1479
+ result = []
1480
+ }
1481
+ | opt_nl tSEMI bv_decls opt_nl
1482
+ {
1483
+ result = val[2]
1484
+ }
1485
+
1486
+ bv_decls: bvar
1487
+ {
1488
+ result = [ val[0] ]
1489
+ }
1490
+ | bv_decls tCOMMA bvar
1491
+ {
1492
+ result = val[0] << val[2]
1493
+ }
1494
+
1495
+ bvar: tIDENTIFIER
1496
+ {
1497
+ result = @builder.shadowarg(val[0])
1498
+ }
1499
+ | f_bad_arg
1500
+
1501
+ lambda: f_larglist lambda_body
1502
+ {
1503
+ result = [ val[0], val[1] ]
1504
+ }
1505
+
1506
+ f_larglist: tLPAREN2 f_args opt_bv_decl tRPAREN
1507
+ {
1508
+ result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1509
+ }
1510
+ | f_args
1511
+ {
1512
+ result = @builder.args(nil, val[0], nil)
1513
+ }
1514
+
1515
+ lambda_body: tLAMBEG compstmt tRCURLY
1516
+ {
1517
+ result = [ val[0], val[1], val[2] ]
1518
+ }
1519
+ | kDO_LAMBDA compstmt kEND
1520
+ {
1521
+ result = [ val[0], val[1], val[2] ]
1522
+ }
1523
+
1524
+ do_block: kDO_BLOCK
1525
+ {
1526
+ @static_env.extend_dynamic
1527
+ }
1528
+ opt_block_param compstmt kEND
1529
+ {
1530
+ result = [ val[0], val[2], val[3], val[4] ]
1531
+
1532
+ @static_env.unextend
1533
+ }
1534
+
1535
+ block_call: command do_block
1536
+ {
1537
+ begin_t, block_args, body, end_t = val[1]
1538
+ result = @builder.block(val[0],
1539
+ begin_t, block_args, body, end_t)
1540
+ }
1541
+ | block_call dot_or_colon operation2 opt_paren_args
1542
+ {
1543
+ lparen_t, args, rparen_t = val[3]
1544
+ result = @builder.call_method(val[0], val[1], val[2],
1545
+ lparen_t, args, rparen_t)
1546
+ }
1547
+ | block_call dot_or_colon operation2 opt_paren_args brace_block
1548
+ {
1549
+ lparen_t, args, rparen_t = val[3]
1550
+ method_call = @builder.call_method(val[0], val[1], val[2],
1551
+ lparen_t, args, rparen_t)
1552
+
1553
+ begin_t, args, body, end_t = val[4]
1554
+ result = @builder.block(method_call,
1555
+ begin_t, args, body, end_t)
1556
+ }
1557
+ | block_call dot_or_colon operation2 command_args do_block
1558
+ {
1559
+ method_call = @builder.call_method(val[0], val[1], val[2],
1560
+ nil, val[3], nil)
1561
+
1562
+ begin_t, args, body, end_t = val[4]
1563
+ result = @builder.block(method_call,
1564
+ begin_t, args, body, end_t)
1565
+ }
1566
+
1567
+ method_call: fcall paren_args
1568
+ {
1569
+ lparen_t, args, rparen_t = val[1]
1570
+ result = @builder.call_method(nil, nil, val[0],
1571
+ lparen_t, args, rparen_t)
1572
+ }
1573
+ | primary_value tDOT operation2 opt_paren_args
1574
+ {
1575
+ lparen_t, args, rparen_t = val[3]
1576
+ result = @builder.call_method(val[0], val[1], val[2],
1577
+ lparen_t, args, rparen_t)
1578
+ }
1579
+ | primary_value tCOLON2 operation2 paren_args
1580
+ {
1581
+ lparen_t, args, rparen_t = val[3]
1582
+ result = @builder.call_method(val[0], val[1], val[2],
1583
+ lparen_t, args, rparen_t)
1584
+ }
1585
+ | primary_value tCOLON2 operation3
1586
+ {
1587
+ result = @builder.call_method(val[0], val[1], val[2])
1588
+ }
1589
+ | primary_value tDOT paren_args
1590
+ {
1591
+ lparen_t, args, rparen_t = val[2]
1592
+ result = @builder.call_method(val[0], val[1], nil,
1593
+ lparen_t, args, rparen_t)
1594
+ }
1595
+ | primary_value tCOLON2 paren_args
1596
+ {
1597
+ lparen_t, args, rparen_t = val[2]
1598
+ result = @builder.call_method(val[0], val[1], nil,
1599
+ lparen_t, args, rparen_t)
1600
+ }
1601
+ | kSUPER paren_args
1602
+ {
1603
+ lparen_t, args, rparen_t = val[1]
1604
+ result = @builder.keyword_cmd(:super, val[0],
1605
+ lparen_t, args, rparen_t)
1606
+ }
1607
+ | kSUPER
1608
+ {
1609
+ result = @builder.keyword_cmd(:zsuper, val[0])
1610
+ }
1611
+ | primary_value tLBRACK2 opt_call_args rbracket
1612
+ {
1613
+ result = @builder.index(val[0], val[1], val[2], val[3])
1614
+ }
1615
+
1616
+ brace_block: tLCURLY
1617
+ {
1618
+ @static_env.extend_dynamic
1619
+ }
1620
+ opt_block_param compstmt tRCURLY
1621
+ {
1622
+ result = [ val[0], val[2], val[3], val[4] ]
1623
+
1624
+ @static_env.unextend
1625
+ }
1626
+ | kDO
1627
+ {
1628
+ @static_env.extend_dynamic
1629
+ }
1630
+ opt_block_param compstmt kEND
1631
+ {
1632
+ result = [ val[0], val[2], val[3], val[4] ]
1633
+
1634
+ @static_env.unextend
1635
+ }
1636
+
1637
+ case_body: kWHEN args then compstmt cases
1638
+ {
1639
+ result = [ @builder.when(val[0], val[1], val[2], val[3]),
1640
+ *val[4] ]
1641
+ }
1642
+
1643
+ cases: opt_else
1644
+ {
1645
+ else_t, else_ = val[0]
1646
+ result = [ else_ ]
1647
+ }
1648
+ | case_body
1649
+
1650
+ opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1651
+ {
1652
+ assoc_t, exc_var = val[2]
1653
+
1654
+ if val[1]
1655
+ exc_list = @builder.array(nil, val[1], nil)
1656
+ end
1657
+
1658
+ result = [ @builder.rescue_body(val[0],
1659
+ exc_list, assoc_t, exc_var,
1660
+ val[3], val[4]),
1661
+ *val[5] ]
1662
+ }
1663
+ |
1664
+ {
1665
+ result = []
1666
+ }
1667
+
1668
+ exc_list: arg_value
1669
+ {
1670
+ result = [ val[0] ]
1671
+ }
1672
+ | mrhs
1673
+ | none
1674
+
1675
+ exc_var: tASSOC lhs
1676
+ {
1677
+ result = val
1678
+ }
1679
+ | none
1680
+
1681
+ opt_ensure: kENSURE compstmt
1682
+ {
1683
+ result = val
1684
+ }
1685
+ | none
1686
+
1687
+ literal: numeric
1688
+ | symbol
1689
+ | dsym
1690
+
1691
+ strings: string
1692
+ {
1693
+ result = @builder.string_compose(nil, val[0], nil)
1694
+ }
1695
+
1696
+ string: string1
1697
+ {
1698
+ result = [ val[0] ]
1699
+ }
1700
+ | string string1
1701
+ {
1702
+ result = val[0] << val[1]
1703
+ }
1704
+
1705
+ string1: tSTRING_BEG string_contents tSTRING_END
1706
+ {
1707
+ result = @builder.string_compose(val[0], val[1], val[2])
1708
+ }
1709
+ | tSTRING
1710
+ {
1711
+ result = @builder.string(val[0])
1712
+ }
1713
+
1714
+ xstring: tXSTRING_BEG xstring_contents tSTRING_END
1715
+ {
1716
+ result = @builder.xstring_compose(val[0], val[1], val[2])
1717
+ }
1718
+
1719
+ regexp: tREGEXP_BEG regexp_contents tSTRING_END tREGEXP_OPT
1720
+ {
1721
+ opts = @builder.regexp_options(val[3])
1722
+ result = @builder.regexp_compose(val[0], val[1], val[2], opts)
1723
+ }
1724
+
1725
+ words: tWORDS_BEG word_list tSTRING_END
1726
+ {
1727
+ result = @builder.words_compose(val[0], val[1], val[2])
1728
+ }
1729
+
1730
+ word_list: # nothing
1731
+ {
1732
+ result = []
1733
+ }
1734
+ | word_list word tSPACE
1735
+ {
1736
+ result = val[0] << @builder.word(val[1])
1737
+ }
1738
+
1739
+ word: string_content
1740
+ {
1741
+ result = [ val[0] ]
1742
+ }
1743
+ | word string_content
1744
+ {
1745
+ result = val[0] << val[1]
1746
+ }
1747
+
1748
+ symbols: tSYMBOLS_BEG symbol_list tSTRING_END
1749
+ {
1750
+ result = @builder.symbols_compose(val[0], val[1], val[2])
1751
+ }
1752
+
1753
+ symbol_list: # nothing
1754
+ {
1755
+ result = []
1756
+ }
1757
+ | symbol_list word tSPACE
1758
+ {
1759
+ result = val[0] << @builder.word(val[1])
1760
+ }
1761
+
1762
+ qwords: tQWORDS_BEG qword_list tSTRING_END
1763
+ {
1764
+ result = @builder.words_compose(val[0], val[1], val[2])
1765
+ }
1766
+
1767
+ qsymbols: tQSYMBOLS_BEG qsym_list tSTRING_END
1768
+ {
1769
+ result = @builder.symbols_compose(val[0], val[1], val[2])
1770
+ }
1771
+
1772
+ qword_list: # nothing
1773
+ {
1774
+ result = []
1775
+ }
1776
+ | qword_list tSTRING_CONTENT tSPACE
1777
+ {
1778
+ result = val[0] << @builder.string(val[1])
1779
+ }
1780
+
1781
+ qsym_list: # nothing
1782
+ {
1783
+ result = []
1784
+ }
1785
+ | qsym_list tSTRING_CONTENT tSPACE
1786
+ {
1787
+ result = val[0] << @builder.symbol(val[1])
1788
+ }
1789
+
1790
+ string_contents: # nothing
1791
+ {
1792
+ result = []
1793
+ }
1794
+ | string_contents string_content
1795
+ {
1796
+ result = val[0] << val[1]
1797
+ }
1798
+
1799
+ xstring_contents: # nothing
1800
+ {
1801
+ result = []
1802
+ }
1803
+ | xstring_contents string_content
1804
+ {
1805
+ result = val[0] << val[1]
1806
+ }
1807
+
1808
+ regexp_contents: # nothing
1809
+ {
1810
+ result = []
1811
+ }
1812
+ | regexp_contents string_content
1813
+ {
1814
+ result = val[0] << val[1]
1815
+ }
1816
+
1817
+ string_content: tSTRING_CONTENT
1818
+ {
1819
+ result = @builder.string(val[0])
1820
+ }
1821
+ | tSTRING_DVAR string_dvar
1822
+ {
1823
+ result = val[1]
1824
+ }
1825
+ | tSTRING_DBEG
1826
+ {
1827
+ @lexer.cond.push(false)
1828
+ @lexer.cmdarg.push(false)
1829
+ }
1830
+ compstmt tSTRING_DEND
1831
+ {
1832
+ @lexer.cond.lexpop
1833
+ @lexer.cmdarg.lexpop
1834
+
1835
+ result = val[2]
1836
+ }
1837
+
1838
+ string_dvar: tGVAR
1839
+ {
1840
+ result = @builder.gvar(val[0])
1841
+ }
1842
+ | tIVAR
1843
+ {
1844
+ result = @builder.ivar(val[0])
1845
+ }
1846
+ | tCVAR
1847
+ {
1848
+ result = @builder.cvar(val[0])
1849
+ }
1850
+ | backref
1851
+
1852
+
1853
+ symbol: tSYMBOL
1854
+ {
1855
+ result = @builder.symbol(val[0])
1856
+ }
1857
+
1858
+ dsym: tSYMBEG xstring_contents tSTRING_END
1859
+ {
1860
+ result = @builder.symbol_compose(val[0], val[1], val[2])
1861
+ }
1862
+
1863
+ numeric: tINTEGER
1864
+ {
1865
+ result = @builder.integer(val[0])
1866
+ }
1867
+ | tFLOAT
1868
+ {
1869
+ result = @builder.float(val[0])
1870
+ }
1871
+ | tUMINUS_NUM tINTEGER =tLOWEST
1872
+ {
1873
+ result = @builder.integer(val[1], true)
1874
+ }
1875
+ | tUMINUS_NUM tFLOAT =tLOWEST
1876
+ {
1877
+ result = @builder.float(val[1], true)
1878
+ }
1879
+
1880
+ user_variable: tIDENTIFIER
1881
+ {
1882
+ result = @builder.ident(val[0])
1883
+ }
1884
+ | tIVAR
1885
+ {
1886
+ result = @builder.ivar(val[0])
1887
+ }
1888
+ | tGVAR
1889
+ {
1890
+ result = @builder.gvar(val[0])
1891
+ }
1892
+ | tCONSTANT
1893
+ {
1894
+ result = @builder.const(val[0])
1895
+ }
1896
+ | tCVAR
1897
+ {
1898
+ result = @builder.cvar(val[0])
1899
+ }
1900
+
1901
+ keyword_variable: kNIL
1902
+ {
1903
+ result = @builder.nil(val[0])
1904
+ }
1905
+ | kSELF
1906
+ {
1907
+ result = @builder.self(val[0])
1908
+ }
1909
+ | kTRUE
1910
+ {
1911
+ result = @builder.true(val[0])
1912
+ }
1913
+ | kFALSE
1914
+ {
1915
+ result = @builder.false(val[0])
1916
+ }
1917
+ | k__FILE__
1918
+ {
1919
+ result = @builder.__FILE__(val[0])
1920
+ }
1921
+ | k__LINE__
1922
+ {
1923
+ result = @builder.__LINE__(val[0])
1924
+ }
1925
+ | k__ENCODING__
1926
+ {
1927
+ result = @builder.__ENCODING__(val[0])
1928
+ }
1929
+
1930
+ var_ref: user_variable
1931
+ {
1932
+ result = @builder.accessible(val[0])
1933
+ }
1934
+ | keyword_variable
1935
+ {
1936
+ result = @builder.accessible(val[0])
1937
+ }
1938
+
1939
+ var_lhs: user_variable
1940
+ {
1941
+ result = @builder.assignable(val[0])
1942
+ }
1943
+ | keyword_variable
1944
+ {
1945
+ result = @builder.assignable(val[0])
1946
+ }
1947
+
1948
+ backref: tNTH_REF
1949
+ {
1950
+ result = @builder.nth_ref(val[0])
1951
+ }
1952
+ | tBACK_REF
1953
+ {
1954
+ result = @builder.back_ref(val[0])
1955
+ }
1956
+
1957
+ superclass: term
1958
+ {
1959
+ result = nil
1960
+ }
1961
+ | tLT
1962
+ {
1963
+ @lexer.state = :expr_value
1964
+ }
1965
+ expr_value term
1966
+ {
1967
+ result = [ val[0], val[2] ]
1968
+ }
1969
+ | error term
1970
+ {
1971
+ yyerrok
1972
+ result = nil
1973
+ }
1974
+
1975
+ f_arglist: tLPAREN2 f_args rparen
1976
+ {
1977
+ result = @builder.args(val[0], val[1], val[2])
1978
+
1979
+ @lexer.state = :expr_value
1980
+ }
1981
+ | f_args term
1982
+ {
1983
+ result = @builder.args(nil, val[0], nil)
1984
+
1985
+ @lexer.state = :expr_value
1986
+ }
1987
+
1988
+ args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
1989
+ {
1990
+ result = val[0].concat(val[2]).concat(val[3])
1991
+ }
1992
+ | f_kwarg opt_f_block_arg
1993
+ {
1994
+ result = val[0].concat(val[1])
1995
+ }
1996
+ | f_kwrest opt_f_block_arg
1997
+ {
1998
+ result = val[0].concat(val[1])
1999
+ }
2000
+ | f_block_arg
2001
+ {
2002
+ result = [ val[0] ]
2003
+ }
2004
+
2005
+ opt_args_tail: tCOMMA args_tail
2006
+ {
2007
+ result = val[1]
2008
+ }
2009
+ | # nothing
2010
+ {
2011
+ result = []
2012
+ }
2013
+
2014
+ f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
2015
+ {
2016
+ result = val[0].
2017
+ concat(val[2]).
2018
+ concat(val[4]).
2019
+ concat(val[5])
2020
+ }
2021
+ | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2022
+ {
2023
+ result = val[0].
2024
+ concat(val[2]).
2025
+ concat(val[4]).
2026
+ concat(val[6]).
2027
+ concat(val[7])
2028
+ }
2029
+ | f_arg tCOMMA f_optarg opt_args_tail
2030
+ {
2031
+ result = val[0].
2032
+ concat(val[2]).
2033
+ concat(val[3])
2034
+ }
2035
+ | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
2036
+ {
2037
+ result = val[0].
2038
+ concat(val[2]).
2039
+ concat(val[4]).
2040
+ concat(val[5])
2041
+ }
2042
+ | f_arg tCOMMA f_rest_arg opt_args_tail
2043
+ {
2044
+ result = val[0].
2045
+ concat(val[2]).
2046
+ concat(val[3])
2047
+ }
2048
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2049
+ {
2050
+ result = val[0].
2051
+ concat(val[2]).
2052
+ concat(val[4]).
2053
+ concat(val[5])
2054
+ }
2055
+ | f_arg opt_args_tail
2056
+ {
2057
+ result = val[0].
2058
+ concat(val[1])
2059
+ }
2060
+ | f_optarg tCOMMA f_rest_arg opt_args_tail
2061
+ {
2062
+ result = val[0].
2063
+ concat(val[2]).
2064
+ concat(val[3])
2065
+ }
2066
+ | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2067
+ {
2068
+ result = val[0].
2069
+ concat(val[2]).
2070
+ concat(val[4]).
2071
+ concat(val[5])
2072
+ }
2073
+ | f_optarg opt_args_tail
2074
+ {
2075
+ result = val[0].
2076
+ concat(val[1])
2077
+ }
2078
+ | f_optarg tCOMMA f_arg opt_args_tail
2079
+ {
2080
+ result = val[0].
2081
+ concat(val[2]).
2082
+ concat(val[3])
2083
+ }
2084
+ | f_rest_arg opt_args_tail
2085
+ {
2086
+ result = val[0].
2087
+ concat(val[1])
2088
+ }
2089
+ | f_rest_arg tCOMMA f_arg opt_args_tail
2090
+ {
2091
+ result = val[0].
2092
+ concat(val[2]).
2093
+ concat(val[3])
2094
+ }
2095
+ | args_tail
2096
+ {
2097
+ result = val[0]
2098
+ }
2099
+ | # nothing
2100
+ {
2101
+ result = []
2102
+ }
2103
+
2104
+ f_bad_arg: tCONSTANT
2105
+ {
2106
+ diagnostic(:error, :argument_const, val[0])
2107
+ }
2108
+ | tIVAR
2109
+ {
2110
+ diagnostic(:error, :argument_ivar, val[0])
2111
+ }
2112
+ | tGVAR
2113
+ {
2114
+ diagnostic(:error, :argument_gvar, val[0])
2115
+ }
2116
+ | tCVAR
2117
+ {
2118
+ diagnostic(:error, :argument_cvar, val[0])
2119
+ }
2120
+
2121
+ f_norm_arg: f_bad_arg
2122
+ | tIDENTIFIER
2123
+
2124
+ f_arg_item: f_norm_arg
2125
+ {
2126
+ @static_env.declare val[0][0]
2127
+
2128
+ result = @builder.arg(val[0])
2129
+ }
2130
+ | tLPAREN f_margs rparen
2131
+ {
2132
+ result = @builder.multi_lhs(val[0], val[1], val[2])
2133
+ }
2134
+
2135
+ f_arg: f_arg_item
2136
+ {
2137
+ result = [ val[0] ]
2138
+ }
2139
+ | f_arg tCOMMA f_arg_item
2140
+ {
2141
+ result = val[0] << val[2]
2142
+ }
2143
+
2144
+ f_kw: tLABEL arg_value
2145
+ {
2146
+ check_kwarg_name(val[0])
2147
+
2148
+ @static_env.declare val[0][0]
2149
+
2150
+ result = @builder.kwoptarg(val[0], val[1])
2151
+ }
2152
+ | tLABEL
2153
+ {
2154
+ check_kwarg_name(val[0])
2155
+
2156
+ @static_env.declare val[0][0]
2157
+
2158
+ result = @builder.kwarg(val[0])
2159
+ }
2160
+
2161
+ f_block_kw: tLABEL primary_value
2162
+ {
2163
+ check_kwarg_name(val[0])
2164
+
2165
+ @static_env.declare val[0][0]
2166
+
2167
+ result = @builder.kwoptarg(val[0], val[1])
2168
+ }
2169
+ | tLABEL
2170
+ {
2171
+ check_kwarg_name(val[0])
2172
+
2173
+ @static_env.declare val[0][0]
2174
+
2175
+ result = @builder.kwarg(val[0])
2176
+ }
2177
+
2178
+ f_block_kwarg: f_block_kw
2179
+ {
2180
+ result = [ val[0] ]
2181
+ }
2182
+ | f_block_kwarg tCOMMA f_block_kw
2183
+ {
2184
+ result = val[0] << val[2]
2185
+ }
2186
+
2187
+ f_kwarg: f_kw
2188
+ {
2189
+ result = [ val[0] ]
2190
+ }
2191
+ | f_kwarg tCOMMA f_kw
2192
+ {
2193
+ result = val[0] << val[2]
2194
+ }
2195
+
2196
+ kwrest_mark: tPOW | tDSTAR
2197
+
2198
+ f_kwrest: kwrest_mark tIDENTIFIER
2199
+ {
2200
+ @static_env.declare val[1][0]
2201
+
2202
+ result = [ @builder.kwrestarg(val[0], val[1]) ]
2203
+ }
2204
+ | kwrest_mark
2205
+ {
2206
+ result = [ @builder.kwrestarg(val[0]) ]
2207
+ }
2208
+
2209
+ f_opt: tIDENTIFIER tEQL arg_value
2210
+ {
2211
+ @static_env.declare val[0][0]
2212
+
2213
+ result = @builder.optarg(val[0], val[1], val[2])
2214
+ }
2215
+
2216
+ f_block_opt: tIDENTIFIER tEQL primary_value
2217
+ {
2218
+ @static_env.declare val[0][0]
2219
+
2220
+ result = @builder.optarg(val[0], val[1], val[2])
2221
+ }
2222
+
2223
+ f_block_optarg: f_block_opt
2224
+ {
2225
+ result = [ val[0] ]
2226
+ }
2227
+ | f_block_optarg tCOMMA f_block_opt
2228
+ {
2229
+ result = val[0] << val[2]
2230
+ }
2231
+
2232
+ f_optarg: f_opt
2233
+ {
2234
+ result = [ val[0] ]
2235
+ }
2236
+ | f_optarg tCOMMA f_opt
2237
+ {
2238
+ result = val[0] << val[2]
2239
+ }
2240
+
2241
+ restarg_mark: tSTAR2 | tSTAR
2242
+
2243
+ f_rest_arg: restarg_mark tIDENTIFIER
2244
+ {
2245
+ @static_env.declare val[1][0]
2246
+
2247
+ result = [ @builder.restarg(val[0], val[1]) ]
2248
+ }
2249
+ | restarg_mark
2250
+ {
2251
+ result = [ @builder.restarg(val[0]) ]
2252
+ }
2253
+
2254
+ blkarg_mark: tAMPER2 | tAMPER
2255
+
2256
+ f_block_arg: blkarg_mark tIDENTIFIER
2257
+ {
2258
+ @static_env.declare val[1][0]
2259
+
2260
+ result = @builder.blockarg(val[0], val[1])
2261
+ }
2262
+
2263
+ opt_f_block_arg: tCOMMA f_block_arg
2264
+ {
2265
+ result = [ val[1] ]
2266
+ }
2267
+ |
2268
+ {
2269
+ result = []
2270
+ }
2271
+
2272
+ singleton: var_ref
2273
+ | tLPAREN2 expr rparen
2274
+ {
2275
+ result = val[1]
2276
+ }
2277
+
2278
+ assoc_list: # nothing
2279
+ {
2280
+ result = []
2281
+ }
2282
+ | assocs trailer
2283
+
2284
+ assocs: assoc
2285
+ {
2286
+ result = [ val[0] ]
2287
+ }
2288
+ | assocs tCOMMA assoc
2289
+ {
2290
+ result = val[0] << val[2]
2291
+ }
2292
+
2293
+ assoc: arg_value tASSOC arg_value
2294
+ {
2295
+ result = @builder.pair(val[0], val[1], val[2])
2296
+ }
2297
+ | tLABEL arg_value
2298
+ {
2299
+ # TODO: Extract colon
2300
+ key = @builder.symbol(val[0])
2301
+ result = @builder.pair(key, nil, val[1])
2302
+ }
2303
+ | tDSTAR arg_value
2304
+ {
2305
+ result = @builder.kwsplat(val[0], val[1])
2306
+ }
2307
+
2308
+ operation: tIDENTIFIER | tCONSTANT | tFID
2309
+ operation2: tIDENTIFIER | tCONSTANT | tFID | op
2310
+ operation3: tIDENTIFIER | tFID | op
2311
+ dot_or_colon: tDOT | tCOLON2
2312
+ opt_terms: | terms
2313
+ opt_nl: | tNL
2314
+ rparen: opt_nl tRPAREN
2315
+ {
2316
+ result = val[1]
2317
+ }
2318
+ rbracket: opt_nl tRBRACK
2319
+ {
2320
+ result = val[1]
2321
+ }
2322
+ trailer: | tNL | tCOMMA
2323
+
2324
+ term: tSEMI
2325
+ {
2326
+ yyerrok
2327
+ }
2328
+ | tNL
2329
+
2330
+ terms: term
2331
+ | terms tSEMI
2332
+
2333
+ none: # nothing
2334
+ {
2335
+ result = nil
2336
+ }
2337
+ end
2338
+
2339
+ ---- header
2340
+
2341
+ require 'parser'
2342
+
2343
+ Parser.check_for_encoding_support
2344
+
2345
+ warn "warning: you are loading parser/ruby21 from #{caller[0]}."
2346
+ warn "warning: Ruby 2.1 is not released yet and parser support may be incomplete."
2347
+
2348
+ ---- inner
2349
+
2350
+ def version
2351
+ 21
2352
+ end