ruby-next-parser 2.8.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2948 @@
1
+ class Parser::RubyNext
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
+ tUPLUS tUMINUS tUNARY_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 tCHARACTER
20
+ tRATIONAL tIMAGINARY tLABEL_END tANDDOT tMETHREF tBDOT2 tBDOT3
21
+
22
+ prechigh
23
+ right tBANG tTILDE tUPLUS
24
+ right tPOW
25
+ right tUNARY_NUM tUMINUS
26
+ left tSTAR2 tDIVIDE tPERCENT
27
+ left tPLUS tMINUS
28
+ left tLSHFT tRSHFT
29
+ left tAMPER2
30
+ left tPIPE tCARET
31
+ left tGT tGEQ tLT tLEQ
32
+ nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
33
+ left tANDOP
34
+ left tOROP
35
+ nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
36
+ right tEH tCOLON
37
+ left kRESCUE_MOD
38
+ right tEQL tOP_ASGN
39
+ nonassoc kDEFINED
40
+ right kNOT
41
+ left kOR kAND
42
+ nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD kIN
43
+ nonassoc tLBRACE_ARG
44
+ nonassoc tLOWEST
45
+ preclow
46
+
47
+ rule
48
+
49
+ program: top_compstmt
50
+
51
+ top_compstmt: top_stmts opt_terms
52
+ {
53
+ result = @builder.compstmt(val[0])
54
+ }
55
+
56
+ top_stmts: # nothing
57
+ {
58
+ result = []
59
+ }
60
+ | top_stmt
61
+ {
62
+ result = [ val[0] ]
63
+ }
64
+ | top_stmts terms top_stmt
65
+ {
66
+ result = val[0] << val[2]
67
+ }
68
+ | error top_stmt
69
+ {
70
+ result = [ val[1] ]
71
+ }
72
+
73
+ top_stmt: stmt
74
+ | klBEGIN begin_block
75
+ {
76
+ result = @builder.preexe(val[0], *val[1])
77
+ }
78
+
79
+ begin_block: tLCURLY top_compstmt tRCURLY
80
+ {
81
+ result = val
82
+ }
83
+
84
+ bodystmt: compstmt opt_rescue opt_else opt_ensure
85
+ {
86
+ rescue_bodies = val[1]
87
+ else_t, else_ = val[2]
88
+ ensure_t, ensure_ = val[3]
89
+
90
+ if rescue_bodies.empty? && !else_t.nil?
91
+ diagnostic :error, :useless_else, nil, else_t
92
+ end
93
+
94
+ result = @builder.begin_body(val[0],
95
+ rescue_bodies,
96
+ else_t, else_,
97
+ ensure_t, ensure_)
98
+ }
99
+
100
+ compstmt: stmts opt_terms
101
+ {
102
+ result = @builder.compstmt(val[0])
103
+ }
104
+
105
+ stmts: # nothing
106
+ {
107
+ result = []
108
+ }
109
+ | stmt_or_begin
110
+ {
111
+ result = [ val[0] ]
112
+ }
113
+ | stmts terms stmt_or_begin
114
+ {
115
+ result = val[0] << val[2]
116
+ }
117
+ | error stmt
118
+ {
119
+ result = [ val[1] ]
120
+ }
121
+
122
+ stmt_or_begin: stmt
123
+ | klBEGIN begin_block
124
+ {
125
+ diagnostic :error, :begin_in_method, nil, val[0]
126
+ }
127
+
128
+ stmt: kALIAS fitem
129
+ {
130
+ @lexer.state = :expr_fname
131
+ }
132
+ fitem
133
+ {
134
+ result = @builder.alias(val[0], val[1], val[3])
135
+ }
136
+ | kALIAS tGVAR tGVAR
137
+ {
138
+ result = @builder.alias(val[0],
139
+ @builder.gvar(val[1]),
140
+ @builder.gvar(val[2]))
141
+ }
142
+ | kALIAS tGVAR tBACK_REF
143
+ {
144
+ result = @builder.alias(val[0],
145
+ @builder.gvar(val[1]),
146
+ @builder.back_ref(val[2]))
147
+ }
148
+ | kALIAS tGVAR tNTH_REF
149
+ {
150
+ diagnostic :error, :nth_ref_alias, nil, val[2]
151
+ }
152
+ | kUNDEF undef_list
153
+ {
154
+ result = @builder.undef_method(val[0], val[1])
155
+ }
156
+ | stmt kIF_MOD expr_value
157
+ {
158
+ result = @builder.condition_mod(val[0], nil,
159
+ val[1], val[2])
160
+ }
161
+ | stmt kUNLESS_MOD expr_value
162
+ {
163
+ result = @builder.condition_mod(nil, val[0],
164
+ val[1], val[2])
165
+ }
166
+ | stmt kWHILE_MOD expr_value
167
+ {
168
+ result = @builder.loop_mod(:while, val[0], val[1], val[2])
169
+ }
170
+ | stmt kUNTIL_MOD expr_value
171
+ {
172
+ result = @builder.loop_mod(:until, val[0], val[1], val[2])
173
+ }
174
+ | stmt kRESCUE_MOD stmt
175
+ {
176
+ rescue_body = @builder.rescue_body(val[1],
177
+ nil, nil, nil,
178
+ nil, val[2])
179
+
180
+ result = @builder.begin_body(val[0], [ rescue_body ])
181
+ }
182
+ | klEND tLCURLY compstmt tRCURLY
183
+ {
184
+ result = @builder.postexe(val[0], val[1], val[2], val[3])
185
+ }
186
+ | command_asgn
187
+ | mlhs tEQL command_call
188
+ {
189
+ result = @builder.multi_assign(val[0], val[1], val[2])
190
+ }
191
+ | lhs tEQL mrhs
192
+ {
193
+ result = @builder.assign(val[0], val[1],
194
+ @builder.array(nil, val[2], nil))
195
+ }
196
+ | mlhs tEQL mrhs_arg kRESCUE_MOD stmt
197
+ {
198
+ rescue_body = @builder.rescue_body(val[3],
199
+ nil, nil, nil,
200
+ nil, val[4])
201
+ begin_body = @builder.begin_body(val[2], [ rescue_body ])
202
+
203
+ result = @builder.multi_assign(val[0], val[1], begin_body)
204
+ }
205
+ | mlhs tEQL mrhs_arg
206
+ {
207
+ result = @builder.multi_assign(val[0], val[1], val[2])
208
+ }
209
+ | expr
210
+
211
+ command_asgn: lhs tEQL command_rhs
212
+ {
213
+ result = @builder.assign(val[0], val[1], val[2])
214
+ }
215
+ | var_lhs tOP_ASGN command_rhs
216
+ {
217
+ result = @builder.op_assign(val[0], val[1], val[2])
218
+ }
219
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
220
+ {
221
+ result = @builder.op_assign(
222
+ @builder.index(
223
+ val[0], val[1], val[2], val[3]),
224
+ val[4], val[5])
225
+ }
226
+ | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
227
+ {
228
+ result = @builder.op_assign(
229
+ @builder.call_method(
230
+ val[0], val[1], val[2]),
231
+ val[3], val[4])
232
+ }
233
+ | primary_value call_op tCONSTANT tOP_ASGN command_rhs
234
+ {
235
+ result = @builder.op_assign(
236
+ @builder.call_method(
237
+ val[0], val[1], val[2]),
238
+ val[3], val[4])
239
+ }
240
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
241
+ {
242
+ const = @builder.const_op_assignable(
243
+ @builder.const_fetch(val[0], val[1], val[2]))
244
+ result = @builder.op_assign(const, val[3], val[4])
245
+ }
246
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
247
+ {
248
+ result = @builder.op_assign(
249
+ @builder.call_method(
250
+ val[0], val[1], val[2]),
251
+ val[3], val[4])
252
+ }
253
+ | backref tOP_ASGN command_rhs
254
+ {
255
+ @builder.op_assign(val[0], val[1], val[2])
256
+ }
257
+
258
+ command_rhs: command_call =tOP_ASGN
259
+ | command_call kRESCUE_MOD stmt
260
+ {
261
+ rescue_body = @builder.rescue_body(val[1],
262
+ nil, nil, nil,
263
+ nil, val[2])
264
+
265
+ result = @builder.begin_body(val[0], [ rescue_body ])
266
+ }
267
+ | command_asgn
268
+
269
+ expr: command_call
270
+ | expr kAND expr
271
+ {
272
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
273
+ }
274
+ | expr kOR expr
275
+ {
276
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
277
+ }
278
+ | kNOT opt_nl expr
279
+ {
280
+ result = @builder.not_op(val[0], nil, val[2], nil)
281
+ }
282
+ | tBANG command_call
283
+ {
284
+ result = @builder.not_op(val[0], nil, val[1], nil)
285
+ }
286
+ | arg kIN
287
+ {
288
+ @lexer.state = :expr_beg
289
+ @lexer.command_start = false
290
+ pattern_variables.push
291
+
292
+ result = @lexer.in_kwarg
293
+ @lexer.in_kwarg = true
294
+ }
295
+ p_expr
296
+ {
297
+ @lexer.in_kwarg = val[2]
298
+ result = @builder.in_match(val[0], val[1], val[3])
299
+ }
300
+ | arg =tLBRACE_ARG
301
+
302
+ expr_value: expr
303
+
304
+ expr_value_do: {
305
+ @lexer.cond.push(true)
306
+ }
307
+ expr_value do
308
+ {
309
+ @lexer.cond.pop
310
+ result = [ val[1], val[2] ]
311
+ }
312
+
313
+ command_call: command
314
+ | block_command
315
+
316
+ block_command: block_call
317
+ | block_call dot_or_colon operation2 command_args
318
+ {
319
+ result = @builder.call_method(val[0], val[1], val[2],
320
+ nil, val[3], nil)
321
+ }
322
+
323
+ cmd_brace_block: tLBRACE_ARG
324
+ {
325
+ @context.push(:block)
326
+ }
327
+ brace_body tRCURLY
328
+ {
329
+ result = [ val[0], *val[2], val[3] ]
330
+ @context.pop
331
+ }
332
+
333
+ fcall: operation
334
+
335
+ command: fcall command_args =tLOWEST
336
+ {
337
+ result = @builder.call_method(nil, nil, val[0],
338
+ nil, val[1], nil)
339
+ }
340
+ | fcall command_args cmd_brace_block
341
+ {
342
+ method_call = @builder.call_method(nil, nil, val[0],
343
+ nil, val[1], nil)
344
+
345
+ begin_t, args, body, end_t = val[2]
346
+ result = @builder.block(method_call,
347
+ begin_t, args, body, end_t)
348
+ }
349
+ | primary_value call_op operation2 command_args =tLOWEST
350
+ {
351
+ result = @builder.call_method(val[0], val[1], val[2],
352
+ nil, val[3], nil)
353
+ }
354
+ | primary_value call_op operation2 command_args cmd_brace_block
355
+ {
356
+ method_call = @builder.call_method(val[0], val[1], val[2],
357
+ nil, val[3], nil)
358
+
359
+ begin_t, args, body, end_t = val[4]
360
+ result = @builder.block(method_call,
361
+ begin_t, args, body, end_t)
362
+ }
363
+ | primary_value tCOLON2 operation2 command_args =tLOWEST
364
+ {
365
+ result = @builder.call_method(val[0], val[1], val[2],
366
+ nil, val[3], nil)
367
+ }
368
+ | primary_value tCOLON2 operation2 command_args cmd_brace_block
369
+ {
370
+ method_call = @builder.call_method(val[0], val[1], val[2],
371
+ nil, val[3], nil)
372
+
373
+ begin_t, args, body, end_t = val[4]
374
+ result = @builder.block(method_call,
375
+ begin_t, args, body, end_t)
376
+ }
377
+ | kSUPER command_args
378
+ {
379
+ result = @builder.keyword_cmd(:super, val[0],
380
+ nil, val[1], nil)
381
+ }
382
+ | kYIELD command_args
383
+ {
384
+ result = @builder.keyword_cmd(:yield, val[0],
385
+ nil, val[1], nil)
386
+ }
387
+ | k_return call_args
388
+ {
389
+ result = @builder.keyword_cmd(:return, val[0],
390
+ nil, val[1], nil)
391
+ }
392
+ | kBREAK call_args
393
+ {
394
+ result = @builder.keyword_cmd(:break, val[0],
395
+ nil, val[1], nil)
396
+ }
397
+ | kNEXT call_args
398
+ {
399
+ result = @builder.keyword_cmd(:next, val[0],
400
+ nil, val[1], nil)
401
+ }
402
+
403
+ mlhs: mlhs_basic
404
+ {
405
+ result = @builder.multi_lhs(nil, val[0], nil)
406
+ }
407
+ | tLPAREN mlhs_inner rparen
408
+ {
409
+ result = @builder.begin(val[0], val[1], val[2])
410
+ }
411
+
412
+ mlhs_inner: mlhs_basic
413
+ {
414
+ result = @builder.multi_lhs(nil, val[0], nil)
415
+ }
416
+ | tLPAREN mlhs_inner rparen
417
+ {
418
+ result = @builder.multi_lhs(val[0], val[1], val[2])
419
+ }
420
+
421
+ mlhs_basic: mlhs_head
422
+ | mlhs_head mlhs_item
423
+ {
424
+ result = val[0].
425
+ push(val[1])
426
+ }
427
+ | mlhs_head tSTAR mlhs_node
428
+ {
429
+ result = val[0].
430
+ push(@builder.splat(val[1], val[2]))
431
+ }
432
+ | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
433
+ {
434
+ result = val[0].
435
+ push(@builder.splat(val[1], val[2])).
436
+ concat(val[4])
437
+ }
438
+ | mlhs_head tSTAR
439
+ {
440
+ result = val[0].
441
+ push(@builder.splat(val[1]))
442
+ }
443
+ | mlhs_head tSTAR tCOMMA mlhs_post
444
+ {
445
+ result = val[0].
446
+ push(@builder.splat(val[1])).
447
+ concat(val[3])
448
+ }
449
+ | tSTAR mlhs_node
450
+ {
451
+ result = [ @builder.splat(val[0], val[1]) ]
452
+ }
453
+ | tSTAR mlhs_node tCOMMA mlhs_post
454
+ {
455
+ result = [ @builder.splat(val[0], val[1]),
456
+ *val[3] ]
457
+ }
458
+ | tSTAR
459
+ {
460
+ result = [ @builder.splat(val[0]) ]
461
+ }
462
+ | tSTAR tCOMMA mlhs_post
463
+ {
464
+ result = [ @builder.splat(val[0]),
465
+ *val[2] ]
466
+ }
467
+
468
+ mlhs_item: mlhs_node
469
+ | tLPAREN mlhs_inner rparen
470
+ {
471
+ result = @builder.begin(val[0], val[1], val[2])
472
+ }
473
+
474
+ mlhs_head: mlhs_item tCOMMA
475
+ {
476
+ result = [ val[0] ]
477
+ }
478
+ | mlhs_head mlhs_item tCOMMA
479
+ {
480
+ result = val[0] << val[1]
481
+ }
482
+
483
+ mlhs_post: mlhs_item
484
+ {
485
+ result = [ val[0] ]
486
+ }
487
+ | mlhs_post tCOMMA mlhs_item
488
+ {
489
+ result = val[0] << val[2]
490
+ }
491
+
492
+ mlhs_node: user_variable
493
+ {
494
+ result = @builder.assignable(val[0])
495
+ }
496
+ | keyword_variable
497
+ {
498
+ result = @builder.assignable(val[0])
499
+ }
500
+ | primary_value tLBRACK2 opt_call_args rbracket
501
+ {
502
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
503
+ }
504
+ | primary_value call_op tIDENTIFIER
505
+ {
506
+ if (val[1][0] == :anddot)
507
+ diagnostic :error, :csend_in_lhs_of_masgn, nil, val[1]
508
+ end
509
+
510
+ result = @builder.attr_asgn(val[0], val[1], val[2])
511
+ }
512
+ | primary_value tCOLON2 tIDENTIFIER
513
+ {
514
+ result = @builder.attr_asgn(val[0], val[1], val[2])
515
+ }
516
+ | primary_value call_op tCONSTANT
517
+ {
518
+ if (val[1][0] == :anddot)
519
+ diagnostic :error, :csend_in_lhs_of_masgn, nil, val[1]
520
+ end
521
+
522
+ result = @builder.attr_asgn(val[0], val[1], val[2])
523
+ }
524
+ | primary_value tCOLON2 tCONSTANT
525
+ {
526
+ result = @builder.assignable(
527
+ @builder.const_fetch(val[0], val[1], val[2]))
528
+ }
529
+ | tCOLON3 tCONSTANT
530
+ {
531
+ result = @builder.assignable(
532
+ @builder.const_global(val[0], val[1]))
533
+ }
534
+ | backref
535
+ {
536
+ result = @builder.assignable(val[0])
537
+ }
538
+
539
+ lhs: user_variable
540
+ {
541
+ result = @builder.assignable(val[0])
542
+ }
543
+ | keyword_variable
544
+ {
545
+ result = @builder.assignable(val[0])
546
+ }
547
+ | primary_value tLBRACK2 opt_call_args rbracket
548
+ {
549
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
550
+ }
551
+ | primary_value call_op tIDENTIFIER
552
+ {
553
+ result = @builder.attr_asgn(val[0], val[1], val[2])
554
+ }
555
+ | primary_value tCOLON2 tIDENTIFIER
556
+ {
557
+ result = @builder.attr_asgn(val[0], val[1], val[2])
558
+ }
559
+ | primary_value call_op tCONSTANT
560
+ {
561
+ result = @builder.attr_asgn(val[0], val[1], val[2])
562
+ }
563
+ | primary_value tCOLON2 tCONSTANT
564
+ {
565
+ result = @builder.assignable(
566
+ @builder.const_fetch(val[0], val[1], val[2]))
567
+ }
568
+ | tCOLON3 tCONSTANT
569
+ {
570
+ result = @builder.assignable(
571
+ @builder.const_global(val[0], val[1]))
572
+ }
573
+ | backref
574
+ {
575
+ result = @builder.assignable(val[0])
576
+ }
577
+
578
+ cname: tIDENTIFIER
579
+ {
580
+ diagnostic :error, :module_name_const, nil, val[0]
581
+ }
582
+ | tCONSTANT
583
+
584
+ cpath: tCOLON3 cname
585
+ {
586
+ result = @builder.const_global(val[0], val[1])
587
+ }
588
+ | cname
589
+ {
590
+ result = @builder.const(val[0])
591
+ }
592
+ | primary_value tCOLON2 cname
593
+ {
594
+ result = @builder.const_fetch(val[0], val[1], val[2])
595
+ }
596
+
597
+ fname: tIDENTIFIER | tCONSTANT | tFID
598
+ | op
599
+ | reswords
600
+
601
+ fitem: fname
602
+ {
603
+ result = @builder.symbol(val[0])
604
+ }
605
+ | symbol
606
+
607
+ undef_list: fitem
608
+ {
609
+ result = [ val[0] ]
610
+ }
611
+ | undef_list tCOMMA
612
+ {
613
+ @lexer.state = :expr_fname
614
+ }
615
+ fitem
616
+ {
617
+ result = val[0] << val[3]
618
+ }
619
+
620
+ op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
621
+ | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
622
+ | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
623
+ | tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
624
+ | tUPLUS | tUMINUS | tAREF | tASET | tDSTAR | tBACK_REF2
625
+
626
+ reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
627
+ | kALIAS | kAND | kBEGIN | kBREAK | kCASE
628
+ | kCLASS | kDEF | kDEFINED | kDO | kELSE
629
+ | kELSIF | kEND | kENSURE | kFALSE | kFOR
630
+ | kIN | kMODULE | kNEXT | kNIL | kNOT
631
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN
632
+ | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
633
+ | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
634
+ | kUNTIL
635
+
636
+ arg: lhs tEQL arg_rhs
637
+ {
638
+ result = @builder.assign(val[0], val[1], val[2])
639
+ }
640
+ | var_lhs tOP_ASGN arg_rhs
641
+ {
642
+ result = @builder.op_assign(val[0], val[1], val[2])
643
+ }
644
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
645
+ {
646
+ result = @builder.op_assign(
647
+ @builder.index(
648
+ val[0], val[1], val[2], val[3]),
649
+ val[4], val[5])
650
+ }
651
+ | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
652
+ {
653
+ result = @builder.op_assign(
654
+ @builder.call_method(
655
+ val[0], val[1], val[2]),
656
+ val[3], val[4])
657
+ }
658
+ | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
659
+ {
660
+ result = @builder.op_assign(
661
+ @builder.call_method(
662
+ val[0], val[1], val[2]),
663
+ val[3], val[4])
664
+ }
665
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
666
+ {
667
+ result = @builder.op_assign(
668
+ @builder.call_method(
669
+ val[0], val[1], val[2]),
670
+ val[3], val[4])
671
+ }
672
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
673
+ {
674
+ const = @builder.const_op_assignable(
675
+ @builder.const_fetch(val[0], val[1], val[2]))
676
+ result = @builder.op_assign(const, val[3], val[4])
677
+ }
678
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
679
+ {
680
+ const = @builder.const_op_assignable(
681
+ @builder.const_global(val[0], val[1]))
682
+ result = @builder.op_assign(const, val[2], val[3])
683
+ }
684
+ | backref tOP_ASGN arg_rhs
685
+ {
686
+ result = @builder.op_assign(val[0], val[1], val[2])
687
+ }
688
+ | arg tDOT2 arg
689
+ {
690
+ result = @builder.range_inclusive(val[0], val[1], val[2])
691
+ }
692
+ | arg tDOT3 arg
693
+ {
694
+ result = @builder.range_exclusive(val[0], val[1], val[2])
695
+ }
696
+ | arg tDOT2
697
+ {
698
+ result = @builder.range_inclusive(val[0], val[1], nil)
699
+ }
700
+ | arg tDOT3
701
+ {
702
+ result = @builder.range_exclusive(val[0], val[1], nil)
703
+ }
704
+ | tBDOT2 arg
705
+ {
706
+ result = @builder.range_inclusive(nil, val[0], val[1])
707
+ }
708
+ | tBDOT3 arg
709
+ {
710
+ result = @builder.range_exclusive(nil, val[0], val[1])
711
+ }
712
+ | arg tPLUS arg
713
+ {
714
+ result = @builder.binary_op(val[0], val[1], val[2])
715
+ }
716
+ | arg tMINUS arg
717
+ {
718
+ result = @builder.binary_op(val[0], val[1], val[2])
719
+ }
720
+ | arg tSTAR2 arg
721
+ {
722
+ result = @builder.binary_op(val[0], val[1], val[2])
723
+ }
724
+ | arg tDIVIDE arg
725
+ {
726
+ result = @builder.binary_op(val[0], val[1], val[2])
727
+ }
728
+ | arg tPERCENT arg
729
+ {
730
+ result = @builder.binary_op(val[0], val[1], val[2])
731
+ }
732
+ | arg tPOW arg
733
+ {
734
+ result = @builder.binary_op(val[0], val[1], val[2])
735
+ }
736
+ | tUNARY_NUM simple_numeric tPOW arg
737
+ {
738
+ result = @builder.unary_op(val[0],
739
+ @builder.binary_op(
740
+ val[1], val[2], val[3]))
741
+ }
742
+ | tUPLUS arg
743
+ {
744
+ result = @builder.unary_op(val[0], val[1])
745
+ }
746
+ | tUMINUS arg
747
+ {
748
+ result = @builder.unary_op(val[0], val[1])
749
+ }
750
+ | arg tPIPE arg
751
+ {
752
+ result = @builder.binary_op(val[0], val[1], val[2])
753
+ }
754
+ | arg tCARET arg
755
+ {
756
+ result = @builder.binary_op(val[0], val[1], val[2])
757
+ }
758
+ | arg tAMPER2 arg
759
+ {
760
+ result = @builder.binary_op(val[0], val[1], val[2])
761
+ }
762
+ | arg tCMP arg
763
+ {
764
+ result = @builder.binary_op(val[0], val[1], val[2])
765
+ }
766
+ | rel_expr =tCMP
767
+ | arg tEQ arg
768
+ {
769
+ result = @builder.binary_op(val[0], val[1], val[2])
770
+ }
771
+ | arg tEQQ arg
772
+ {
773
+ result = @builder.binary_op(val[0], val[1], val[2])
774
+ }
775
+ | arg tNEQ arg
776
+ {
777
+ result = @builder.binary_op(val[0], val[1], val[2])
778
+ }
779
+ | arg tMATCH arg
780
+ {
781
+ result = @builder.match_op(val[0], val[1], val[2])
782
+ }
783
+ | arg tNMATCH arg
784
+ {
785
+ result = @builder.binary_op(val[0], val[1], val[2])
786
+ }
787
+ | tBANG arg
788
+ {
789
+ result = @builder.not_op(val[0], nil, val[1], nil)
790
+ }
791
+ | tTILDE arg
792
+ {
793
+ result = @builder.unary_op(val[0], val[1])
794
+ }
795
+ | arg tLSHFT arg
796
+ {
797
+ result = @builder.binary_op(val[0], val[1], val[2])
798
+ }
799
+ | arg tRSHFT arg
800
+ {
801
+ result = @builder.binary_op(val[0], val[1], val[2])
802
+ }
803
+ | arg tANDOP arg
804
+ {
805
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
806
+ }
807
+ | arg tOROP arg
808
+ {
809
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
810
+ }
811
+ | kDEFINED opt_nl arg
812
+ {
813
+ result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
814
+ }
815
+ | arg tEH arg opt_nl tCOLON arg
816
+ {
817
+ result = @builder.ternary(val[0], val[1],
818
+ val[2], val[4], val[5])
819
+ }
820
+ | primary
821
+
822
+ relop: tGT | tLT | tGEQ | tLEQ
823
+
824
+ rel_expr: arg relop arg =tGT
825
+ {
826
+ result = @builder.binary_op(val[0], val[1], val[2])
827
+ }
828
+ | rel_expr relop arg =tGT
829
+ {
830
+ result = @builder.binary_op(val[0], val[1], val[2])
831
+ }
832
+
833
+ arg_value: arg
834
+
835
+ aref_args: none
836
+ | args trailer
837
+ | args tCOMMA assocs trailer
838
+ {
839
+ result = val[0] << @builder.associate(nil, val[2], nil)
840
+ }
841
+ | assocs trailer
842
+ {
843
+ result = [ @builder.associate(nil, val[0], nil) ]
844
+ }
845
+
846
+ arg_rhs: arg =tOP_ASGN
847
+ | arg kRESCUE_MOD arg
848
+ {
849
+ rescue_body = @builder.rescue_body(val[1],
850
+ nil, nil, nil,
851
+ nil, val[2])
852
+
853
+ result = @builder.begin_body(val[0], [ rescue_body ])
854
+ }
855
+
856
+ paren_args: tLPAREN2 opt_call_args rparen
857
+ {
858
+ result = val
859
+ }
860
+ | tLPAREN2 args_forward rparen
861
+ {
862
+ unless @static_env.declared_forward_args?
863
+ diagnostic :error, :unexpected_token, { :token => 'tBDOT3' } , val[1]
864
+ end
865
+
866
+ result = [val[0], [@builder.forwarded_args(val[1])], val[2]]
867
+ }
868
+
869
+ opt_paren_args: # nothing
870
+ {
871
+ result = [ nil, [], nil ]
872
+ }
873
+ | paren_args
874
+
875
+ opt_call_args: # nothing
876
+ {
877
+ result = []
878
+ }
879
+ | call_args
880
+ | args tCOMMA
881
+ | args tCOMMA assocs tCOMMA
882
+ {
883
+ result = val[0] << @builder.associate(nil, val[2], nil)
884
+ }
885
+ | assocs tCOMMA
886
+ {
887
+ result = [ @builder.associate(nil, val[0], nil) ]
888
+ }
889
+
890
+ call_args: command
891
+ {
892
+ result = [ val[0] ]
893
+ }
894
+ | args opt_block_arg
895
+ {
896
+ result = val[0].concat(val[1])
897
+ }
898
+ | assocs opt_block_arg
899
+ {
900
+ result = [ @builder.associate(nil, val[0], nil) ]
901
+ result.concat(val[1])
902
+ }
903
+ | args tCOMMA assocs opt_block_arg
904
+ {
905
+ assocs = @builder.associate(nil, val[2], nil)
906
+ result = val[0] << assocs
907
+ result.concat(val[3])
908
+ }
909
+ | block_arg
910
+ {
911
+ result = [ val[0] ]
912
+ }
913
+
914
+ command_args: {
915
+ # When branch gets invoked by RACC's lookahead
916
+ # and command args start with '[' or '('
917
+ # we need to put `true` to the cmdarg stack
918
+ # **before** `false` pushed by lexer
919
+ # m [], n
920
+ # ^
921
+ # Right here we have cmdarg [...0] because
922
+ # lexer pushed it on '['
923
+ # We need to modify cmdarg stack to [...10]
924
+ #
925
+ # For all other cases (like `m n` or `m n, []`) we simply put 1 to the stack
926
+ # and later lexer pushes corresponding bits on top of it.
927
+ last_token = @last_token[0]
928
+ lookahead = last_token == :tLBRACK || last_token == :tLPAREN_ARG
929
+
930
+ if lookahead
931
+ top = @lexer.cmdarg.pop
932
+ @lexer.cmdarg.push(true)
933
+ @lexer.cmdarg.push(top)
934
+ else
935
+ @lexer.cmdarg.push(true)
936
+ end
937
+ }
938
+ call_args
939
+ {
940
+ # call_args can be followed by tLBRACE_ARG (that does cmdarg.push(0) in the lexer)
941
+ # but the push must be done after cmdarg.pop() in the parser.
942
+ # So this code does cmdarg.pop() to pop 0 pushed by tLBRACE_ARG,
943
+ # cmdarg.pop() to pop 1 pushed by command_args,
944
+ # and cmdarg.push(0) to restore back the flag set by tLBRACE_ARG.
945
+ last_token = @last_token[0]
946
+ lookahead = last_token == :tLBRACE_ARG
947
+ if lookahead
948
+ top = @lexer.cmdarg.pop
949
+ @lexer.cmdarg.pop
950
+ @lexer.cmdarg.push(top)
951
+ else
952
+ @lexer.cmdarg.pop
953
+ end
954
+
955
+ result = val[1]
956
+ }
957
+
958
+ block_arg: tAMPER arg_value
959
+ {
960
+ result = @builder.block_pass(val[0], val[1])
961
+ }
962
+
963
+ opt_block_arg: tCOMMA block_arg
964
+ {
965
+ result = [ val[1] ]
966
+ }
967
+ | # nothing
968
+ {
969
+ result = []
970
+ }
971
+
972
+ args: arg_value
973
+ {
974
+ result = [ val[0] ]
975
+ }
976
+ | tSTAR arg_value
977
+ {
978
+ result = [ @builder.splat(val[0], val[1]) ]
979
+ }
980
+ | args tCOMMA arg_value
981
+ {
982
+ result = val[0] << val[2]
983
+ }
984
+ | args tCOMMA tSTAR arg_value
985
+ {
986
+ result = val[0] << @builder.splat(val[2], val[3])
987
+ }
988
+
989
+ mrhs_arg: mrhs
990
+ {
991
+ result = @builder.array(nil, val[0], nil)
992
+ }
993
+ | arg_value
994
+
995
+ mrhs: args tCOMMA arg_value
996
+ {
997
+ result = val[0] << val[2]
998
+ }
999
+ | args tCOMMA tSTAR arg_value
1000
+ {
1001
+ result = val[0] << @builder.splat(val[2], val[3])
1002
+ }
1003
+ | tSTAR arg_value
1004
+ {
1005
+ result = [ @builder.splat(val[0], val[1]) ]
1006
+ }
1007
+
1008
+ primary: literal
1009
+ | strings
1010
+ | xstring
1011
+ | regexp
1012
+ | words
1013
+ | qwords
1014
+ | symbols
1015
+ | qsymbols
1016
+ | var_ref
1017
+ | backref
1018
+ | tFID
1019
+ {
1020
+ result = @builder.call_method(nil, nil, val[0])
1021
+ }
1022
+ | kBEGIN
1023
+ {
1024
+ @lexer.cmdarg.push(false)
1025
+ }
1026
+ bodystmt kEND
1027
+ {
1028
+ @lexer.cmdarg.pop
1029
+
1030
+ result = @builder.begin_keyword(val[0], val[2], val[3])
1031
+ }
1032
+ | tLPAREN_ARG stmt
1033
+ {
1034
+ @lexer.state = :expr_endarg
1035
+ }
1036
+ rparen
1037
+ {
1038
+ result = @builder.begin(val[0], val[1], val[3])
1039
+ }
1040
+ | tLPAREN_ARG
1041
+ {
1042
+ @lexer.state = :expr_endarg
1043
+ }
1044
+ opt_nl tRPAREN
1045
+ {
1046
+ result = @builder.begin(val[0], nil, val[3])
1047
+ }
1048
+ | tLPAREN compstmt tRPAREN
1049
+ {
1050
+ result = @builder.begin(val[0], val[1], val[2])
1051
+ }
1052
+ | primary_value tCOLON2 tCONSTANT
1053
+ {
1054
+ result = @builder.const_fetch(val[0], val[1], val[2])
1055
+ }
1056
+ | tCOLON3 tCONSTANT
1057
+ {
1058
+ result = @builder.const_global(val[0], val[1])
1059
+ }
1060
+ | tLBRACK aref_args tRBRACK
1061
+ {
1062
+ result = @builder.array(val[0], val[1], val[2])
1063
+ }
1064
+ | tLBRACE assoc_list tRCURLY
1065
+ {
1066
+ result = @builder.associate(val[0], val[1], val[2])
1067
+ }
1068
+ | k_return
1069
+ {
1070
+ result = @builder.keyword_cmd(:return, val[0])
1071
+ }
1072
+ | kYIELD tLPAREN2 call_args rparen
1073
+ {
1074
+ result = @builder.keyword_cmd(:yield, val[0], val[1], val[2], val[3])
1075
+ }
1076
+ | kYIELD tLPAREN2 rparen
1077
+ {
1078
+ result = @builder.keyword_cmd(:yield, val[0], val[1], [], val[2])
1079
+ }
1080
+ | kYIELD
1081
+ {
1082
+ result = @builder.keyword_cmd(:yield, val[0])
1083
+ }
1084
+ | kDEFINED opt_nl tLPAREN2 expr rparen
1085
+ {
1086
+ result = @builder.keyword_cmd(:defined?, val[0],
1087
+ val[2], [ val[3] ], val[4])
1088
+ }
1089
+ | kNOT tLPAREN2 expr rparen
1090
+ {
1091
+ result = @builder.not_op(val[0], val[1], val[2], val[3])
1092
+ }
1093
+ | kNOT tLPAREN2 rparen
1094
+ {
1095
+ result = @builder.not_op(val[0], val[1], nil, val[2])
1096
+ }
1097
+ | fcall brace_block
1098
+ {
1099
+ method_call = @builder.call_method(nil, nil, val[0])
1100
+
1101
+ begin_t, args, body, end_t = val[1]
1102
+ result = @builder.block(method_call,
1103
+ begin_t, args, body, end_t)
1104
+ }
1105
+ | method_call
1106
+ | method_call brace_block
1107
+ {
1108
+ begin_t, args, body, end_t = val[1]
1109
+ result = @builder.block(val[0],
1110
+ begin_t, args, body, end_t)
1111
+ }
1112
+ | tLAMBDA lambda
1113
+ {
1114
+ lambda_call = @builder.call_lambda(val[0])
1115
+
1116
+ args, (begin_t, body, end_t) = val[1]
1117
+ result = @builder.block(lambda_call,
1118
+ begin_t, args, body, end_t)
1119
+ }
1120
+ | kIF expr_value then compstmt if_tail kEND
1121
+ {
1122
+ else_t, else_ = val[4]
1123
+ result = @builder.condition(val[0], val[1], val[2],
1124
+ val[3], else_t,
1125
+ else_, val[5])
1126
+ }
1127
+ | kUNLESS expr_value then compstmt opt_else kEND
1128
+ {
1129
+ else_t, else_ = val[4]
1130
+ result = @builder.condition(val[0], val[1], val[2],
1131
+ else_, else_t,
1132
+ val[3], val[5])
1133
+ }
1134
+ | kWHILE expr_value_do compstmt kEND
1135
+ {
1136
+ result = @builder.loop(:while, val[0], *val[1], val[2], val[3])
1137
+ }
1138
+ | kUNTIL expr_value_do compstmt kEND
1139
+ {
1140
+ result = @builder.loop(:until, val[0], *val[1], val[2], val[3])
1141
+ }
1142
+ | kCASE expr_value opt_terms case_body kEND
1143
+ {
1144
+ *when_bodies, (else_t, else_body) = *val[3]
1145
+
1146
+ result = @builder.case(val[0], val[1],
1147
+ when_bodies, else_t, else_body,
1148
+ val[4])
1149
+ }
1150
+ | kCASE opt_terms case_body kEND
1151
+ {
1152
+ *when_bodies, (else_t, else_body) = *val[2]
1153
+
1154
+ result = @builder.case(val[0], nil,
1155
+ when_bodies, else_t, else_body,
1156
+ val[3])
1157
+ }
1158
+ | kCASE expr_value opt_terms p_case_body kEND
1159
+ {
1160
+ *in_bodies, (else_t, else_body) = *val[3]
1161
+
1162
+ result = @builder.case_match(val[0], val[1],
1163
+ in_bodies, else_t, else_body,
1164
+ val[4])
1165
+ }
1166
+ | kFOR for_var kIN expr_value_do compstmt kEND
1167
+ {
1168
+ result = @builder.for(val[0], val[1], val[2], *val[3], val[4], val[5])
1169
+ }
1170
+ | kCLASS cpath superclass
1171
+ {
1172
+ @static_env.extend_static
1173
+ @lexer.cmdarg.push(false)
1174
+ @lexer.cond.push(false)
1175
+ @context.push(:class)
1176
+ }
1177
+ bodystmt kEND
1178
+ {
1179
+ unless @context.class_definition_allowed?
1180
+ diagnostic :error, :class_in_def, nil, val[0]
1181
+ end
1182
+
1183
+ lt_t, superclass = val[2]
1184
+ result = @builder.def_class(val[0], val[1],
1185
+ lt_t, superclass,
1186
+ val[4], val[5])
1187
+
1188
+ @lexer.cmdarg.pop
1189
+ @lexer.cond.pop
1190
+ @static_env.unextend
1191
+ @context.pop
1192
+ }
1193
+ | kCLASS tLSHFT expr term
1194
+ {
1195
+ @static_env.extend_static
1196
+ @lexer.cmdarg.push(false)
1197
+ @lexer.cond.push(false)
1198
+ @context.push(:sclass)
1199
+ }
1200
+ bodystmt kEND
1201
+ {
1202
+ result = @builder.def_sclass(val[0], val[1], val[2],
1203
+ val[5], val[6])
1204
+
1205
+ @lexer.cmdarg.pop
1206
+ @lexer.cond.pop
1207
+ @static_env.unextend
1208
+ @context.pop
1209
+ }
1210
+ | kMODULE cpath
1211
+ {
1212
+ @static_env.extend_static
1213
+ @lexer.cmdarg.push(false)
1214
+ }
1215
+ bodystmt kEND
1216
+ {
1217
+ unless @context.module_definition_allowed?
1218
+ diagnostic :error, :module_in_def, nil, val[0]
1219
+ end
1220
+
1221
+ result = @builder.def_module(val[0], val[1],
1222
+ val[3], val[4])
1223
+
1224
+ @lexer.cmdarg.pop
1225
+ @static_env.unextend
1226
+ }
1227
+ | kDEF fname
1228
+ {
1229
+ @static_env.extend_static
1230
+ @lexer.cmdarg.push(false)
1231
+ @lexer.cond.push(false)
1232
+ @context.push(:def)
1233
+ @current_arg_stack.push(nil)
1234
+ }
1235
+ f_arglist bodystmt kEND
1236
+ {
1237
+ result = @builder.def_method(val[0], val[1],
1238
+ val[3], val[4], val[5])
1239
+
1240
+ @lexer.cmdarg.pop
1241
+ @lexer.cond.pop
1242
+ @static_env.unextend
1243
+ @context.pop
1244
+ @current_arg_stack.pop
1245
+ }
1246
+ | kDEF singleton dot_or_colon
1247
+ {
1248
+ @lexer.state = :expr_fname
1249
+ }
1250
+ fname
1251
+ {
1252
+ @static_env.extend_static
1253
+ @lexer.cmdarg.push(false)
1254
+ @lexer.cond.push(false)
1255
+ @context.push(:defs)
1256
+ @current_arg_stack.push(nil)
1257
+ }
1258
+ f_arglist bodystmt kEND
1259
+ {
1260
+ result = @builder.def_singleton(val[0], val[1], val[2],
1261
+ val[4], val[6], val[7], val[8])
1262
+
1263
+ @lexer.cmdarg.pop
1264
+ @lexer.cond.pop
1265
+ @static_env.unextend
1266
+ @context.pop
1267
+ @current_arg_stack.pop
1268
+ }
1269
+ | kBREAK
1270
+ {
1271
+ result = @builder.keyword_cmd(:break, val[0])
1272
+ }
1273
+ | kNEXT
1274
+ {
1275
+ result = @builder.keyword_cmd(:next, val[0])
1276
+ }
1277
+ | kREDO
1278
+ {
1279
+ result = @builder.keyword_cmd(:redo, val[0])
1280
+ }
1281
+ | kRETRY
1282
+ {
1283
+ result = @builder.keyword_cmd(:retry, val[0])
1284
+ }
1285
+ | primary_value tMETHREF operation2
1286
+ {
1287
+ result = @builder.method_ref(val[0], val[1], val[2])
1288
+ }
1289
+
1290
+ primary_value: primary
1291
+
1292
+ k_return: kRETURN
1293
+ {
1294
+ if @context.in_class?
1295
+ diagnostic :error, :invalid_return, nil, val[0]
1296
+ end
1297
+ }
1298
+
1299
+ then: term
1300
+ | kTHEN
1301
+ | term kTHEN
1302
+ {
1303
+ result = val[1]
1304
+ }
1305
+
1306
+ do: term
1307
+ | kDO_COND
1308
+
1309
+ if_tail: opt_else
1310
+ | kELSIF expr_value then compstmt if_tail
1311
+ {
1312
+ else_t, else_ = val[4]
1313
+ result = [ val[0],
1314
+ @builder.condition(val[0], val[1], val[2],
1315
+ val[3], else_t,
1316
+ else_, nil),
1317
+ ]
1318
+ }
1319
+
1320
+ opt_else: none
1321
+ | kELSE compstmt
1322
+ {
1323
+ result = val
1324
+ }
1325
+
1326
+ for_var: lhs
1327
+ | mlhs
1328
+
1329
+ f_marg: f_norm_arg
1330
+ {
1331
+ result = @builder.arg(val[0])
1332
+ }
1333
+ | tLPAREN f_margs rparen
1334
+ {
1335
+ result = @builder.multi_lhs(val[0], val[1], val[2])
1336
+ }
1337
+
1338
+ f_marg_list: f_marg
1339
+ {
1340
+ result = [ val[0] ]
1341
+ }
1342
+ | f_marg_list tCOMMA f_marg
1343
+ {
1344
+ result = val[0] << val[2]
1345
+ }
1346
+
1347
+ f_margs: f_marg_list
1348
+ | f_marg_list tCOMMA f_rest_marg
1349
+ {
1350
+ result = val[0].
1351
+ push(val[2])
1352
+ }
1353
+ | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1354
+ {
1355
+ result = val[0].
1356
+ push(val[2]).
1357
+ concat(val[4])
1358
+ }
1359
+ | f_rest_marg
1360
+ {
1361
+ result = [ val[0] ]
1362
+ }
1363
+ | f_rest_marg tCOMMA f_marg_list
1364
+ {
1365
+ result = [ val[0], *val[2] ]
1366
+ }
1367
+
1368
+ f_rest_marg: tSTAR f_norm_arg
1369
+ {
1370
+ result = @builder.restarg(val[0], val[1])
1371
+ }
1372
+ | tSTAR
1373
+ {
1374
+ result = @builder.restarg(val[0])
1375
+ }
1376
+
1377
+ block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1378
+ {
1379
+ result = val[0].concat(val[2]).concat(val[3])
1380
+ }
1381
+ | f_block_kwarg opt_f_block_arg
1382
+ {
1383
+ result = val[0].concat(val[1])
1384
+ }
1385
+ | f_kwrest opt_f_block_arg
1386
+ {
1387
+ result = val[0].concat(val[1])
1388
+ }
1389
+ | f_no_kwarg opt_f_block_arg
1390
+ {
1391
+ result = val[0].concat(val[1])
1392
+ }
1393
+ | f_block_arg
1394
+ {
1395
+ result = [ val[0] ]
1396
+ }
1397
+
1398
+ opt_block_args_tail:
1399
+ tCOMMA block_args_tail
1400
+ {
1401
+ result = val[1]
1402
+ }
1403
+ | # nothing
1404
+ {
1405
+ result = []
1406
+ }
1407
+
1408
+ block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1409
+ {
1410
+ result = val[0].
1411
+ concat(val[2]).
1412
+ concat(val[4]).
1413
+ concat(val[5])
1414
+ }
1415
+ | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1416
+ {
1417
+ result = val[0].
1418
+ concat(val[2]).
1419
+ concat(val[4]).
1420
+ concat(val[6]).
1421
+ concat(val[7])
1422
+ }
1423
+ | f_arg tCOMMA f_block_optarg opt_block_args_tail
1424
+ {
1425
+ result = val[0].
1426
+ concat(val[2]).
1427
+ concat(val[3])
1428
+ }
1429
+ | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1430
+ {
1431
+ result = val[0].
1432
+ concat(val[2]).
1433
+ concat(val[4]).
1434
+ concat(val[5])
1435
+ }
1436
+ | f_arg tCOMMA f_rest_arg opt_block_args_tail
1437
+ {
1438
+ result = val[0].
1439
+ concat(val[2]).
1440
+ concat(val[3])
1441
+ }
1442
+ | f_arg tCOMMA
1443
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1444
+ {
1445
+ result = val[0].
1446
+ concat(val[2]).
1447
+ concat(val[4]).
1448
+ concat(val[5])
1449
+ }
1450
+ | f_arg opt_block_args_tail
1451
+ {
1452
+ if val[1].empty? && val[0].size == 1
1453
+ result = [@builder.procarg0(val[0][0])]
1454
+ else
1455
+ result = val[0].concat(val[1])
1456
+ end
1457
+ }
1458
+ | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1459
+ {
1460
+ result = val[0].
1461
+ concat(val[2]).
1462
+ concat(val[3])
1463
+ }
1464
+ | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1465
+ {
1466
+ result = val[0].
1467
+ concat(val[2]).
1468
+ concat(val[4]).
1469
+ concat(val[5])
1470
+ }
1471
+ | f_block_optarg opt_block_args_tail
1472
+ {
1473
+ result = val[0].
1474
+ concat(val[1])
1475
+ }
1476
+ | f_block_optarg tCOMMA f_arg opt_block_args_tail
1477
+ {
1478
+ result = val[0].
1479
+ concat(val[2]).
1480
+ concat(val[3])
1481
+ }
1482
+ | f_rest_arg opt_block_args_tail
1483
+ {
1484
+ result = val[0].
1485
+ concat(val[1])
1486
+ }
1487
+ | f_rest_arg tCOMMA f_arg opt_block_args_tail
1488
+ {
1489
+ result = val[0].
1490
+ concat(val[2]).
1491
+ concat(val[3])
1492
+ }
1493
+ | block_args_tail
1494
+
1495
+ opt_block_param: # nothing
1496
+ {
1497
+ result = @builder.args(nil, [], nil)
1498
+ }
1499
+ | block_param_def
1500
+ {
1501
+ @lexer.state = :expr_value
1502
+ }
1503
+
1504
+ block_param_def: tPIPE opt_bv_decl tPIPE
1505
+ {
1506
+ @max_numparam_stack.has_ordinary_params!
1507
+ @current_arg_stack.set(nil)
1508
+ result = @builder.args(val[0], val[1], val[2])
1509
+ }
1510
+ | tPIPE block_param opt_bv_decl tPIPE
1511
+ {
1512
+ @max_numparam_stack.has_ordinary_params!
1513
+ @current_arg_stack.set(nil)
1514
+ result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1515
+ }
1516
+
1517
+ opt_bv_decl: opt_nl
1518
+ {
1519
+ result = []
1520
+ }
1521
+ | opt_nl tSEMI bv_decls opt_nl
1522
+ {
1523
+ result = val[2]
1524
+ }
1525
+
1526
+ bv_decls: bvar
1527
+ {
1528
+ result = [ val[0] ]
1529
+ }
1530
+ | bv_decls tCOMMA bvar
1531
+ {
1532
+ result = val[0] << val[2]
1533
+ }
1534
+
1535
+ bvar: tIDENTIFIER
1536
+ {
1537
+ @static_env.declare val[0][0]
1538
+ result = @builder.shadowarg(val[0])
1539
+ }
1540
+ | f_bad_arg
1541
+
1542
+ lambda: {
1543
+ @static_env.extend_dynamic
1544
+ @max_numparam_stack.push
1545
+ @context.push(:lambda)
1546
+ }
1547
+ f_larglist
1548
+ {
1549
+ @context.pop
1550
+ @lexer.cmdarg.push(false)
1551
+ }
1552
+ lambda_body
1553
+ {
1554
+ args = @max_numparam_stack.has_numparams? ? @builder.numargs(@max_numparam_stack.top) : val[1]
1555
+ result = [ args, val[3] ]
1556
+
1557
+ @max_numparam_stack.pop
1558
+ @static_env.unextend
1559
+ @lexer.cmdarg.pop
1560
+ }
1561
+
1562
+ f_larglist: tLPAREN2 f_args opt_bv_decl tRPAREN
1563
+ {
1564
+ @max_numparam_stack.has_ordinary_params!
1565
+ result = @builder.args(val[0], val[1].concat(val[2]), val[3])
1566
+ }
1567
+ | f_args
1568
+ {
1569
+ if val[0].any?
1570
+ @max_numparam_stack.has_ordinary_params!
1571
+ end
1572
+ result = @builder.args(nil, val[0], nil)
1573
+ }
1574
+
1575
+ lambda_body: tLAMBEG
1576
+ {
1577
+ @context.push(:lambda)
1578
+ }
1579
+ compstmt tRCURLY
1580
+ {
1581
+ result = [ val[0], val[2], val[3] ]
1582
+ @context.pop
1583
+ }
1584
+ | kDO_LAMBDA
1585
+ {
1586
+ @context.push(:lambda)
1587
+ }
1588
+ bodystmt kEND
1589
+ {
1590
+ result = [ val[0], val[2], val[3] ]
1591
+ @context.pop
1592
+ }
1593
+
1594
+ do_block: kDO_BLOCK
1595
+ {
1596
+ @context.push(:block)
1597
+ }
1598
+ do_body kEND
1599
+ {
1600
+ result = [ val[0], *val[2], val[3] ]
1601
+ @context.pop
1602
+ }
1603
+
1604
+ block_call: command do_block
1605
+ {
1606
+ begin_t, block_args, body, end_t = val[1]
1607
+ result = @builder.block(val[0],
1608
+ begin_t, block_args, body, end_t)
1609
+ }
1610
+ | block_call dot_or_colon operation2 opt_paren_args
1611
+ {
1612
+ lparen_t, args, rparen_t = val[3]
1613
+ result = @builder.call_method(val[0], val[1], val[2],
1614
+ lparen_t, args, rparen_t)
1615
+ }
1616
+ | block_call dot_or_colon operation2 opt_paren_args brace_block
1617
+ {
1618
+ lparen_t, args, rparen_t = val[3]
1619
+ method_call = @builder.call_method(val[0], val[1], val[2],
1620
+ lparen_t, args, rparen_t)
1621
+
1622
+ begin_t, args, body, end_t = val[4]
1623
+ result = @builder.block(method_call,
1624
+ begin_t, args, body, end_t)
1625
+ }
1626
+ | block_call dot_or_colon operation2 command_args do_block
1627
+ {
1628
+ method_call = @builder.call_method(val[0], val[1], val[2],
1629
+ nil, val[3], nil)
1630
+
1631
+ begin_t, args, body, end_t = val[4]
1632
+ result = @builder.block(method_call,
1633
+ begin_t, args, body, end_t)
1634
+ }
1635
+
1636
+ method_call: fcall paren_args
1637
+ {
1638
+ lparen_t, args, rparen_t = val[1]
1639
+ result = @builder.call_method(nil, nil, val[0],
1640
+ lparen_t, args, rparen_t)
1641
+ }
1642
+ | primary_value call_op operation2 opt_paren_args
1643
+ {
1644
+ lparen_t, args, rparen_t = val[3]
1645
+ result = @builder.call_method(val[0], val[1], val[2],
1646
+ lparen_t, args, rparen_t)
1647
+ }
1648
+ | primary_value tCOLON2 operation2 paren_args
1649
+ {
1650
+ lparen_t, args, rparen_t = val[3]
1651
+ result = @builder.call_method(val[0], val[1], val[2],
1652
+ lparen_t, args, rparen_t)
1653
+ }
1654
+ | primary_value tCOLON2 operation3
1655
+ {
1656
+ result = @builder.call_method(val[0], val[1], val[2])
1657
+ }
1658
+ | primary_value call_op paren_args
1659
+ {
1660
+ lparen_t, args, rparen_t = val[2]
1661
+ result = @builder.call_method(val[0], val[1], nil,
1662
+ lparen_t, args, rparen_t)
1663
+ }
1664
+ | primary_value tCOLON2 paren_args
1665
+ {
1666
+ lparen_t, args, rparen_t = val[2]
1667
+ result = @builder.call_method(val[0], val[1], nil,
1668
+ lparen_t, args, rparen_t)
1669
+ }
1670
+ | kSUPER paren_args
1671
+ {
1672
+ lparen_t, args, rparen_t = val[1]
1673
+ result = @builder.keyword_cmd(:super, val[0],
1674
+ lparen_t, args, rparen_t)
1675
+ }
1676
+ | kSUPER
1677
+ {
1678
+ result = @builder.keyword_cmd(:zsuper, val[0])
1679
+ }
1680
+ | primary_value tLBRACK2 opt_call_args rbracket
1681
+ {
1682
+ result = @builder.index(val[0], val[1], val[2], val[3])
1683
+ }
1684
+
1685
+ brace_block: tLCURLY
1686
+ {
1687
+ @context.push(:block)
1688
+ }
1689
+ brace_body tRCURLY
1690
+ {
1691
+ result = [ val[0], *val[2], val[3] ]
1692
+ @context.pop
1693
+ }
1694
+ | kDO
1695
+ {
1696
+ @context.push(:block)
1697
+ }
1698
+ do_body kEND
1699
+ {
1700
+ result = [ val[0], *val[2], val[3] ]
1701
+ @context.pop
1702
+ }
1703
+
1704
+ brace_body: {
1705
+ @static_env.extend_dynamic
1706
+ @max_numparam_stack.push
1707
+ }
1708
+ opt_block_param compstmt
1709
+ {
1710
+ args = @max_numparam_stack.has_numparams? ? @builder.numargs(@max_numparam_stack.top) : val[1]
1711
+ result = [ args, val[2] ]
1712
+
1713
+ @max_numparam_stack.pop
1714
+ @static_env.unextend
1715
+ }
1716
+
1717
+ do_body: {
1718
+ @static_env.extend_dynamic
1719
+ @max_numparam_stack.push
1720
+ }
1721
+ {
1722
+ @lexer.cmdarg.push(false)
1723
+ }
1724
+ opt_block_param bodystmt
1725
+ {
1726
+ args = @max_numparam_stack.has_numparams? ? @builder.numargs(@max_numparam_stack.top) : val[2]
1727
+ result = [ args, val[3] ]
1728
+
1729
+ @max_numparam_stack.pop
1730
+ @static_env.unextend
1731
+ @lexer.cmdarg.pop
1732
+ }
1733
+
1734
+ case_body: kWHEN args then compstmt cases
1735
+ {
1736
+ result = [ @builder.when(val[0], val[1], val[2], val[3]),
1737
+ *val[4] ]
1738
+ }
1739
+
1740
+ cases: opt_else
1741
+ {
1742
+ result = [ val[0] ]
1743
+ }
1744
+ | case_body
1745
+
1746
+ p_case_body: kIN
1747
+ {
1748
+ @lexer.state = :expr_beg
1749
+ @lexer.command_start = false
1750
+ @pattern_variables.push
1751
+ @pattern_hash_keys.push
1752
+
1753
+ result = @lexer.in_kwarg
1754
+ @lexer.in_kwarg = true
1755
+ }
1756
+ p_top_expr then
1757
+ {
1758
+ @lexer.in_kwarg = val[1]
1759
+ }
1760
+ compstmt p_cases
1761
+ {
1762
+ result = [ @builder.in_pattern(val[0], *val[2], val[3], val[5]),
1763
+ *val[6] ]
1764
+ }
1765
+
1766
+ p_cases: opt_else
1767
+ {
1768
+ result = [ val[0] ]
1769
+ }
1770
+ | p_case_body
1771
+
1772
+ p_top_expr: p_top_expr_body
1773
+ {
1774
+ result = [ val[0], nil ]
1775
+ }
1776
+ | p_top_expr_body kIF_MOD expr_value
1777
+ {
1778
+ result = [ val[0], @builder.if_guard(val[1], val[2]) ]
1779
+ }
1780
+ | p_top_expr_body kUNLESS_MOD expr_value
1781
+ {
1782
+ result = [ val[0], @builder.unless_guard(val[1], val[2]) ]
1783
+ }
1784
+
1785
+ p_top_expr_body: p_expr
1786
+ | p_expr tCOMMA
1787
+ {
1788
+ # array patterns that end with comma
1789
+ # like 1, 2,
1790
+ # must be emitted as `array_pattern_with_tail`
1791
+ item = @builder.match_with_trailing_comma(val[0], val[1])
1792
+ result = @builder.array_pattern(nil, [ item ], nil)
1793
+ }
1794
+ | p_expr tCOMMA p_args
1795
+ {
1796
+ result = @builder.array_pattern(nil, [val[0]].concat(val[2]), nil)
1797
+ }
1798
+ | p_args_tail
1799
+ {
1800
+ result = @builder.array_pattern(nil, val[0], nil)
1801
+ }
1802
+ | p_kwargs
1803
+ {
1804
+ result = @builder.hash_pattern(nil, val[0], nil)
1805
+ }
1806
+
1807
+ p_expr: p_as
1808
+
1809
+ p_as: p_expr tASSOC p_variable
1810
+ {
1811
+ result = @builder.match_as(val[0], val[1], val[2])
1812
+ }
1813
+ | p_alt
1814
+
1815
+ p_alt: p_alt tPIPE p_expr_basic
1816
+ {
1817
+ result = @builder.match_alt(val[0], val[1], val[2])
1818
+ }
1819
+ | p_expr_basic
1820
+
1821
+ p_lparen: tLPAREN2
1822
+ {
1823
+ result = val[0]
1824
+ @pattern_hash_keys.push
1825
+ }
1826
+
1827
+ p_lbracket: tLBRACK2
1828
+ {
1829
+ result = val[0]
1830
+ @pattern_hash_keys.push
1831
+ }
1832
+
1833
+ p_expr_basic: p_value
1834
+ | p_const p_lparen p_args rparen
1835
+ {
1836
+ @pattern_hash_keys.pop
1837
+ pattern = @builder.array_pattern(nil, val[2], nil)
1838
+ result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1839
+ }
1840
+ | p_const p_lparen p_kwargs rparen
1841
+ {
1842
+ @pattern_hash_keys.pop
1843
+ pattern = @builder.hash_pattern(nil, val[2], nil)
1844
+ result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1845
+ }
1846
+ | p_const tLPAREN2 rparen
1847
+ {
1848
+ pattern = @builder.array_pattern(val[1], nil, val[2])
1849
+ result = @builder.const_pattern(val[0], val[1], pattern, val[2])
1850
+ }
1851
+ | p_const p_lbracket p_args rbracket
1852
+ {
1853
+ @pattern_hash_keys.pop
1854
+ pattern = @builder.array_pattern(nil, val[2], nil)
1855
+ result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1856
+ }
1857
+ | p_const p_lbracket p_kwargs rbracket
1858
+ {
1859
+ @pattern_hash_keys.pop
1860
+ pattern = @builder.hash_pattern(nil, val[2], nil)
1861
+ result = @builder.const_pattern(val[0], val[1], pattern, val[3])
1862
+ }
1863
+ | p_const tLBRACK2 rbracket
1864
+ {
1865
+ pattern = @builder.array_pattern(val[1], nil, val[2])
1866
+ result = @builder.const_pattern(val[0], val[1], pattern, val[2])
1867
+ }
1868
+ | tLBRACK
1869
+ {
1870
+ @pattern_hash_keys.push
1871
+ }
1872
+ p_args rbracket
1873
+ {
1874
+ @pattern_hash_keys.pop
1875
+ result = @builder.array_pattern(val[0], val[2], val[3])
1876
+ }
1877
+ | tLBRACK rbracket
1878
+ {
1879
+ result = @builder.array_pattern(val[0], [], val[1])
1880
+ }
1881
+ | tLBRACE
1882
+ {
1883
+ @pattern_hash_keys.push
1884
+ result = @lexer.in_kwarg
1885
+ @lexer.in_kwarg = false
1886
+ }
1887
+ p_kwargs rbrace
1888
+ {
1889
+ @pattern_hash_keys.pop
1890
+ @lexer.in_kwarg = val[1]
1891
+ result = @builder.hash_pattern(val[0], val[2], val[3])
1892
+ }
1893
+ | tLBRACE rbrace
1894
+ {
1895
+ result = @builder.hash_pattern(val[0], [], val[1])
1896
+ }
1897
+ | tLPAREN
1898
+ {
1899
+ @pattern_hash_keys.push
1900
+ }
1901
+ p_expr rparen
1902
+ {
1903
+ @pattern_hash_keys.pop
1904
+ result = @builder.begin(val[0], val[2], val[3])
1905
+ }
1906
+
1907
+ p_args: p_expr
1908
+ {
1909
+ result = [ val[0] ]
1910
+ }
1911
+ | p_args_head
1912
+ {
1913
+ result = val[0]
1914
+ }
1915
+ | p_args_head p_arg
1916
+ {
1917
+ result = [ *val[0], val[1] ]
1918
+ }
1919
+ | p_args_head tSTAR tIDENTIFIER
1920
+ {
1921
+ match_rest = @builder.match_rest(val[1], val[2])
1922
+ result = [ *val[0], match_rest ]
1923
+ }
1924
+ | p_args_head tSTAR tIDENTIFIER tCOMMA p_args_post
1925
+ {
1926
+ match_rest = @builder.match_rest(val[1], val[2])
1927
+ result = [ *val[0], match_rest, *val[4] ]
1928
+ }
1929
+ | p_args_head tSTAR
1930
+ {
1931
+ result = [ *val[0], @builder.match_rest(val[1]) ]
1932
+ }
1933
+ | p_args_head tSTAR tCOMMA p_args_post
1934
+ {
1935
+ result = [ *val[0], @builder.match_rest(val[1]), *val[3] ]
1936
+ }
1937
+ | p_args_tail
1938
+
1939
+ p_args_head: p_arg tCOMMA
1940
+ {
1941
+ # array patterns that end with comma
1942
+ # like [1, 2,]
1943
+ # must be emitted as `array_pattern_with_tail`
1944
+ item = @builder.match_with_trailing_comma(val[0], val[1])
1945
+ result = [ item ]
1946
+ }
1947
+ | p_args_head p_arg tCOMMA
1948
+ {
1949
+ # array patterns that end with comma
1950
+ # like [1, 2,]
1951
+ # must be emitted as `array_pattern_with_tail`
1952
+ last_item = @builder.match_with_trailing_comma(val[1], val[2])
1953
+ result = [ *val[0], last_item ]
1954
+ }
1955
+
1956
+ p_args_tail: tSTAR tIDENTIFIER
1957
+ {
1958
+ match_rest = @builder.match_rest(val[0], val[1])
1959
+ result = [ match_rest ]
1960
+ }
1961
+ | tSTAR tIDENTIFIER tCOMMA p_args_post
1962
+ {
1963
+ match_rest = @builder.match_rest(val[0], val[1])
1964
+ result = [ match_rest, *val[3] ]
1965
+ }
1966
+ | tSTAR
1967
+ {
1968
+ match_rest = @builder.match_rest(val[0])
1969
+ result = [ match_rest ]
1970
+ }
1971
+ | tSTAR tCOMMA p_args_post
1972
+ {
1973
+ match_rest = @builder.match_rest(val[0])
1974
+ result = [ match_rest, *val[2] ]
1975
+ }
1976
+
1977
+ p_args_post: p_arg
1978
+ {
1979
+ result = [ val[0] ]
1980
+ }
1981
+ | p_args_post tCOMMA p_arg
1982
+ {
1983
+ result = [ *val[0], val[2] ]
1984
+ }
1985
+
1986
+ p_arg: p_expr
1987
+
1988
+ p_kwargs: p_kwarg tCOMMA p_kwrest
1989
+ {
1990
+ result = [ *val[0], *val[2] ]
1991
+ }
1992
+ | p_kwarg
1993
+ {
1994
+ result = val[0]
1995
+ }
1996
+ | p_kwarg tCOMMA
1997
+ {
1998
+ result = val[0]
1999
+ }
2000
+ | p_kwrest
2001
+ {
2002
+ result = val[0]
2003
+ }
2004
+ | p_kwarg tCOMMA p_kwnorest
2005
+ {
2006
+ result = [ *val[0], *val[2] ]
2007
+ }
2008
+ | p_kwnorest
2009
+ {
2010
+ result = [ *val[0], *val[2] ]
2011
+ }
2012
+
2013
+ p_kwarg: p_kw
2014
+ {
2015
+ result = [ val[0] ]
2016
+ }
2017
+ | p_kwarg tCOMMA p_kw
2018
+ {
2019
+ result = [ *val[0], val[2] ]
2020
+ }
2021
+
2022
+ p_kw: p_kw_label p_expr
2023
+ {
2024
+ result = @builder.match_pair(*val[0], val[1])
2025
+ }
2026
+ | p_kw_label
2027
+ {
2028
+ result = @builder.match_label(*val[0])
2029
+ }
2030
+
2031
+ p_kw_label: tLABEL
2032
+ {
2033
+ check_kwarg_name(val[0])
2034
+ result = [:label, val[0]]
2035
+ }
2036
+ | tSTRING_BEG string_contents tLABEL_END
2037
+ {
2038
+ result = [:quoted, [val[0], val[1], val[2]]]
2039
+ }
2040
+
2041
+ p_kwrest: kwrest_mark tIDENTIFIER
2042
+ {
2043
+ result = [ @builder.match_rest(val[0], val[1]) ]
2044
+ }
2045
+ | kwrest_mark
2046
+ {
2047
+ result = [ @builder.match_rest(val[0], nil) ]
2048
+ }
2049
+
2050
+ p_kwnorest: kwrest_mark kNIL
2051
+ {
2052
+ result = [ @builder.match_nil_pattern(val[0], val[1]) ]
2053
+ }
2054
+
2055
+ p_value: p_primitive
2056
+ | p_primitive tDOT2 p_primitive
2057
+ {
2058
+ result = @builder.range_inclusive(val[0], val[1], val[2])
2059
+ }
2060
+ | p_primitive tDOT3 p_primitive
2061
+ {
2062
+ result = @builder.range_exclusive(val[0], val[1], val[2])
2063
+ }
2064
+ | p_primitive tDOT2
2065
+ {
2066
+ result = @builder.range_inclusive(val[0], val[1], nil)
2067
+ }
2068
+ | p_primitive tDOT3
2069
+ {
2070
+ result = @builder.range_exclusive(val[0], val[1], nil)
2071
+ }
2072
+ | p_variable
2073
+ | p_var_ref
2074
+ | p_const
2075
+ | tBDOT2 p_primitive
2076
+ {
2077
+ result = @builder.range_inclusive(nil, val[0], val[1])
2078
+ }
2079
+ | tBDOT3 p_primitive
2080
+ {
2081
+ result = @builder.range_exclusive(nil, val[0], val[1])
2082
+ }
2083
+
2084
+ p_primitive: literal
2085
+ | strings
2086
+ | xstring
2087
+ | regexp
2088
+ | words
2089
+ | qwords
2090
+ | symbols
2091
+ | qsymbols
2092
+ | keyword_variable
2093
+ {
2094
+ result = @builder.accessible(val[0])
2095
+ }
2096
+ | tLAMBDA lambda
2097
+ {
2098
+ lambda_call = @builder.call_lambda(val[0])
2099
+
2100
+ args, (begin_t, body, end_t) = val[1]
2101
+ result = @builder.block(lambda_call,
2102
+ begin_t, args, body, end_t)
2103
+ }
2104
+
2105
+ p_variable: tIDENTIFIER
2106
+ {
2107
+ result = @builder.match_var(val[0])
2108
+ }
2109
+
2110
+ p_var_ref: tCARET tIDENTIFIER
2111
+ {
2112
+ name = val[1][0]
2113
+ unless static_env.declared?(name)
2114
+ diagnostic :error, :undefined_lvar, { :name => name }, val[1]
2115
+ end
2116
+
2117
+ lvar = @builder.accessible(@builder.ident(val[1]))
2118
+ result = @builder.pin(val[0], lvar)
2119
+ }
2120
+
2121
+ p_const: tCOLON3 cname
2122
+ {
2123
+ result = @builder.const_global(val[0], val[1])
2124
+ }
2125
+ | p_const tCOLON2 cname
2126
+ {
2127
+ result = @builder.const_fetch(val[0], val[1], val[2])
2128
+ }
2129
+ | tCONSTANT
2130
+ {
2131
+ result = @builder.const(val[0])
2132
+ }
2133
+
2134
+ opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
2135
+ {
2136
+ assoc_t, exc_var = val[2]
2137
+
2138
+ if val[1]
2139
+ exc_list = @builder.array(nil, val[1], nil)
2140
+ end
2141
+
2142
+ result = [ @builder.rescue_body(val[0],
2143
+ exc_list, assoc_t, exc_var,
2144
+ val[3], val[4]),
2145
+ *val[5] ]
2146
+ }
2147
+ |
2148
+ {
2149
+ result = []
2150
+ }
2151
+
2152
+ exc_list: arg_value
2153
+ {
2154
+ result = [ val[0] ]
2155
+ }
2156
+ | mrhs
2157
+ | none
2158
+
2159
+ exc_var: tASSOC lhs
2160
+ {
2161
+ result = [ val[0], val[1] ]
2162
+ }
2163
+ | none
2164
+
2165
+ opt_ensure: kENSURE compstmt
2166
+ {
2167
+ result = [ val[0], val[1] ]
2168
+ }
2169
+ | none
2170
+
2171
+ literal: numeric
2172
+ | symbol
2173
+
2174
+ strings: string
2175
+ {
2176
+ result = @builder.string_compose(nil, val[0], nil)
2177
+ }
2178
+
2179
+ string: string1
2180
+ {
2181
+ result = [ val[0] ]
2182
+ }
2183
+ | string string1
2184
+ {
2185
+ result = val[0] << val[1]
2186
+ }
2187
+
2188
+ string1: tSTRING_BEG string_contents tSTRING_END
2189
+ {
2190
+ string = @builder.string_compose(val[0], val[1], val[2])
2191
+ result = @builder.dedent_string(string, @lexer.dedent_level)
2192
+ }
2193
+ | tSTRING
2194
+ {
2195
+ string = @builder.string(val[0])
2196
+ result = @builder.dedent_string(string, @lexer.dedent_level)
2197
+ }
2198
+ | tCHARACTER
2199
+ {
2200
+ result = @builder.character(val[0])
2201
+ }
2202
+
2203
+ xstring: tXSTRING_BEG xstring_contents tSTRING_END
2204
+ {
2205
+ string = @builder.xstring_compose(val[0], val[1], val[2])
2206
+ result = @builder.dedent_string(string, @lexer.dedent_level)
2207
+ }
2208
+
2209
+ regexp: tREGEXP_BEG regexp_contents tSTRING_END tREGEXP_OPT
2210
+ {
2211
+ opts = @builder.regexp_options(val[3])
2212
+ result = @builder.regexp_compose(val[0], val[1], val[2], opts)
2213
+ }
2214
+
2215
+ words: tWORDS_BEG word_list tSTRING_END
2216
+ {
2217
+ result = @builder.words_compose(val[0], val[1], val[2])
2218
+ }
2219
+
2220
+ word_list: # nothing
2221
+ {
2222
+ result = []
2223
+ }
2224
+ | word_list word tSPACE
2225
+ {
2226
+ result = val[0] << @builder.word(val[1])
2227
+ }
2228
+
2229
+ word: string_content
2230
+ {
2231
+ result = [ val[0] ]
2232
+ }
2233
+ | word string_content
2234
+ {
2235
+ result = val[0] << val[1]
2236
+ }
2237
+
2238
+ symbols: tSYMBOLS_BEG symbol_list tSTRING_END
2239
+ {
2240
+ result = @builder.symbols_compose(val[0], val[1], val[2])
2241
+ }
2242
+
2243
+ symbol_list: # nothing
2244
+ {
2245
+ result = []
2246
+ }
2247
+ | symbol_list word tSPACE
2248
+ {
2249
+ result = val[0] << @builder.word(val[1])
2250
+ }
2251
+
2252
+ qwords: tQWORDS_BEG qword_list tSTRING_END
2253
+ {
2254
+ result = @builder.words_compose(val[0], val[1], val[2])
2255
+ }
2256
+
2257
+ qsymbols: tQSYMBOLS_BEG qsym_list tSTRING_END
2258
+ {
2259
+ result = @builder.symbols_compose(val[0], val[1], val[2])
2260
+ }
2261
+
2262
+ qword_list: # nothing
2263
+ {
2264
+ result = []
2265
+ }
2266
+ | qword_list tSTRING_CONTENT tSPACE
2267
+ {
2268
+ result = val[0] << @builder.string_internal(val[1])
2269
+ }
2270
+
2271
+ qsym_list: # nothing
2272
+ {
2273
+ result = []
2274
+ }
2275
+ | qsym_list tSTRING_CONTENT tSPACE
2276
+ {
2277
+ result = val[0] << @builder.symbol_internal(val[1])
2278
+ }
2279
+
2280
+ string_contents: # nothing
2281
+ {
2282
+ result = []
2283
+ }
2284
+ | string_contents string_content
2285
+ {
2286
+ result = val[0] << val[1]
2287
+ }
2288
+
2289
+ xstring_contents: # nothing
2290
+ {
2291
+ result = []
2292
+ }
2293
+ | xstring_contents string_content
2294
+ {
2295
+ result = val[0] << val[1]
2296
+ }
2297
+
2298
+ regexp_contents: # nothing
2299
+ {
2300
+ result = []
2301
+ }
2302
+ | regexp_contents string_content
2303
+ {
2304
+ result = val[0] << val[1]
2305
+ }
2306
+
2307
+ string_content: tSTRING_CONTENT
2308
+ {
2309
+ result = @builder.string_internal(val[0])
2310
+ }
2311
+ | tSTRING_DVAR string_dvar
2312
+ {
2313
+ result = val[1]
2314
+ }
2315
+ | tSTRING_DBEG
2316
+ {
2317
+ @lexer.cmdarg.push(false)
2318
+ @lexer.cond.push(false)
2319
+ }
2320
+ compstmt tSTRING_DEND
2321
+ {
2322
+ @lexer.cmdarg.pop
2323
+ @lexer.cond.pop
2324
+
2325
+ result = @builder.begin(val[0], val[2], val[3])
2326
+ }
2327
+
2328
+ string_dvar: tGVAR
2329
+ {
2330
+ result = @builder.gvar(val[0])
2331
+ }
2332
+ | tIVAR
2333
+ {
2334
+ result = @builder.ivar(val[0])
2335
+ }
2336
+ | tCVAR
2337
+ {
2338
+ result = @builder.cvar(val[0])
2339
+ }
2340
+ | backref
2341
+
2342
+ symbol: ssym
2343
+ | dsym
2344
+
2345
+ ssym: tSYMBOL
2346
+ {
2347
+ @lexer.state = :expr_end
2348
+ result = @builder.symbol(val[0])
2349
+ }
2350
+
2351
+ dsym: tSYMBEG string_contents tSTRING_END
2352
+ {
2353
+ @lexer.state = :expr_end
2354
+ result = @builder.symbol_compose(val[0], val[1], val[2])
2355
+ }
2356
+
2357
+ numeric: simple_numeric
2358
+ {
2359
+ result = val[0]
2360
+ }
2361
+ | tUNARY_NUM simple_numeric =tLOWEST
2362
+ {
2363
+ if @builder.respond_to? :negate
2364
+ # AST builder interface compatibility
2365
+ result = @builder.negate(val[0], val[1])
2366
+ else
2367
+ result = @builder.unary_num(val[0], val[1])
2368
+ end
2369
+ }
2370
+
2371
+ simple_numeric: tINTEGER
2372
+ {
2373
+ @lexer.state = :expr_end
2374
+ result = @builder.integer(val[0])
2375
+ }
2376
+ | tFLOAT
2377
+ {
2378
+ @lexer.state = :expr_end
2379
+ result = @builder.float(val[0])
2380
+ }
2381
+ | tRATIONAL
2382
+ {
2383
+ @lexer.state = :expr_end
2384
+ result = @builder.rational(val[0])
2385
+ }
2386
+ | tIMAGINARY
2387
+ {
2388
+ @lexer.state = :expr_end
2389
+ result = @builder.complex(val[0])
2390
+ }
2391
+
2392
+ user_variable: tIDENTIFIER
2393
+ {
2394
+ result = @builder.ident(val[0])
2395
+ }
2396
+ | tIVAR
2397
+ {
2398
+ result = @builder.ivar(val[0])
2399
+ }
2400
+ | tGVAR
2401
+ {
2402
+ result = @builder.gvar(val[0])
2403
+ }
2404
+ | tCONSTANT
2405
+ {
2406
+ result = @builder.const(val[0])
2407
+ }
2408
+ | tCVAR
2409
+ {
2410
+ result = @builder.cvar(val[0])
2411
+ }
2412
+
2413
+ keyword_variable: kNIL
2414
+ {
2415
+ result = @builder.nil(val[0])
2416
+ }
2417
+ | kSELF
2418
+ {
2419
+ result = @builder.self(val[0])
2420
+ }
2421
+ | kTRUE
2422
+ {
2423
+ result = @builder.true(val[0])
2424
+ }
2425
+ | kFALSE
2426
+ {
2427
+ result = @builder.false(val[0])
2428
+ }
2429
+ | k__FILE__
2430
+ {
2431
+ result = @builder.__FILE__(val[0])
2432
+ }
2433
+ | k__LINE__
2434
+ {
2435
+ result = @builder.__LINE__(val[0])
2436
+ }
2437
+ | k__ENCODING__
2438
+ {
2439
+ result = @builder.__ENCODING__(val[0])
2440
+ }
2441
+
2442
+ var_ref: user_variable
2443
+ {
2444
+ if (node = val[0]) && node.type == :ident
2445
+ name = node.children[0]
2446
+
2447
+ if name =~ /\A_[1-9]\z/ && !static_env.declared?(name) && context.in_dynamic_block?
2448
+ # definitely an implicit param
2449
+ location = node.loc.expression
2450
+
2451
+ if max_numparam_stack.has_ordinary_params?
2452
+ diagnostic :error, :ordinary_param_defined, nil, [nil, location]
2453
+ end
2454
+
2455
+ raw_context = context.stack.dup
2456
+ raw_max_numparam_stack = max_numparam_stack.stack.dup
2457
+
2458
+ # ignore current block scope
2459
+ raw_context.pop
2460
+ raw_max_numparam_stack.pop
2461
+
2462
+ raw_context.reverse_each do |outer_scope|
2463
+ if outer_scope == :block || outer_scope == :lambda
2464
+ outer_scope_has_numparams = raw_max_numparam_stack.pop > 0
2465
+
2466
+ if outer_scope_has_numparams
2467
+ diagnostic :error, :numparam_used_in_outer_scope, nil, [nil, location]
2468
+ else
2469
+ # for now it's ok, but an outer scope can also be a block
2470
+ # with numparams, so we need to continue
2471
+ end
2472
+ else
2473
+ # found an outer scope that can't have numparams
2474
+ # like def/class/etc
2475
+ break
2476
+ end
2477
+ end
2478
+
2479
+ static_env.declare(name)
2480
+ max_numparam_stack.register(name[1].to_i)
2481
+ end
2482
+ end
2483
+
2484
+ result = @builder.accessible(val[0])
2485
+ }
2486
+ | keyword_variable
2487
+ {
2488
+ result = @builder.accessible(val[0])
2489
+ }
2490
+
2491
+ var_lhs: user_variable
2492
+ {
2493
+ result = @builder.assignable(val[0])
2494
+ }
2495
+ | keyword_variable
2496
+ {
2497
+ result = @builder.assignable(val[0])
2498
+ }
2499
+
2500
+ backref: tNTH_REF
2501
+ {
2502
+ result = @builder.nth_ref(val[0])
2503
+ }
2504
+ | tBACK_REF
2505
+ {
2506
+ result = @builder.back_ref(val[0])
2507
+ }
2508
+
2509
+ superclass: tLT
2510
+ {
2511
+ @lexer.state = :expr_value
2512
+ }
2513
+ expr_value term
2514
+ {
2515
+ result = [ val[0], val[2] ]
2516
+ }
2517
+ | # nothing
2518
+ {
2519
+ result = nil
2520
+ }
2521
+
2522
+ f_arglist: tLPAREN2 f_args rparen
2523
+ {
2524
+ result = @builder.args(val[0], val[1], val[2])
2525
+
2526
+ @lexer.state = :expr_value
2527
+ }
2528
+ | tLPAREN2 args_forward rparen
2529
+ {
2530
+ result = @builder.forward_args(val[0], val[1], val[2])
2531
+ @static_env.declare_forward_args
2532
+
2533
+ @lexer.state = :expr_value
2534
+ }
2535
+ | {
2536
+ result = @lexer.in_kwarg
2537
+ @lexer.in_kwarg = true
2538
+ }
2539
+ f_args term
2540
+ {
2541
+ @lexer.in_kwarg = val[0]
2542
+ result = @builder.args(nil, val[1], nil)
2543
+ }
2544
+
2545
+ args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
2546
+ {
2547
+ result = val[0].concat(val[2]).concat(val[3])
2548
+ }
2549
+ | f_kwarg opt_f_block_arg
2550
+ {
2551
+ result = val[0].concat(val[1])
2552
+ }
2553
+ | f_kwrest opt_f_block_arg
2554
+ {
2555
+ result = val[0].concat(val[1])
2556
+ }
2557
+ | f_no_kwarg opt_f_block_arg
2558
+ {
2559
+ result = val[0].concat(val[1])
2560
+ }
2561
+ | f_block_arg
2562
+ {
2563
+ result = [ val[0] ]
2564
+ }
2565
+
2566
+ opt_args_tail: tCOMMA args_tail
2567
+ {
2568
+ result = val[1]
2569
+ }
2570
+ | # nothing
2571
+ {
2572
+ result = []
2573
+ }
2574
+
2575
+ f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
2576
+ {
2577
+ result = val[0].
2578
+ concat(val[2]).
2579
+ concat(val[4]).
2580
+ concat(val[5])
2581
+ }
2582
+ | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2583
+ {
2584
+ result = val[0].
2585
+ concat(val[2]).
2586
+ concat(val[4]).
2587
+ concat(val[6]).
2588
+ concat(val[7])
2589
+ }
2590
+ | f_arg tCOMMA f_optarg opt_args_tail
2591
+ {
2592
+ result = val[0].
2593
+ concat(val[2]).
2594
+ concat(val[3])
2595
+ }
2596
+ | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
2597
+ {
2598
+ result = val[0].
2599
+ concat(val[2]).
2600
+ concat(val[4]).
2601
+ concat(val[5])
2602
+ }
2603
+ | f_arg tCOMMA f_rest_arg opt_args_tail
2604
+ {
2605
+ result = val[0].
2606
+ concat(val[2]).
2607
+ concat(val[3])
2608
+ }
2609
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2610
+ {
2611
+ result = val[0].
2612
+ concat(val[2]).
2613
+ concat(val[4]).
2614
+ concat(val[5])
2615
+ }
2616
+ | f_arg opt_args_tail
2617
+ {
2618
+ result = val[0].
2619
+ concat(val[1])
2620
+ }
2621
+ | f_optarg tCOMMA f_rest_arg opt_args_tail
2622
+ {
2623
+ result = val[0].
2624
+ concat(val[2]).
2625
+ concat(val[3])
2626
+ }
2627
+ | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2628
+ {
2629
+ result = val[0].
2630
+ concat(val[2]).
2631
+ concat(val[4]).
2632
+ concat(val[5])
2633
+ }
2634
+ | f_optarg opt_args_tail
2635
+ {
2636
+ result = val[0].
2637
+ concat(val[1])
2638
+ }
2639
+ | f_optarg tCOMMA f_arg opt_args_tail
2640
+ {
2641
+ result = val[0].
2642
+ concat(val[2]).
2643
+ concat(val[3])
2644
+ }
2645
+ | f_rest_arg opt_args_tail
2646
+ {
2647
+ result = val[0].
2648
+ concat(val[1])
2649
+ }
2650
+ | f_rest_arg tCOMMA f_arg opt_args_tail
2651
+ {
2652
+ result = val[0].
2653
+ concat(val[2]).
2654
+ concat(val[3])
2655
+ }
2656
+ | args_tail
2657
+ {
2658
+ result = val[0]
2659
+ }
2660
+ | # nothing
2661
+ {
2662
+ result = []
2663
+ }
2664
+
2665
+ args_forward: tBDOT3
2666
+ {
2667
+ result = val[0]
2668
+ }
2669
+
2670
+ f_bad_arg: tCONSTANT
2671
+ {
2672
+ diagnostic :error, :argument_const, nil, val[0]
2673
+ }
2674
+ | tIVAR
2675
+ {
2676
+ diagnostic :error, :argument_ivar, nil, val[0]
2677
+ }
2678
+ | tGVAR
2679
+ {
2680
+ diagnostic :error, :argument_gvar, nil, val[0]
2681
+ }
2682
+ | tCVAR
2683
+ {
2684
+ diagnostic :error, :argument_cvar, nil, val[0]
2685
+ }
2686
+
2687
+ f_norm_arg: f_bad_arg
2688
+ | tIDENTIFIER
2689
+ {
2690
+ @static_env.declare val[0][0]
2691
+
2692
+ @max_numparam_stack.has_ordinary_params!
2693
+
2694
+ result = val[0]
2695
+ }
2696
+
2697
+ f_arg_asgn: f_norm_arg
2698
+ {
2699
+ @current_arg_stack.set(val[0][0])
2700
+ result = val[0]
2701
+ }
2702
+
2703
+ f_arg_item: f_arg_asgn
2704
+ {
2705
+ @current_arg_stack.set(0)
2706
+ result = @builder.arg(val[0])
2707
+ }
2708
+ | tLPAREN f_margs rparen
2709
+ {
2710
+ result = @builder.multi_lhs(val[0], val[1], val[2])
2711
+ }
2712
+
2713
+ f_arg: f_arg_item
2714
+ {
2715
+ result = [ val[0] ]
2716
+ }
2717
+ | f_arg tCOMMA f_arg_item
2718
+ {
2719
+ result = val[0] << val[2]
2720
+ }
2721
+
2722
+ f_label: tLABEL
2723
+ {
2724
+ check_kwarg_name(val[0])
2725
+
2726
+ @static_env.declare val[0][0]
2727
+
2728
+ @max_numparam_stack.has_ordinary_params!
2729
+
2730
+ @current_arg_stack.set(val[0][0])
2731
+
2732
+ result = val[0]
2733
+ }
2734
+
2735
+ f_kw: f_label arg_value
2736
+ {
2737
+ @current_arg_stack.set(nil)
2738
+ result = @builder.kwoptarg(val[0], val[1])
2739
+ }
2740
+ | f_label
2741
+ {
2742
+ @current_arg_stack.set(nil)
2743
+ result = @builder.kwarg(val[0])
2744
+ }
2745
+
2746
+ f_block_kw: f_label primary_value
2747
+ {
2748
+ result = @builder.kwoptarg(val[0], val[1])
2749
+ }
2750
+ | f_label
2751
+ {
2752
+ result = @builder.kwarg(val[0])
2753
+ }
2754
+
2755
+ f_block_kwarg: f_block_kw
2756
+ {
2757
+ result = [ val[0] ]
2758
+ }
2759
+ | f_block_kwarg tCOMMA f_block_kw
2760
+ {
2761
+ result = val[0] << val[2]
2762
+ }
2763
+
2764
+ f_kwarg: f_kw
2765
+ {
2766
+ result = [ val[0] ]
2767
+ }
2768
+ | f_kwarg tCOMMA f_kw
2769
+ {
2770
+ result = val[0] << val[2]
2771
+ }
2772
+
2773
+ kwrest_mark: tPOW | tDSTAR
2774
+
2775
+ f_no_kwarg: kwrest_mark kNIL
2776
+ {
2777
+ result = [ @builder.kwnilarg(val[0], val[1]) ]
2778
+ }
2779
+
2780
+ f_kwrest: kwrest_mark tIDENTIFIER
2781
+ {
2782
+ @static_env.declare val[1][0]
2783
+
2784
+ result = [ @builder.kwrestarg(val[0], val[1]) ]
2785
+ }
2786
+ | kwrest_mark
2787
+ {
2788
+ result = [ @builder.kwrestarg(val[0]) ]
2789
+ }
2790
+
2791
+ f_opt: f_arg_asgn tEQL arg_value
2792
+ {
2793
+ @current_arg_stack.set(0)
2794
+ result = @builder.optarg(val[0], val[1], val[2])
2795
+ }
2796
+
2797
+ f_block_opt: f_arg_asgn tEQL primary_value
2798
+ {
2799
+ @current_arg_stack.set(0)
2800
+ result = @builder.optarg(val[0], val[1], val[2])
2801
+ }
2802
+
2803
+ f_block_optarg: f_block_opt
2804
+ {
2805
+ result = [ val[0] ]
2806
+ }
2807
+ | f_block_optarg tCOMMA f_block_opt
2808
+ {
2809
+ result = val[0] << val[2]
2810
+ }
2811
+
2812
+ f_optarg: f_opt
2813
+ {
2814
+ result = [ val[0] ]
2815
+ }
2816
+ | f_optarg tCOMMA f_opt
2817
+ {
2818
+ result = val[0] << val[2]
2819
+ }
2820
+
2821
+ restarg_mark: tSTAR2 | tSTAR
2822
+
2823
+ f_rest_arg: restarg_mark tIDENTIFIER
2824
+ {
2825
+ @static_env.declare val[1][0]
2826
+
2827
+ result = [ @builder.restarg(val[0], val[1]) ]
2828
+ }
2829
+ | restarg_mark
2830
+ {
2831
+ result = [ @builder.restarg(val[0]) ]
2832
+ }
2833
+
2834
+ blkarg_mark: tAMPER2 | tAMPER
2835
+
2836
+ f_block_arg: blkarg_mark tIDENTIFIER
2837
+ {
2838
+ @static_env.declare val[1][0]
2839
+
2840
+ result = @builder.blockarg(val[0], val[1])
2841
+ }
2842
+
2843
+ opt_f_block_arg: tCOMMA f_block_arg
2844
+ {
2845
+ result = [ val[1] ]
2846
+ }
2847
+ |
2848
+ {
2849
+ result = []
2850
+ }
2851
+
2852
+ singleton: var_ref
2853
+ | tLPAREN2 expr rparen
2854
+ {
2855
+ result = val[1]
2856
+ }
2857
+
2858
+ assoc_list: # nothing
2859
+ {
2860
+ result = []
2861
+ }
2862
+ | assocs trailer
2863
+
2864
+ assocs: assoc
2865
+ {
2866
+ result = [ val[0] ]
2867
+ }
2868
+ | assocs tCOMMA assoc
2869
+ {
2870
+ result = val[0] << val[2]
2871
+ }
2872
+
2873
+ assoc: arg_value tASSOC arg_value
2874
+ {
2875
+ result = @builder.pair(val[0], val[1], val[2])
2876
+ }
2877
+ | tLABEL arg_value
2878
+ {
2879
+ result = @builder.pair_keyword(val[0], val[1])
2880
+ }
2881
+ | tSTRING_BEG string_contents tLABEL_END arg_value
2882
+ {
2883
+ result = @builder.pair_quoted(val[0], val[1], val[2], val[3])
2884
+ }
2885
+ | tDSTAR arg_value
2886
+ {
2887
+ result = @builder.kwsplat(val[0], val[1])
2888
+ }
2889
+
2890
+ operation: tIDENTIFIER | tCONSTANT | tFID
2891
+ operation2: tIDENTIFIER | tCONSTANT | tFID | op
2892
+ operation3: tIDENTIFIER | tFID | op
2893
+ dot_or_colon: call_op | tCOLON2
2894
+ call_op: tDOT
2895
+ {
2896
+ result = [:dot, val[0][1]]
2897
+ }
2898
+ | tANDDOT
2899
+ {
2900
+ result = [:anddot, val[0][1]]
2901
+ }
2902
+ opt_terms: | terms
2903
+ opt_nl: | tNL
2904
+ rparen: opt_nl tRPAREN
2905
+ {
2906
+ result = val[1]
2907
+ }
2908
+ rbracket: opt_nl tRBRACK
2909
+ {
2910
+ result = val[1]
2911
+ }
2912
+ rbrace: opt_nl tRCURLY
2913
+ {
2914
+ result = val[1]
2915
+ }
2916
+ trailer: | tNL | tCOMMA
2917
+
2918
+ term: tSEMI
2919
+ {
2920
+ yyerrok
2921
+ }
2922
+ | tNL
2923
+
2924
+ terms: term
2925
+ | terms tSEMI
2926
+
2927
+ none: # nothing
2928
+ {
2929
+ result = nil
2930
+ }
2931
+ end
2932
+
2933
+ ---- header
2934
+
2935
+ require 'parser'
2936
+ require 'parser/ruby-next/parser_ext'
2937
+
2938
+ ---- inner
2939
+
2940
+ prepend Parser::NextExt
2941
+
2942
+ def version
2943
+ 28 # the master Ruby version
2944
+ end
2945
+
2946
+ def default_encoding
2947
+ Encoding::UTF_8
2948
+ end