racc 1.4.14 → 1.4.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/Manifest.txt +50 -0
  3. data/ext/racc/com/headius/racc/Cparse.java +66 -23
  4. data/ext/racc/cparse.c +1 -1
  5. data/ext/racc/depend +1 -1
  6. data/lib/racc/info.rb +2 -2
  7. data/test/assets/bibtex.y +141 -0
  8. data/test/assets/cadenza.y +170 -0
  9. data/test/assets/cast.y +926 -0
  10. data/test/assets/csspool.y +729 -0
  11. data/test/assets/edtf.y +583 -0
  12. data/test/assets/huia.y +318 -0
  13. data/test/assets/journey.y +47 -0
  14. data/test/assets/liquor.y +313 -0
  15. data/test/assets/machete.y +423 -0
  16. data/test/assets/macruby.y +2197 -0
  17. data/test/assets/mediacloth.y +599 -0
  18. data/test/assets/mof.y +649 -0
  19. data/test/assets/namae.y +302 -0
  20. data/test/assets/nasl.y +626 -0
  21. data/test/assets/nokogiri-css.y +255 -0
  22. data/test/assets/opal.y +1807 -0
  23. data/test/assets/php_serialization.y +98 -0
  24. data/test/assets/rdblockparser.y +576 -0
  25. data/test/assets/rdinlineparser.y +561 -0
  26. data/test/assets/riml.y +665 -0
  27. data/test/assets/ruby18.y +1943 -0
  28. data/test/assets/ruby19.y +2174 -0
  29. data/test/assets/ruby20.y +2350 -0
  30. data/test/assets/ruby21.y +2359 -0
  31. data/test/assets/ruby22.y +2381 -0
  32. data/test/assets/tp_plus.y +622 -0
  33. data/test/assets/twowaysql.y +278 -0
  34. data/test/helper.rb +31 -15
  35. data/test/regress/bibtex +474 -0
  36. data/test/regress/cadenza +796 -0
  37. data/test/regress/cast +3425 -0
  38. data/test/regress/csspool +2318 -0
  39. data/test/regress/edtf +1794 -0
  40. data/test/regress/huia +1392 -0
  41. data/test/regress/journey +222 -0
  42. data/test/regress/liquor +885 -0
  43. data/test/regress/machete +833 -0
  44. data/test/regress/mediacloth +1463 -0
  45. data/test/regress/mof +1368 -0
  46. data/test/regress/namae +634 -0
  47. data/test/regress/nasl +2058 -0
  48. data/test/regress/nokogiri-css +836 -0
  49. data/test/regress/opal +6429 -0
  50. data/test/regress/php_serialization +336 -0
  51. data/test/regress/rdblockparser +1061 -0
  52. data/test/regress/rdinlineparser +1243 -0
  53. data/test/regress/riml +3297 -0
  54. data/test/regress/ruby18 +6351 -0
  55. data/test/regress/ruby22 +7456 -0
  56. data/test/regress/tp_plus +1933 -0
  57. data/test/regress/twowaysql +556 -0
  58. data/test/test_racc_command.rb +177 -0
  59. metadata +75 -20
