parser 2.7.1.3 → 3.0.1.0

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