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