@@ -0,0 +1,1943 @@
1
+ # Copyright (c) 2013 Peter Zotov <whitequark@whitequark.org>
2
+ #
3
+ # Parts of the source are derived from ruby_parser:
4
+ # Copyright (c) Ryan Davis, seattle.rb
5
+ #
6
+ # MIT License
7
+ #
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to
13
+ # permit persons to whom the Software is furnished to do so, subject to
14
+ # the following conditions:
15
+ #
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+ #
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ class Parser::Ruby18
28
+
29
+ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
30
+ kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
31
+ kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kRETURN kYIELD kSUPER
32
+ kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
33
+ kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
34
+ k__FILE__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tNTH_REF
35
+ tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT tREGEXP_END tUPLUS
36
+ tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ tGEQ tLEQ tANDOP
37
+ tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF tASET tLSHFT tRSHFT
38
+ tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN tLPAREN2 tRPAREN tLPAREN_ARG
39
+ tLBRACK tLBRACK2 tRBRACK tLBRACE tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2
40
+ tTILDE tPERCENT tDIVIDE tPLUS tMINUS tLT tGT tPIPE tBANG tCARET
41
+ tLCURLY tRCURLY tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
42
+ tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
43
+ tSYMBOL tREGEXP_OPT tNL tEH tCOLON tCOMMA tSPACE tSEMI
44
+
45
+ prechigh
46
+ right tBANG tTILDE tUPLUS
47
+ right tPOW
48
+ right tUMINUS_NUM tUMINUS
49
+ left tSTAR2 tDIVIDE tPERCENT
50
+ left tPLUS tMINUS
51
+ left tLSHFT tRSHFT
52
+ left tAMPER2
53
+ left tPIPE tCARET
54
+ left tGT tGEQ tLT tLEQ
55
+ nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
56
+ left tANDOP
57
+ left tOROP
58
+ nonassoc tDOT2 tDOT3
59
+ right tEH tCOLON
60
+ left kRESCUE_MOD
61
+ right tEQL tOP_ASGN
62
+ nonassoc kDEFINED
63
+ right kNOT
64
+ left kOR kAND
65
+ nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
66
+ nonassoc tLBRACE_ARG
67
+ nonassoc tLOWEST
68
+ preclow
69
+
70
+ rule
71
+
72
+ program: compstmt
73
+ {
74
+ result = val[0]
75
+ }
76
+
77
+ bodystmt: compstmt opt_rescue opt_else opt_ensure
78
+ {
79
+ rescue_bodies = val[1]
80
+ else_t, else_ = val[2]
81
+ ensure_t, ensure_ = val[3]
82
+
83
+ if rescue_bodies.empty? && !else_.nil?
84
+ diagnostic :warning, :useless_else, nil, else_t
85
+ end
86
+
87
+ result = @builder.begin_body(val[0],
88
+ rescue_bodies,
89
+ else_t, else_,
90
+ ensure_t, ensure_)
91
+ }
92
+
93
+ compstmt: stmts opt_terms
94
+ {
95
+ result = @builder.compstmt(val[0])
96
+ }
97
+
98
+ stmts: # nothing
99
+ {
100
+ result = []
101
+ }
102
+ | stmt
103
+ {
104
+ result = [ val[0] ]
105
+ }
106
+ | error stmt
107
+ {
108
+ result = [ val[1] ]
109
+ }
110
+ | stmts terms stmt
111
+ {
112
+ result = val[0] << val[2]
113
+ }
114
+
115
+ stmt: kALIAS fitem
116
+ {
117
+ @lexer.state = :expr_fname
118
+ }
119
+ fitem
120
+ {
121
+ result = @builder.alias(val[0], val[1], val[3])
122
+ }
123
+ | kALIAS tGVAR tGVAR
124
+ {
125
+ result = @builder.alias(val[0],
126
+ @builder.gvar(val[1]),
127
+ @builder.gvar(val[2]))
128
+ }
129
+ | kALIAS tGVAR tBACK_REF
130
+ {
131
+ result = @builder.alias(val[0],
132
+ @builder.gvar(val[1]),
133
+ @builder.back_ref(val[2]))
134
+ }
135
+ | kALIAS tGVAR tNTH_REF
136
+ {
137
+ diagnostic :error, :nth_ref_alias, nil, val[2]
138
+ }
139
+ | kUNDEF undef_list
140
+ {
141
+ result = @builder.undef_method(val[0], val[1])
142
+ }
143
+ | stmt kIF_MOD expr_value
144
+ {
145
+ result = @builder.condition_mod(val[0], nil,
146
+ val[1], val[2])
147
+ }
148
+ | stmt kUNLESS_MOD expr_value
149
+ {
150
+ result = @builder.condition_mod(nil, val[0],
151
+ val[1], val[2])
152
+ }
153
+ | stmt kWHILE_MOD expr_value
154
+ {
155
+ result = @builder.loop_mod(:while, val[0], val[1], val[2])
156
+ }
157
+ | stmt kUNTIL_MOD expr_value
158
+ {
159
+ result = @builder.loop_mod(:until, val[0], val[1], val[2])
160
+ }
161
+ | stmt kRESCUE_MOD stmt
162
+ {
163
+ rescue_body = @builder.rescue_body(val[1],
164
+ nil, nil, nil,
165
+ nil, val[2])
166
+
167
+ result = @builder.begin_body(val[0], [ rescue_body ])
168
+ }
169
+ | klBEGIN tLCURLY compstmt tRCURLY
170
+ {
171
+ if in_def?
172
+ diagnostic :error, :begin_in_method, nil, val[0]
173
+ end
174
+
175
+ result = @builder.preexe(val[0], val[1], val[2], val[3])
176
+ }
177
+ | klEND tLCURLY compstmt tRCURLY
178
+ {
179
+ result = @builder.postexe(val[0], val[1], val[2], val[3])
180
+ }
181
+ | lhs tEQL command_call
182
+ {
183
+ result = @builder.assign(val[0], val[1], val[2])
184
+ }
185
+ | mlhs tEQL command_call
186
+ {
187
+ result = @builder.multi_assign(val[0], val[1], val[2])
188
+ }
189
+ | var_lhs tOP_ASGN command_call
190
+ {
191
+ result = @builder.op_assign(val[0], val[1], val[2])
192
+ }
193
+ | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN command_call
194
+ {
195
+ result = @builder.op_assign(
196
+ @builder.index(
197
+ val[0], val[1], val[2], val[3]),
198
+ val[4], val[5])
199
+ }
200
+ | primary_value tDOT tIDENTIFIER tOP_ASGN command_call
201
+ {
202
+ result = @builder.op_assign(
203
+ @builder.call_method(
204
+ val[0], val[1], val[2]),
205
+ val[3], val[4])
206
+ }
207
+ | primary_value tDOT tCONSTANT tOP_ASGN command_call
208
+ {
209
+ result = @builder.op_assign(
210
+ @builder.call_method(
211
+ val[0], val[1], val[2]),
212
+ val[3], val[4])
213
+ }
214
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
215
+ {
216
+ result = @builder.op_assign(
217
+ @builder.call_method(
218
+ val[0], val[1], val[2]),
219
+ val[3], val[4])
220
+ }
221
+ | backref tOP_ASGN command_call
222
+ {
223
+ @builder.op_assign(val[0], val[1], val[2])
224
+ }
225
+ | lhs tEQL mrhs
226
+ {
227
+ result = @builder.assign(val[0], val[1],
228
+ @builder.array(nil, val[2], nil))
229
+ }
230
+ | mlhs tEQL arg_value
231
+ {
232
+ result = @builder.multi_assign(val[0], val[1], val[2])
233
+ }
234
+ | mlhs tEQL mrhs
235
+ {
236
+ result = @builder.multi_assign(val[0], val[1],
237
+ @builder.array(nil, val[2], nil))
238
+ }
239
+ | expr
240
+
241
+ expr: command_call
242
+ | expr kAND expr
243
+ {
244
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
245
+ }
246
+ | expr kOR expr
247
+ {
248
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
249
+ }
250
+ | kNOT expr
251
+ {
252
+ result = @builder.not_op(val[0], nil, val[1], nil)
253
+ }
254
+ | tBANG command_call
255
+ {
256
+ result = @builder.not_op(val[0], nil, val[1], nil)
257
+ }
258
+ | arg
259
+
260
+ expr_value: expr
261
+
262
+ command_call: command
263
+ | block_command
264
+ | kRETURN call_args
265
+ {
266
+ result = @builder.keyword_cmd(:return, val[0],
267
+ nil, val[1], nil)
268
+ }
269
+ | kBREAK call_args
270
+ {
271
+ result = @builder.keyword_cmd(:break, val[0],
272
+ nil, val[1], nil)
273
+ }
274
+ | kNEXT call_args
275
+ {
276
+ result = @builder.keyword_cmd(:next, val[0],
277
+ nil, val[1], nil)
278
+ }
279
+
280
+ block_command: block_call
281
+ | block_call tDOT operation2 command_args
282
+ {
283
+ lparen_t, args, rparen_t = val[3]
284
+ result = @builder.call_method(val[0], val[1], val[2],
285
+ lparen_t, args, rparen_t)
286
+ }
287
+ | block_call tCOLON2 operation2 command_args
288
+ {
289
+ lparen_t, args, rparen_t = val[3]
290
+ result = @builder.call_method(val[0], val[1], val[2],
291
+ lparen_t, args, rparen_t)
292
+ }
293
+
294
+ cmd_brace_block: tLBRACE_ARG
295
+ {
296
+ @static_env.extend_dynamic
297
+ }
298
+ opt_block_var compstmt tRCURLY
299
+ {
300
+ result = [ val[0], val[2], val[3], val[4] ]
301
+
302
+ @static_env.unextend
303
+ }
304
+
305
+ command: operation command_args =tLOWEST
306
+ {
307
+ lparen_t, args, rparen_t = val[1]
308
+ result = @builder.call_method(nil, nil, val[0],
309
+ lparen_t, args, rparen_t)
310
+ }
311
+ | operation command_args cmd_brace_block
312
+ {
313
+ lparen_t, args, rparen_t = val[1]
314
+ method_call = @builder.call_method(nil, nil, val[0],
315
+ lparen_t, args, rparen_t)
316
+
317
+ begin_t, block_args, body, end_t = val[2]
318
+ result = @builder.block(method_call,
319
+ begin_t, block_args, body, end_t)
320
+ }
321
+ | primary_value tDOT operation2 command_args =tLOWEST
322
+ {
323
+ lparen_t, args, rparen_t = val[3]
324
+ result = @builder.call_method(val[0], val[1], val[2],
325
+ lparen_t, args, rparen_t)
326
+
327
+ }
328
+ | primary_value tDOT operation2 command_args cmd_brace_block
329
+ {
330
+ lparen_t, args, rparen_t = val[3]
331
+ method_call = @builder.call_method(val[0], val[1], val[2],
332
+ lparen_t, args, rparen_t)
333
+
334
+ begin_t, block_args, body, end_t = val[4]
335
+ result = @builder.block(method_call,
336
+ begin_t, block_args, body, end_t)
337
+ }
338
+ | primary_value tCOLON2 operation2 command_args =tLOWEST
339
+ {
340
+ lparen_t, args, rparen_t = val[3]
341
+ result = @builder.call_method(val[0], val[1], val[2],
342
+ lparen_t, args, rparen_t)
343
+ }
344
+ | primary_value tCOLON2 operation2 command_args cmd_brace_block
345
+ {
346
+ lparen_t, args, rparen_t = val[3]
347
+ method_call = @builder.call_method(val[0], val[1], val[2],
348
+ lparen_t, args, rparen_t)
349
+
350
+ begin_t, block_args, body, end_t = val[4]
351
+ result = @builder.block(method_call,
352
+ begin_t, block_args, body, end_t)
353
+ }
354
+ | kSUPER command_args
355
+ {
356
+ lparen_t, args, rparen_t = val[1]
357
+ result = @builder.keyword_cmd(:super, val[0],
358
+ lparen_t, args, rparen_t)
359
+ }
360
+ | kYIELD command_args
361
+ {
362
+ lparen_t, args, rparen_t = val[1]
363
+ result = @builder.keyword_cmd(:yield, val[0],
364
+ lparen_t, args, rparen_t)
365
+ }
366
+
367
+ mlhs: mlhs_basic
368
+ {
369
+ result = @builder.multi_lhs(nil, val[0], nil)
370
+ }
371
+ | tLPAREN mlhs_entry tRPAREN
372
+ {
373
+ result = @builder.begin(val[0], val[1], val[2])
374
+ }
375
+
376
+ mlhs_entry: mlhs_basic
377
+ {
378
+ result = @builder.multi_lhs(nil, val[0], nil)
379
+ }
380
+ | tLPAREN mlhs_entry tRPAREN
381
+ {
382
+ result = @builder.multi_lhs(val[0], val[1], val[2])
383
+ }
384
+
385
+ mlhs_basic: mlhs_head
386
+ {
387
+ result = val[0]
388
+ }
389
+ | mlhs_head mlhs_item
390
+ {
391
+ result = val[0] << val[1]
392
+ }
393
+ | mlhs_head tSTAR mlhs_node
394
+ {
395
+ result = val[0] << @builder.splat(val[1], val[2])
396
+ }
397
+ | mlhs_head tSTAR
398
+ {
399
+ result = val[0] << @builder.splat(val[1])
400
+ }
401
+ | tSTAR mlhs_node
402
+ {
403
+ result = [ @builder.splat(val[0], val[1]) ]
404
+ }
405
+ | tSTAR
406
+ {
407
+ result = [ @builder.splat(val[0]) ]
408
+ }
409
+
410
+ mlhs_item: mlhs_node
411
+ | tLPAREN mlhs_entry tRPAREN
412
+ {
413
+ result = @builder.begin(val[0], val[1], val[2])
414
+ }
415
+
416
+ mlhs_head: mlhs_item tCOMMA
417
+ {
418
+ result = [ val[0] ]
419
+ }
420
+ | mlhs_head mlhs_item tCOMMA
421
+ {
422
+ result = val[0] << val[1]
423
+ }
424
+
425
+ mlhs_node: variable
426
+ {
427
+ result = @builder.assignable(val[0])
428
+ }
429
+ | primary_value tLBRACK2 aref_args tRBRACK
430
+ {
431
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
432
+ }
433
+ | primary_value tDOT tIDENTIFIER
434
+ {
435
+ result = @builder.attr_asgn(val[0], val[1], val[2])
436
+ }
437
+ | primary_value tCOLON2 tIDENTIFIER
438
+ {
439
+ result = @builder.attr_asgn(val[0], val[1], val[2])
440
+ }
441
+ | primary_value tDOT tCONSTANT
442
+ {
443
+ result = @builder.attr_asgn(val[0], val[1], val[2])
444
+ }
445
+ | primary_value tCOLON2 tCONSTANT
446
+ {
447
+ result = @builder.assignable(
448
+ @builder.const_fetch(val[0], val[1], val[2]))
449
+ }
450
+ | tCOLON3 tCONSTANT
451
+ {
452
+ result = @builder.assignable(
453
+ @builder.const_global(val[0], val[1]))
454
+ }
455
+ | backref
456
+ {
457
+ result = @builder.assignable(val[0])
458
+ }
459
+
460
+ lhs: variable
461
+ {
462
+ result = @builder.assignable(val[0])
463
+ }
464
+ | primary_value tLBRACK2 aref_args tRBRACK
465
+ {
466
+ result = @builder.index_asgn(val[0], val[1], val[2], val[3])
467
+ }
468
+ | primary_value tDOT tIDENTIFIER
469
+ {
470
+ result = @builder.attr_asgn(val[0], val[1], val[2])
471
+ }
472
+ | primary_value tCOLON2 tIDENTIFIER
473
+ {
474
+ result = @builder.attr_asgn(val[0], val[1], val[2])
475
+ }
476
+ | primary_value tDOT tCONSTANT
477
+ {
478
+ result = @builder.attr_asgn(val[0], val[1], val[2])
479
+ }
480
+ | primary_value tCOLON2 tCONSTANT
481
+ {
482
+ result = @builder.assignable(
483
+ @builder.const_fetch(val[0], val[1], val[2]))
484
+ }
485
+ | tCOLON3 tCONSTANT
486
+ {
487
+ result = @builder.assignable(
488
+ @builder.const_global(val[0], val[1]))
489
+ }
490
+ | backref
491
+ {
492
+ result = @builder.assignable(val[0])
493
+ }
494
+
495
+ cname: tIDENTIFIER
496
+ {
497
+ diagnostic :error, :module_name_const, nil, val[0]
498
+ }
499
+ | tCONSTANT
500
+
501
+ cpath: tCOLON3 cname
502
+ {
503
+ result = @builder.const_global(val[0], val[1])
504
+ }
505
+ | cname
506
+ {
507
+ result = @builder.const(val[0])
508
+ }
509
+ | primary_value tCOLON2 cname
510
+ {
511
+ result = @builder.const_fetch(val[0], val[1], val[2])
512
+ }
513
+
514
+ fname: tIDENTIFIER | tCONSTANT | tFID
515
+ | op
516
+ | reswords
517
+
518
+ fsym: fname
519
+ {
520
+ result = @builder.symbol(val[0])
521
+ }
522
+ | symbol
523
+
524
+ fitem: fsym
525
+ | dsym
526
+
527
+ undef_list: fitem
528
+ {
529
+ result = [ val[0] ]
530
+ }
531
+ | undef_list tCOMMA
532
+ {
533
+ @lexer.state = :expr_fname
534
+ }
535
+ fitem
536
+ {
537
+ result = val[0] << val[3]
538
+ }
539
+
540
+ op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
541
+ | tMATCH | tGT | tGEQ | tLT | tLEQ | tLSHFT
542
+ | tRSHFT | tPLUS | tMINUS | tSTAR2 | tSTAR | tDIVIDE
543
+ | tPERCENT | tPOW | tTILDE | tUPLUS | tUMINUS | tAREF
544
+ | tASET | tBACK_REF2
545
+
546
+ reswords: k__LINE__ | k__FILE__ | klBEGIN | klEND | kALIAS | kAND
547
+ | kBEGIN | kBREAK | kCASE | kCLASS | kDEF | kDEFINED
548
+ | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
549
+ | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
550
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF
551
+ | kSUPER | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
552
+ | kIF | kUNLESS | kWHILE | kUNTIL
553
+
554
+ arg: lhs tEQL arg
555
+ {
556
+ result = @builder.assign(val[0], val[1], val[2])
557
+ }
558
+ | lhs tEQL arg kRESCUE_MOD arg
559
+ {
560
+ rescue_body = @builder.rescue_body(val[3],
561
+ nil, nil, nil,
562
+ nil, val[4])
563
+
564
+ rescue_ = @builder.begin_body(val[2], [ rescue_body ])
565
+
566
+ result = @builder.assign(val[0], val[1], rescue_)
567
+ }
568
+ | var_lhs tOP_ASGN arg
569
+ {
570
+ result = @builder.op_assign(val[0], val[1], val[2])
571
+ }
572
+ | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN arg
573
+ {
574
+ result = @builder.op_assign(
575
+ @builder.index(
576
+ val[0], val[1], val[2], val[3]),
577
+ val[4], val[5])
578
+ }
579
+ | primary_value tDOT tIDENTIFIER tOP_ASGN arg
580
+ {
581
+ result = @builder.op_assign(
582
+ @builder.call_method(
583
+ val[0], val[1], val[2]),
584
+ val[3], val[4])
585
+ }
586
+ | primary_value tDOT tCONSTANT tOP_ASGN arg
587
+ {
588
+ result = @builder.op_assign(
589
+ @builder.call_method(
590
+ val[0], val[1], val[2]),
591
+ val[3], val[4])
592
+ }
593
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
594
+ {
595
+ result = @builder.op_assign(
596
+ @builder.call_method(
597
+ val[0], val[1], val[2]),
598
+ val[3], val[4])
599
+ }
600
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
601
+ {
602
+ diagnostic :error, :dynamic_const, nil, val[2], [ val[3] ]
603
+ }
604
+ | tCOLON3 tCONSTANT tOP_ASGN arg
605
+ {
606
+ diagnostic :error, :dynamic_const, nil, val[1], [ val[2] ]
607
+ }
608
+ | backref tOP_ASGN arg
609
+ {
610
+ result = @builder.op_assign(val[0], val[1], val[2])
611
+ }
612
+ | arg tDOT2 arg
613
+ {
614
+ result = @builder.range_inclusive(val[0], val[1], val[2])
615
+ }
616
+ | arg tDOT3 arg
617
+ {
618
+ result = @builder.range_exclusive(val[0], val[1], val[2])
619
+ }
620
+ | arg tPLUS arg
621
+ {
622
+ result = @builder.binary_op(val[0], val[1], val[2])
623
+ }
624
+ | arg tMINUS arg
625
+ {
626
+ result = @builder.binary_op(val[0], val[1], val[2])
627
+ }
628
+ | arg tSTAR2 arg
629
+ {
630
+ result = @builder.binary_op(val[0], val[1], val[2])
631
+ }
632
+ | arg tDIVIDE arg
633
+ {
634
+ result = @builder.binary_op(val[0], val[1], val[2])
635
+ }
636
+ | arg tPERCENT arg
637
+ {
638
+ result = @builder.binary_op(val[0], val[1], val[2])
639
+ }
640
+ | arg tPOW arg
641
+ {
642
+ result = @builder.binary_op(val[0], val[1], val[2])
643
+ }
644
+ | tUMINUS_NUM tINTEGER tPOW arg
645
+ {
646
+ result = @builder.unary_op(val[0],
647
+ @builder.binary_op(
648
+ @builder.integer(val[1]),
649
+ val[2], val[3]))
650
+ }
651
+ | tUMINUS_NUM tFLOAT tPOW arg
652
+ {
653
+ result = @builder.unary_op(val[0],
654
+ @builder.binary_op(
655
+ @builder.float(val[1]),
656
+ val[2], val[3]))
657
+ }
658
+ | tUPLUS arg
659
+ {
660
+ result = @builder.unary_op(val[0], val[1])
661
+ }
662
+ | tUMINUS arg
663
+ {
664
+ result = @builder.unary_op(val[0], val[1])
665
+ }
666
+ | arg tPIPE arg
667
+ {
668
+ result = @builder.binary_op(val[0], val[1], val[2])
669
+ }
670
+ | arg tCARET arg
671
+ {
672
+ result = @builder.binary_op(val[0], val[1], val[2])
673
+ }
674
+ | arg tAMPER2 arg
675
+ {
676
+ result = @builder.binary_op(val[0], val[1], val[2])
677
+ }
678
+ | arg tCMP arg
679
+ {
680
+ result = @builder.binary_op(val[0], val[1], val[2])
681
+ }
682
+ | arg tGT arg
683
+ {
684
+ result = @builder.binary_op(val[0], val[1], val[2])
685
+ }
686
+ | arg tGEQ arg
687
+ {
688
+ result = @builder.binary_op(val[0], val[1], val[2])
689
+ }
690
+ | arg tLT arg
691
+ {
692
+ result = @builder.binary_op(val[0], val[1], val[2])
693
+ }
694
+ | arg tLEQ arg
695
+ {
696
+ result = @builder.binary_op(val[0], val[1], val[2])
697
+ }
698
+ | arg tEQ arg
699
+ {
700
+ result = @builder.binary_op(val[0], val[1], val[2])
701
+ }
702
+ | arg tEQQ arg
703
+ {
704
+ result = @builder.binary_op(val[0], val[1], val[2])
705
+ }
706
+ | arg tNEQ arg
707
+ {
708
+ result = @builder.binary_op(val[0], val[1], val[2])
709
+ }
710
+ | arg tMATCH arg
711
+ {
712
+ result = @builder.binary_op(val[0], val[1], val[2])
713
+ }
714
+ | arg tNMATCH arg
715
+ {
716
+ result = @builder.binary_op(val[0], val[1], val[2])
717
+ }
718
+ | tBANG arg
719
+ {
720
+ result = @builder.not_op(val[0], nil, val[1], nil)
721
+ }
722
+ | tTILDE arg
723
+ {
724
+ result = @builder.unary_op(val[0], val[1])
725
+ }
726
+ | arg tLSHFT arg
727
+ {
728
+ result = @builder.binary_op(val[0], val[1], val[2])
729
+ }
730
+ | arg tRSHFT arg
731
+ {
732
+ result = @builder.binary_op(val[0], val[1], val[2])
733
+ }
734
+ | arg tANDOP arg
735
+ {
736
+ result = @builder.logical_op(:and, val[0], val[1], val[2])
737
+ }
738
+ | arg tOROP arg
739
+ {
740
+ result = @builder.logical_op(:or, val[0], val[1], val[2])
741
+ }
742
+ | kDEFINED opt_nl arg
743
+ {
744
+ result = @builder.keyword_cmd(:defined?, val[0], nil, [ val[2] ], nil)
745
+ }
746
+ | arg tEH arg tCOLON arg
747
+ {
748
+ result = @builder.ternary(val[0], val[1],
749
+ val[2], val[3], val[4])
750
+ }
751
+ | primary
752
+
753
+ arg_value: arg
754
+
755
+ aref_args: none
756
+ | command opt_nl
757
+ {
758
+ result = [ val[0] ]
759
+ }
760
+ | args trailer
761
+ {
762
+ result = val[0]
763
+ }
764
+ | args tCOMMA tSTAR arg opt_nl
765
+ {
766
+ result = val[0] << @builder.splat(val[2], val[3])
767
+ }
768
+ | assocs trailer
769
+ {
770
+ result = [ @builder.associate(nil, val[0], nil) ]
771
+ }
772
+ | tSTAR arg opt_nl
773
+ {
774
+ result = [ @builder.splat(val[0], val[1]) ]
775
+ }
776
+
777
+ paren_args: tLPAREN2 none tRPAREN
778
+ {
779
+ result = [ val[0], [], val[2] ]
780
+ }
781
+ | tLPAREN2 call_args opt_nl tRPAREN
782
+ {
783
+ result = [ val[0], val[1], val[3] ]
784
+ }
785
+ | tLPAREN2 block_call opt_nl tRPAREN
786
+ {
787
+ result = [ val[0], [ val[1] ], val[3] ]
788
+ }
789
+ | tLPAREN2 args tCOMMA block_call opt_nl tRPAREN
790
+ {
791
+ result = [ val[0], val[1] << val[3], val[5] ]
792
+ }
793
+
794
+ opt_paren_args: # nothing
795
+ {
796
+ result = [ nil, [], nil ]
797
+ }
798
+ | paren_args
799
+
800
+ call_args: command
801
+ {
802
+ result = [ val[0] ]
803
+ }
804
+ | args opt_block_arg
805
+ {
806
+ result = val[0].concat(val[1])
807
+ }
808
+ | args tCOMMA tSTAR arg_value opt_block_arg
809
+ {
810
+ result = val[0].concat(
811
+ [ @builder.splat(val[2], val[3]),
812
+ *val[4] ])
813
+ }
814
+ | assocs opt_block_arg
815
+ {
816
+ result = [ @builder.associate(nil, val[0], nil),
817
+ *val[1] ]
818
+ }
819
+ | assocs tCOMMA tSTAR arg_value opt_block_arg
820
+ {
821
+ result = [ @builder.associate(nil, val[0], nil),
822
+ @builder.splat(val[2], val[3]),
823
+ *val[4] ]
824
+ }
825
+ | args tCOMMA assocs opt_block_arg
826
+ {
827
+ result = val[0].concat(
828
+ [ @builder.associate(nil, val[2], nil),
829
+ *val[3] ])
830
+ }
831
+ | args tCOMMA assocs tCOMMA tSTAR arg opt_block_arg
832
+ {
833
+ result = val[0].concat(
834
+ [ @builder.associate(nil, val[2], nil),
835
+ @builder.splat(val[4], val[5]),
836
+ *val[6] ])
837
+ }
838
+ | tSTAR arg_value opt_block_arg
839
+ {
840
+ result = [ @builder.splat(val[0], val[1]),
841
+ *val[2] ]
842
+ }
843
+ | block_arg
844
+ {
845
+ result = [ val[0] ]
846
+ }
847
+
848
+ call_args2: arg_value tCOMMA args opt_block_arg
849
+ {
850
+ result = [ val[0], *val[2].concat(val[3]) ]
851
+ }
852
+ | arg_value tCOMMA block_arg
853
+ {
854
+ result = [ val[0], val[2] ]
855
+ }
856
+ | arg_value tCOMMA tSTAR arg_value opt_block_arg
857
+ {
858
+ result = [ val[0],
859
+ @builder.splat(val[2], val[3]),
860
+ *val[4] ]
861
+ }
862
+ | arg_value tCOMMA args tCOMMA tSTAR arg_value opt_block_arg
863
+ {
864
+ result = [ val[0],
865
+ *val[2].
866
+ push(@builder.splat(val[4], val[5])).
867
+ concat(val[6]) ]
868
+ }
869
+ | assocs opt_block_arg
870
+ {
871
+ result = [ @builder.associate(nil, val[0], nil),
872
+ *val[1] ]
873
+ }
874
+ | assocs tCOMMA tSTAR arg_value opt_block_arg
875
+ {
876
+ result = [ @builder.associate(nil, val[0], nil),
877
+ @builder.splat(val[2], val[3]),
878
+ *val[4] ]
879
+ }
880
+ | arg_value tCOMMA assocs opt_block_arg
881
+ {
882
+ result = [ val[0],
883
+ @builder.associate(nil, val[2], nil),
884
+ *val[3] ]
885
+ }
886
+ | arg_value tCOMMA args tCOMMA assocs opt_block_arg
887
+ {
888
+ result = [ val[0],
889
+ *val[2].
890
+ push(@builder.associate(nil, val[4], nil)).
891
+ concat(val[5]) ]
892
+ }
893
+ | arg_value tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
894
+ {
895
+ result = [ val[0],
896
+ @builder.associate(nil, val[2], nil),
897
+ @builder.splat(val[4], val[5]),
898
+ *val[6] ]
899
+ }
900
+ | arg_value tCOMMA args tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
901
+ {
902
+ result = [ val[0],
903
+ *val[2].
904
+ push(@builder.associate(nil, val[4], nil)).
905
+ push(@builder.splat(val[6], val[7])).
906
+ concat(val[8]) ]
907
+ }
908
+ | tSTAR arg_value opt_block_arg
909
+ {
910
+ result = [ @builder.splat(val[0], val[1]),
911
+ *val[2] ]
912
+ }
913
+ | block_arg
914
+ {
915
+ result = [ val[0] ]
916
+ }
917
+
918
+ command_args: {
919
+ result = @lexer.cmdarg.dup
920
+ @lexer.cmdarg.push(true)
921
+ }
922
+ open_args
923
+ {
924
+ @lexer.cmdarg = val[0]
925
+
926
+ result = val[1]
927
+ }
928
+
929
+ open_args: call_args
930
+ {
931
+ result = [ nil, val[0], nil ]
932
+ }
933
+ | tLPAREN_ARG
934
+ {
935
+ @lexer.state = :expr_endarg
936
+ }
937
+ tRPAREN
938
+ {
939
+ result = [ val[0], [], val[2] ]
940
+ }
941
+ | tLPAREN_ARG call_args2
942
+ {
943
+ @lexer.state = :expr_endarg
944
+ }
945
+ tRPAREN
946
+ {
947
+ result = [ val[0], val[1], val[3] ]
948
+ }
949
+
950
+ block_arg: tAMPER arg_value
951
+ {
952
+ result = @builder.block_pass(val[0], val[1])
953
+ }
954
+
955
+ opt_block_arg: tCOMMA block_arg
956
+ {
957
+ result = [ val[1] ]
958
+ }
959
+ | # nothing
960
+ {
961
+ result = []
962
+ }
963
+
964
+ args: arg_value
965
+ {
966
+ result = [ val[0] ]
967
+ }
968
+ | args tCOMMA arg_value
969
+ {
970
+ result = val[0] << val[2]
971
+ }
972
+
973
+ mrhs: args tCOMMA arg_value
974
+ {
975
+ result = val[0] << val[2]
976
+ }
977
+ | args tCOMMA tSTAR arg_value
978
+ {
979
+ result = val[0] << @builder.splat(val[2], val[3])
980
+ }
981
+ | tSTAR arg_value
982
+ {
983
+ result = [ @builder.splat(val[0], val[1]) ]
984
+ }
985
+
986
+ primary: literal
987
+ | strings
988
+ | xstring
989
+ | regexp
990
+ | words
991
+ | qwords
992
+ | var_ref
993
+ | backref
994
+ | tFID
995
+ {
996
+ result = @builder.call_method(nil, nil, val[0])
997
+ }
998
+ | kBEGIN bodystmt kEND
999
+ {
1000
+ result = @builder.begin_keyword(val[0], val[1], val[2])
1001
+ }
1002
+ | tLPAREN_ARG expr
1003
+ {
1004
+ @lexer.state = :expr_endarg
1005
+ }
1006
+ opt_nl tRPAREN
1007
+ {
1008
+ result = @builder.begin(val[0], val[1], val[4])
1009
+ }
1010
+ | tLPAREN compstmt tRPAREN
1011
+ {
1012
+ result = @builder.begin(val[0], val[1], val[2])
1013
+ }
1014
+ | primary_value tCOLON2 tCONSTANT
1015
+ {
1016
+ result = @builder.const_fetch(val[0], val[1], val[2])
1017
+ }
1018
+ | tCOLON3 tCONSTANT
1019
+ {
1020
+ result = @builder.const_global(val[0], val[1])
1021
+ }
1022
+ | primary_value tLBRACK2 aref_args tRBRACK
1023
+ {
1024
+ result = @builder.index(val[0], val[1], val[2], val[3])
1025
+ }
1026
+ | tLBRACK aref_args tRBRACK
1027
+ {
1028
+ result = @builder.array(val[0], val[1], val[2])
1029
+ }
1030
+ | tLBRACE assoc_list tRCURLY
1031
+ {
1032
+ result = @builder.associate(val[0], val[1], val[2])
1033
+ }
1034
+ | kRETURN
1035
+ {
1036
+ result = @builder.keyword_cmd(:return, val[0])
1037
+ }
1038
+ | kYIELD tLPAREN2 call_args tRPAREN
1039
+ {
1040
+ result = @builder.keyword_cmd(:yield, val[0], val[1], val[2], val[3])
1041
+ }
1042
+ | kYIELD tLPAREN2 tRPAREN
1043
+ {
1044
+ result = @builder.keyword_cmd(:yield, val[0], val[1], [], val[2])
1045
+ }
1046
+ | kYIELD
1047
+ {
1048
+ result = @builder.keyword_cmd(:yield, val[0])
1049
+ }
1050
+ | kDEFINED opt_nl tLPAREN2 expr tRPAREN
1051
+ {
1052
+ result = @builder.keyword_cmd(:defined?, val[0],
1053
+ val[2], [ val[3] ], val[4])
1054
+ }
1055
+ | operation brace_block
1056
+ {
1057
+ method_call = @builder.call_method(nil, nil, val[0])
1058
+
1059
+ begin_t, args, body, end_t = val[1]
1060
+ result = @builder.block(method_call,
1061
+ begin_t, args, body, end_t)
1062
+ }
1063
+ | method_call
1064
+ | method_call brace_block
1065
+ {
1066
+ begin_t, args, body, end_t = val[1]
1067
+ result = @builder.block(val[0],
1068
+ begin_t, args, body, end_t)
1069
+ }
1070
+ | kIF expr_value then compstmt if_tail kEND
1071
+ {
1072
+ else_t, else_ = val[4]
1073
+ result = @builder.condition(val[0], val[1], val[2],
1074
+ val[3], else_t,
1075
+ else_, val[5])
1076
+ }
1077
+ | kUNLESS expr_value then compstmt opt_else kEND
1078
+ {
1079
+ else_t, else_ = val[4]
1080
+ result = @builder.condition(val[0], val[1], val[2],
1081
+ else_, else_t,
1082
+ val[3], val[5])
1083
+ }
1084
+ | kWHILE
1085
+ {
1086
+ @lexer.cond.push(true)
1087
+ }
1088
+ expr_value do
1089
+ {
1090
+ @lexer.cond.pop
1091
+ }
1092
+ compstmt kEND
1093
+ {
1094
+ result = @builder.loop(:while, val[0], val[2], val[3],
1095
+ val[5], val[6])
1096
+ }
1097
+ | kUNTIL
1098
+ {
1099
+ @lexer.cond.push(true)
1100
+ }
1101
+ expr_value do
1102
+ {
1103
+ @lexer.cond.pop
1104
+ }
1105
+ compstmt kEND
1106
+ {
1107
+ result = @builder.loop(:until, val[0], val[2], val[3],
1108
+ val[5], val[6])
1109
+ }
1110
+ | kCASE expr_value opt_terms case_body kEND
1111
+ {
1112
+ when_bodies = val[3][0..-2]
1113
+ else_t, else_body = val[3][-1]
1114
+
1115
+ result = @builder.case(val[0], val[1],
1116
+ when_bodies, else_t, else_body,
1117
+ val[4])
1118
+ }
1119
+ | kCASE opt_terms case_body kEND
1120
+ {
1121
+ when_bodies = val[2][0..-2]
1122
+ else_t, else_body = val[2][-1]
1123
+
1124
+ result = @builder.case(val[0], nil,
1125
+ when_bodies, else_t, else_body,
1126
+ val[3])
1127
+ }
1128
+ | kCASE opt_terms kELSE compstmt kEND
1129
+ {
1130
+ result = @builder.case(val[0], nil,
1131
+ [], val[2], val[3],
1132
+ val[4])
1133
+ }
1134
+ | kFOR for_var kIN
1135
+ {
1136
+ @lexer.cond.push(true)
1137
+ }
1138
+ expr_value do
1139
+ {
1140
+ @lexer.cond.pop
1141
+ }
1142
+ compstmt kEND
1143
+ {
1144
+ result = @builder.for(val[0], val[1],
1145
+ val[2], val[4],
1146
+ val[5], val[7], val[8])
1147
+ }
1148
+ | kCLASS cpath superclass
1149
+ {
1150
+ @static_env.extend_static
1151
+ }
1152
+ bodystmt kEND
1153
+ {
1154
+ if in_def?
1155
+ diagnostic :error, :class_in_def, nil, val[0]
1156
+ end
1157
+
1158
+ lt_t, superclass = val[2]
1159
+ result = @builder.def_class(val[0], val[1],
1160
+ lt_t, superclass,
1161
+ val[4], val[5])
1162
+
1163
+ @static_env.unextend
1164
+ }
1165
+ | kCLASS tLSHFT expr term
1166
+ {
1167
+ result = @def_level
1168
+ @def_level = 0
1169
+
1170
+ @static_env.extend_static
1171
+ }
1172
+ bodystmt kEND
1173
+ {
1174
+ result = @builder.def_sclass(val[0], val[1], val[2],
1175
+ val[5], val[6])
1176
+
1177
+ @static_env.unextend
1178
+
1179
+ @def_level = val[4]
1180
+ }
1181
+ | kMODULE cpath
1182
+ {
1183
+ @static_env.extend_static
1184
+ }
1185
+ bodystmt kEND
1186
+ {
1187
+ if in_def?
1188
+ diagnostic :error, :module_in_def, nil, val[0]
1189
+ end
1190
+
1191
+ result = @builder.def_module(val[0], val[1],
1192
+ val[3], val[4])
1193
+
1194
+ @static_env.unextend
1195
+ }
1196
+ | kDEF fname
1197
+ {
1198
+ @def_level += 1
1199
+ @static_env.extend_static
1200
+ }
1201
+ f_arglist bodystmt kEND
1202
+ {
1203
+ result = @builder.def_method(val[0], val[1],
1204
+ val[3], val[4], val[5])
1205
+
1206
+ @static_env.unextend
1207
+ @def_level -= 1
1208
+ }
1209
+ | kDEF singleton dot_or_colon
1210
+ {
1211
+ @lexer.state = :expr_fname
1212
+ }
1213
+ fname
1214
+ {
1215
+ @def_level += 1
1216
+ @static_env.extend_static
1217
+ }
1218
+ f_arglist bodystmt kEND
1219
+ {
1220
+ result = @builder.def_singleton(val[0], val[1], val[2],
1221
+ val[4], val[6], val[7], val[8])
1222
+
1223
+ @static_env.unextend
1224
+ @def_level -= 1
1225
+ }
1226
+ | kBREAK
1227
+ {
1228
+ result = @builder.keyword_cmd(:break, val[0])
1229
+ }
1230
+ | kNEXT
1231
+ {
1232
+ result = @builder.keyword_cmd(:next, val[0])
1233
+ }
1234
+ | kREDO
1235
+ {
1236
+ result = @builder.keyword_cmd(:redo, val[0])
1237
+ }
1238
+ | kRETRY
1239
+ {
1240
+ result = @builder.keyword_cmd(:retry, val[0])
1241
+ }
1242
+
1243
+ primary_value: primary
1244
+
1245
+ then: term
1246
+ | tCOLON
1247
+ | kTHEN
1248
+ | term kTHEN
1249
+ {
1250
+ result = val[1]
1251
+ }
1252
+
1253
+ do: term
1254
+ | tCOLON
1255
+ | kDO_COND
1256
+
1257
+ if_tail: opt_else
1258
+ | kELSIF expr_value then compstmt if_tail
1259
+ {
1260
+ else_t, else_ = val[4]
1261
+ result = [ val[0],
1262
+ @builder.condition(val[0], val[1], val[2],
1263
+ val[3], else_t,
1264
+ else_, nil),
1265
+ ]
1266
+ }
1267
+
1268
+ opt_else: none
1269
+ | kELSE compstmt
1270
+ {
1271
+ result = val
1272
+ }
1273
+
1274
+ for_var: lhs
1275
+ | mlhs
1276
+
1277
+ block_par: mlhs_item
1278
+ {
1279
+ result = [ @builder.arg_expr(val[0]) ]
1280
+ }
1281
+ | block_par tCOMMA mlhs_item
1282
+ {
1283
+ result = val[0] << @builder.arg_expr(val[2])
1284
+ }
1285
+
1286
+ block_var: block_par
1287
+ | block_par tCOMMA
1288
+ | block_par tCOMMA tAMPER lhs
1289
+ {
1290
+ result = val[0].
1291
+ push(@builder.blockarg_expr(val[2], val[3]))
1292
+ }
1293
+ | block_par tCOMMA tSTAR lhs tCOMMA tAMPER lhs
1294
+ {
1295
+ result = val[0].
1296
+ push(@builder.restarg_expr(val[2], val[3])).
1297
+ push(@builder.blockarg_expr(val[5], val[6]))
1298
+ }
1299
+ | block_par tCOMMA tSTAR tCOMMA tAMPER lhs
1300
+ {
1301
+ result = val[0].
1302
+ push(@builder.restarg_expr(val[2])).
1303
+ push(@builder.blockarg_expr(val[4], val[5]))
1304
+ }
1305
+ | block_par tCOMMA tSTAR lhs
1306
+ {
1307
+ result = val[0].
1308
+ push(@builder.restarg_expr(val[2], val[3]))
1309
+ }
1310
+ | block_par tCOMMA tSTAR
1311
+ {
1312
+ result = val[0].
1313
+ push(@builder.restarg_expr(val[2]))
1314
+ }
1315
+ | tSTAR lhs tCOMMA tAMPER lhs
1316
+ {
1317
+ result = [ @builder.restarg_expr(val[0], val[1]),
1318
+ @builder.blockarg_expr(val[3], val[4]) ]
1319
+ }
1320
+ | tSTAR tCOMMA tAMPER lhs
1321
+ {
1322
+ result = [ @builder.restarg_expr(val[0]),
1323
+ @builder.blockarg_expr(val[2], val[3]) ]
1324
+ }
1325
+ | tSTAR lhs
1326
+ {
1327
+ result = [ @builder.restarg_expr(val[0], val[1]) ]
1328
+ }
1329
+ | tSTAR
1330
+ {
1331
+ result = [ @builder.restarg_expr(val[0]) ]
1332
+ }
1333
+ | tAMPER lhs
1334
+ {
1335
+ result = [ @builder.blockarg_expr(val[0], val[1]) ]
1336
+ }
1337
+ ;
1338
+
1339
+ opt_block_var: # nothing
1340
+ {
1341
+ result = @builder.args(nil, [], nil)
1342
+ }
1343
+ | tPIPE tPIPE
1344
+ {
1345
+ result = @builder.args(val[0], [], val[1])
1346
+ }
1347
+ | tOROP
1348
+ {
1349
+ result = @builder.args(val[0], [], val[0])
1350
+ }
1351
+ | tPIPE block_var tPIPE
1352
+ {
1353
+ result = @builder.args(val[0], val[1], val[2], false)
1354
+ }
1355
+
1356
+ do_block: kDO_BLOCK
1357
+ {
1358
+ @static_env.extend_dynamic
1359
+ }
1360
+ opt_block_var compstmt kEND
1361
+ {
1362
+ result = [ val[0], val[2], val[3], val[4] ]
1363
+
1364
+ @static_env.unextend
1365
+ }
1366
+
1367
+ block_call: command do_block
1368
+ {
1369
+ begin_t, block_args, body, end_t = val[1]
1370
+ result = @builder.block(val[0],
1371
+ begin_t, block_args, body, end_t)
1372
+ }
1373
+ | block_call tDOT operation2 opt_paren_args
1374
+ {
1375
+ lparen_t, args, rparen_t = val[3]
1376
+ result = @builder.call_method(val[0], val[1], val[2],
1377
+ lparen_t, args, rparen_t)
1378
+ }
1379
+ | block_call tCOLON2 operation2 opt_paren_args
1380
+ {
1381
+ lparen_t, args, rparen_t = val[3]
1382
+ result = @builder.call_method(val[0], val[1], val[2],
1383
+ lparen_t, args, rparen_t)
1384
+ }
1385
+
1386
+ method_call: operation paren_args
1387
+ {
1388
+ lparen_t, args, rparen_t = val[1]
1389
+ result = @builder.call_method(nil, nil, val[0],
1390
+ lparen_t, args, rparen_t)
1391
+ }
1392
+ | primary_value tDOT operation2 opt_paren_args
1393
+ {
1394
+ lparen_t, args, rparen_t = val[3]
1395
+ result = @builder.call_method(val[0], val[1], val[2],
1396
+ lparen_t, args, rparen_t)
1397
+ }
1398
+ | primary_value tCOLON2 operation2 paren_args
1399
+ {
1400
+ lparen_t, args, rparen_t = val[3]
1401
+ result = @builder.call_method(val[0], val[1], val[2],
1402
+ lparen_t, args, rparen_t)
1403
+ }
1404
+ | primary_value tCOLON2 operation3
1405
+ {
1406
+ result = @builder.call_method(val[0], val[1], val[2])
1407
+ }
1408
+ | kSUPER paren_args
1409
+ {
1410
+ lparen_t, args, rparen_t = val[1]
1411
+ result = @builder.keyword_cmd(:super, val[0],
1412
+ lparen_t, args, rparen_t)
1413
+ }
1414
+ | kSUPER
1415
+ {
1416
+ result = @builder.keyword_cmd(:zsuper, val[0])
1417
+ }
1418
+
1419
+ brace_block: tLCURLY
1420
+ {
1421
+ @static_env.extend_dynamic
1422
+ }
1423
+ opt_block_var compstmt tRCURLY
1424
+ {
1425
+ result = [ val[0], val[2], val[3], val[4] ]
1426
+
1427
+ @static_env.unextend
1428
+ }
1429
+ | kDO
1430
+ {
1431
+ @static_env.extend_dynamic
1432
+ }
1433
+ opt_block_var compstmt kEND
1434
+ {
1435
+ result = [ val[0], val[2], val[3], val[4] ]
1436
+
1437
+ @static_env.unextend
1438
+ }
1439
+
1440
+ case_body: kWHEN when_args then compstmt cases
1441
+ {
1442
+ result = [ @builder.when(val[0], val[1], val[2], val[3]),
1443
+ *val[4] ]
1444
+ }
1445
+
1446
+ when_args: args
1447
+ | args tCOMMA tSTAR arg_value
1448
+ {
1449
+ result = val[0] << @builder.splat(val[2], val[3])
1450
+ }
1451
+ | tSTAR arg_value
1452
+ {
1453
+ result = [ @builder.splat(val[0], val[1]) ]
1454
+ }
1455
+
1456
+ cases: opt_else
1457
+ {
1458
+ result = [ val[0] ]
1459
+ }
1460
+ | case_body
1461
+
1462
+ opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1463
+ {
1464
+ assoc_t, exc_var = val[2]
1465
+
1466
+ if val[1]
1467
+ exc_list = @builder.array(nil, val[1], nil)
1468
+ end
1469
+
1470
+ result = [ @builder.rescue_body(val[0],
1471
+ exc_list, assoc_t, exc_var,
1472
+ val[3], val[4]),
1473
+ *val[5] ]
1474
+ }
1475
+ | # nothing
1476
+ {
1477
+ result = []
1478
+ }
1479
+
1480
+ exc_list: arg_value
1481
+ {
1482
+ result = [ val[0] ]
1483
+ }
1484
+ | mrhs
1485
+ | none
1486
+
1487
+ exc_var: tASSOC lhs
1488
+ {
1489
+ result = [ val[0], val[1] ]
1490
+ }
1491
+ | none
1492
+
1493
+ opt_ensure: kENSURE compstmt
1494
+ {
1495
+ result = [ val[0], val[1] ]
1496
+ }
1497
+ | none
1498
+
1499
+ literal: numeric
1500
+ | symbol
1501
+ | dsym
1502
+
1503
+ strings: string
1504
+ {
1505
+ result = @builder.string_compose(nil, val[0], nil)
1506
+ }
1507
+
1508
+ string: string1
1509
+ {
1510
+ result = [ val[0] ]
1511
+ }
1512
+ | string string1
1513
+ {
1514
+ result = val[0] << val[1]
1515
+ }
1516
+
1517
+ string1: tSTRING_BEG string_contents tSTRING_END
1518
+ {
1519
+ result = @builder.string_compose(val[0], val[1], val[2])
1520
+ }
1521
+ | tSTRING
1522
+ {
1523
+ result = @builder.string(val[0])
1524
+ }
1525
+
1526
+ xstring: tXSTRING_BEG xstring_contents tSTRING_END
1527
+ {
1528
+ result = @builder.xstring_compose(val[0], val[1], val[2])
1529
+ }
1530
+
1531
+ regexp: tREGEXP_BEG xstring_contents tSTRING_END tREGEXP_OPT
1532
+ {
1533
+ opts = @builder.regexp_options(val[3])
1534
+ result = @builder.regexp_compose(val[0], val[1], val[2], opts)
1535
+ }
1536
+
1537
+ words: tWORDS_BEG word_list tSTRING_END
1538
+ {
1539
+ result = @builder.words_compose(val[0], val[1], val[2])
1540
+ }
1541
+
1542
+ word_list: # nothing
1543
+ {
1544
+ result = []
1545
+ }
1546
+ | word_list word tSPACE
1547
+ {
1548
+ result = val[0] << @builder.word(val[1])
1549
+ }
1550
+
1551
+ word: string_content
1552
+ {
1553
+ result = [ val[0] ]
1554
+ }
1555
+ | word string_content
1556
+ {
1557
+ result = val[0] << val[1]
1558
+ }
1559
+
1560
+ qwords: tQWORDS_BEG qword_list tSTRING_END
1561
+ {
1562
+ result = @builder.words_compose(val[0], val[1], val[2])
1563
+ }
1564
+
1565
+ qword_list: # nothing
1566
+ {
1567
+ result = []
1568
+ }
1569
+ | qword_list tSTRING_CONTENT tSPACE
1570
+ {
1571
+ result = val[0] << @builder.string_internal(val[1])
1572
+ }
1573
+
1574
+ string_contents: # nothing
1575
+ {
1576
+ result = []
1577
+ }
1578
+ | string_contents string_content
1579
+ {
1580
+ result = val[0] << val[1]
1581
+ }
1582
+
1583
+ xstring_contents: # nothing
1584
+ {
1585
+ result = []
1586
+ }
1587
+ | xstring_contents string_content
1588
+ {
1589
+ result = val[0] << val[1]
1590
+ }
1591
+
1592
+ string_content: tSTRING_CONTENT
1593
+ {
1594
+ result = @builder.string_internal(val[0])
1595
+ }
1596
+ | tSTRING_DVAR string_dvar
1597
+ {
1598
+ result = val[1]
1599
+ }
1600
+ | tSTRING_DBEG
1601
+ {
1602
+ @lexer.cond.push(false)
1603
+ @lexer.cmdarg.push(false)
1604
+ }
1605
+ compstmt tRCURLY
1606
+ {
1607
+ @lexer.cond.lexpop
1608
+ @lexer.cmdarg.lexpop
1609
+
1610
+ result = @builder.begin(val[0], val[2], val[3])
1611
+ }
1612
+
1613
+ string_dvar: tGVAR
1614
+ {
1615
+ result = @builder.gvar(val[0])
1616
+ }
1617
+ | tIVAR
1618
+ {
1619
+ result = @builder.ivar(val[0])
1620
+ }
1621
+ | tCVAR
1622
+ {
1623
+ result = @builder.cvar(val[0])
1624
+ }
1625
+ | backref
1626
+
1627
+
1628
+ symbol: tSYMBOL
1629
+ {
1630
+ result = @builder.symbol(val[0])
1631
+ }
1632
+
1633
+ dsym: tSYMBEG xstring_contents tSTRING_END
1634
+ {
1635
+ result = @builder.symbol_compose(val[0], val[1], val[2])
1636
+ }
1637
+
1638
+ numeric: tINTEGER
1639
+ {
1640
+ result = @builder.integer(val[0])
1641
+ }
1642
+ | tFLOAT
1643
+ {
1644
+ result = @builder.float(val[0])
1645
+ }
1646
+ | tUMINUS_NUM tINTEGER =tLOWEST
1647
+ {
1648
+ result = @builder.negate(val[0],
1649
+ @builder.integer(val[1]))
1650
+ }
1651
+ | tUMINUS_NUM tFLOAT =tLOWEST
1652
+ {
1653
+ result = @builder.negate(val[0],
1654
+ @builder.float(val[1]))
1655
+ }
1656
+
1657
+ variable: tIDENTIFIER
1658
+ {
1659
+ result = @builder.ident(val[0])
1660
+ }
1661
+ | tIVAR
1662
+ {
1663
+ result = @builder.ivar(val[0])
1664
+ }
1665
+ | tGVAR
1666
+ {
1667
+ result = @builder.gvar(val[0])
1668
+ }
1669
+ | tCVAR
1670
+ {
1671
+ result = @builder.cvar(val[0])
1672
+ }
1673
+ | tCONSTANT
1674
+ {
1675
+ result = @builder.const(val[0])
1676
+ }
1677
+ | kNIL
1678
+ {
1679
+ result = @builder.nil(val[0])
1680
+ }
1681
+ | kSELF
1682
+ {
1683
+ result = @builder.self(val[0])
1684
+ }
1685
+ | kTRUE
1686
+ {
1687
+ result = @builder.true(val[0])
1688
+ }
1689
+ | kFALSE
1690
+ {
1691
+ result = @builder.false(val[0])
1692
+ }
1693
+ | k__FILE__
1694
+ {
1695
+ result = @builder.__FILE__(val[0])
1696
+ }
1697
+ | k__LINE__
1698
+ {
1699
+ result = @builder.__LINE__(val[0])
1700
+ }
1701
+
1702
+ var_ref: variable
1703
+ {
1704
+ result = @builder.accessible(val[0])
1705
+ }
1706
+
1707
+ var_lhs: variable
1708
+ {
1709
+ result = @builder.assignable(val[0])
1710
+ }
1711
+
1712
+ backref: tNTH_REF
1713
+ {
1714
+ result = @builder.nth_ref(val[0])
1715
+ }
1716
+ | tBACK_REF
1717
+ {
1718
+ result = @builder.back_ref(val[0])
1719
+ }
1720
+
1721
+ superclass: term
1722
+ {
1723
+ result = nil
1724
+ }
1725
+ | tLT expr_value term
1726
+ {
1727
+ result = [ val[0], val[1] ]
1728
+ }
1729
+ | error term
1730
+ {
1731
+ yyerrok
1732
+ result = nil
1733
+ }
1734
+
1735
+ f_arglist: tLPAREN2 f_args opt_nl tRPAREN
1736
+ {
1737
+ result = @builder.args(val[0], val[1], val[3])
1738
+
1739
+ @lexer.state = :expr_beg
1740
+ }
1741
+ | f_args term
1742
+ {
1743
+ result = @builder.args(nil, val[0], nil)
1744
+ }
1745
+
1746
+ f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_f_block_arg
1747
+ {
1748
+ result = val[0].
1749
+ concat(val[2]).
1750
+ concat(val[4]).
1751
+ concat(val[5])
1752
+ }
1753
+ | f_arg tCOMMA f_optarg opt_f_block_arg
1754
+ {
1755
+ result = val[0].
1756
+ concat(val[2]).
1757
+ concat(val[3])
1758
+ }
1759
+ | f_arg tCOMMA f_rest_arg opt_f_block_arg
1760
+ {
1761
+ result = val[0].
1762
+ concat(val[2]).
1763
+ concat(val[3])
1764
+ }
1765
+ | f_arg opt_f_block_arg
1766
+ {
1767
+ result = val[0].
1768
+ concat(val[1])
1769
+ }
1770
+ | f_optarg tCOMMA f_rest_arg opt_f_block_arg
1771
+ {
1772
+ result = val[0].
1773
+ concat(val[2]).
1774
+ concat(val[3])
1775
+ }
1776
+ | f_optarg opt_f_block_arg
1777
+ {
1778
+ result = val[0].
1779
+ concat(val[1])
1780
+ }
1781
+ | f_rest_arg opt_f_block_arg
1782
+ {
1783
+ result = val[0].
1784
+ concat(val[1])
1785
+ }
1786
+ | f_block_arg
1787
+ {
1788
+ result = [ val[0] ]
1789
+ }
1790
+ | # nothing
1791
+ {
1792
+ result = []
1793
+ }
1794
+
1795
+ f_norm_arg: tCONSTANT
1796
+ {
1797
+ diagnostic :error, :argument_const, nil, val[0]
1798
+ }
1799
+ | tIVAR
1800
+ {
1801
+ diagnostic :error, :argument_ivar, nil, val[0]
1802
+ }
1803
+ | tGVAR
1804
+ {
1805
+ diagnostic :error, :argument_gvar, nil, val[0]
1806
+ }
1807
+ | tCVAR
1808
+ {
1809
+ diagnostic :error, :argument_cvar, nil, val[0]
1810
+ }
1811
+ | tIDENTIFIER
1812
+ {
1813
+ @static_env.declare val[0][0]
1814
+
1815
+ result = @builder.arg(val[0])
1816
+ }
1817
+
1818
+ f_arg: f_norm_arg
1819
+ {
1820
+ result = [ val[0] ]
1821
+ }
1822
+ | f_arg tCOMMA f_norm_arg
1823
+ {
1824
+ result = val[0] << val[2]
1825
+ }
1826
+
1827
+ f_opt: tIDENTIFIER tEQL arg_value
1828
+ {
1829
+ @static_env.declare val[0][0]
1830
+
1831
+ result = @builder.optarg(val[0], val[1], val[2])
1832
+ }
1833
+
1834
+ f_optarg: f_opt
1835
+ {
1836
+ result = [ val[0] ]
1837
+ }
1838
+ | f_optarg tCOMMA f_opt
1839
+ {
1840
+ result = val[0] << val[2]
1841
+ }
1842
+
1843
+ restarg_mark: tSTAR2 | tSTAR
1844
+
1845
+ f_rest_arg: restarg_mark tIDENTIFIER
1846
+ {
1847
+ @static_env.declare val[1][0]
1848
+
1849
+ result = [ @builder.restarg(val[0], val[1]) ]
1850
+ }
1851
+ | restarg_mark
1852
+ {
1853
+ result = [ @builder.restarg(val[0]) ]
1854
+ }
1855
+
1856
+ blkarg_mark: tAMPER2 | tAMPER
1857
+
1858
+ f_block_arg: blkarg_mark tIDENTIFIER
1859
+ {
1860
+ @static_env.declare val[1][0]
1861
+
1862
+ result = @builder.blockarg(val[0], val[1])
1863
+ }
1864
+
1865
+ opt_f_block_arg: tCOMMA f_block_arg
1866
+ {
1867
+ result = [ val[1] ]
1868
+ }
1869
+ | # nothing
1870
+ {
1871
+ result = []
1872
+ }
1873
+
1874
+ singleton: var_ref
1875
+ | tLPAREN2 expr opt_nl tRPAREN
1876
+ {
1877
+ result = val[1]
1878
+ }
1879
+
1880
+ assoc_list: # nothing
1881
+ {
1882
+ result = []
1883
+ }
1884
+ | assocs trailer
1885
+ {
1886
+ result = val[0]
1887
+ }
1888
+ | args trailer
1889
+ {
1890
+ result = @builder.pair_list_18(val[0])
1891
+ }
1892
+
1893
+ assocs: assoc
1894
+ {
1895
+ result = [ val[0] ]
1896
+ }
1897
+ | assocs tCOMMA assoc
1898
+ {
1899
+ result = val[0] << val[2]
1900
+ }
1901
+
1902
+ assoc: arg_value tASSOC arg_value
1903
+ {
1904
+ result = @builder.pair(val[0], val[1], val[2])
1905
+ }
1906
+
1907
+ operation: tIDENTIFIER | tCONSTANT | tFID
1908
+ operation2: tIDENTIFIER | tCONSTANT | tFID | op
1909
+ operation3: tIDENTIFIER | tFID | op
1910
+ dot_or_colon: tDOT | tCOLON2
1911
+ opt_terms: | terms
1912
+ opt_nl: | tNL
1913
+ trailer: | tNL | tCOMMA
1914
+
1915
+ term: tSEMI
1916
+ {
1917
+ yyerrok
1918
+ }
1919
+ | tNL
1920
+
1921
+ terms: term
1922
+ | terms tSEMI
1923
+
1924
+ none: # nothing
1925
+ {
1926
+ result = nil
1927
+ }
1928
+
1929
+ end
1930
+
1931
+ ---- header
1932
+
1933
+ require 'parser'
1934
+
1935
+ ---- inner
1936
+
1937
+ def version
1938
+ 18
1939
+ end
1940
+
1941
+ def default_encoding
1942
+ Encoding::BINARY if defined? Encoding
1943
+ end