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