racc 1.4.14-java → 1.4.15-java

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