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