parser 0.9.1 → 0.9.2

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