racc 1.4.13 → 1.5.1

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