racc 1.4.14 → 1.4.15

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