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