parser 2.7.1.1 → 3.0.2.0

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