ruby_parser 3.20.3 → 3.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/History.rdoc +32 -0
  4. data/Manifest.txt +14 -24
  5. data/README.rdoc +3 -3
  6. data/Rakefile +113 -115
  7. data/compare/normalize.rb +2 -0
  8. data/lib/ruby_lexer.rb +9 -16
  9. data/lib/ruby_lexer.rex.rb +1 -2
  10. data/lib/ruby_parser.rb +15 -13
  11. data/lib/{ruby_parser.yy → ruby_parser2.yy} +3 -10
  12. data/lib/{ruby20_parser.rb → ruby_parser20.rb} +9 -12
  13. data/lib/{ruby21_parser.rb → ruby_parser21.rb} +9 -12
  14. data/lib/{ruby22_parser.rb → ruby_parser22.rb} +9 -12
  15. data/lib/{ruby23_parser.rb → ruby_parser23.rb} +9 -12
  16. data/lib/{ruby24_parser.rb → ruby_parser24.rb} +9 -12
  17. data/lib/{ruby25_parser.rb → ruby_parser25.rb} +9 -12
  18. data/lib/{ruby26_parser.rb → ruby_parser26.rb} +9 -12
  19. data/lib/{ruby27_parser.rb → ruby_parser27.rb} +9 -12
  20. data/lib/{ruby3_parser.yy → ruby_parser3.yy} +7 -33
  21. data/lib/{ruby30_parser.rb → ruby_parser30.rb} +11 -35
  22. data/lib/{ruby31_parser.rb → ruby_parser31.rb} +11 -35
  23. data/lib/{ruby32_parser.rb → ruby_parser32.rb} +11 -35
  24. data/lib/ruby_parser33.rb +13577 -0
  25. data/lib/ruby_parser_extras.rb +34 -17
  26. data/test/test_ruby_lexer.rb +5 -5
  27. data/test/test_ruby_parser.rb +21 -19
  28. data.tar.gz.sig +0 -0
  29. metadata +41 -51
  30. metadata.gz.sig +0 -0
  31. data/lib/ruby20_parser.y +0 -2707
  32. data/lib/ruby21_parser.y +0 -2724
  33. data/lib/ruby22_parser.y +0 -2735
  34. data/lib/ruby23_parser.y +0 -2737
  35. data/lib/ruby24_parser.y +0 -2745
  36. data/lib/ruby25_parser.y +0 -2745
  37. data/lib/ruby26_parser.y +0 -2760
  38. data/lib/ruby27_parser.y +0 -3360
  39. data/lib/ruby30_parser.y +0 -3508
  40. data/lib/ruby31_parser.y +0 -3542
  41. data/lib/ruby32_parser.y +0 -3543
data/lib/ruby31_parser.y DELETED
@@ -1,3542 +0,0 @@
1
- # -*- racc -*-
2
-
3
- class Ruby31Parser
4
-
5
- token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
6
- kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
7
- kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
8
- kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
9
- kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
10
- k__FILE__ k__ENCODING__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT
11
- tLABEL tCVAR tNTH_REF tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT
12
- tREGEXP_END tUPLUS tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ
13
- tGEQ tLEQ tANDOP tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF
14
- tASET tLSHFT tRSHFT tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN
15
- tLPAREN2 tRPAREN tLPAREN_ARG tLBRACK tLBRACK2 tRBRACK tLBRACE
16
- tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2 tTILDE tPERCENT tDIVIDE
17
- tPLUS tMINUS tLT tGT tPIPE tBANG tCARET tLCURLY tRCURLY
18
- tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
19
- tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END
20
- tSTRING tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAMBDA
21
- tLAMBEG tDSTAR tCHAR tSYMBOLS_BEG tQSYMBOLS_BEG tSTRING_DEND
22
- tRATIONAL tIMAGINARY
23
- tLABEL_END
24
- tLONELY
25
- tBDOT2 tBDOT3
26
-
27
- preclow
28
- nonassoc tLOWEST
29
- nonassoc tLBRACE_ARG
30
- nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
31
- left kOR kAND
32
- right kNOT
33
- nonassoc kDEFINED
34
- right tEQL tOP_ASGN
35
- left kRESCUE_MOD
36
- right tEH tCOLON
37
- nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
38
- left tOROP
39
- left tANDOP
40
- nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
41
- left tGT tGEQ tLT tLEQ
42
- left tPIPE tCARET
43
- left tAMPER2
44
- left tLSHFT tRSHFT
45
- left tPLUS tMINUS
46
- left tSTAR2 tDIVIDE tPERCENT # TODO: tSTAR2 -> tMULT
47
- right tUMINUS_NUM tUMINUS
48
- right tPOW
49
- right tBANG tTILDE tUPLUS
50
- prechigh
51
-
52
- rule
53
-
54
- program: {
55
- self.lexer.lex_state = EXPR_BEG
56
- }
57
- top_compstmt
58
- {
59
- result = new_compstmt val
60
-
61
- lexer.cond.pop # local_pop
62
- lexer.cmdarg.pop
63
- }
64
-
65
- top_compstmt: top_stmts opt_terms
66
- {
67
- stmt, _ = val
68
- result = stmt
69
- }
70
-
71
- top_stmts: none
72
- | top_stmt
73
- | top_stmts terms top_stmt
74
- {
75
- result = self.block_append val[0], val[2]
76
- }
77
- | error top_stmt
78
-
79
- top_stmt: stmt
80
- | klBEGIN
81
- {
82
- if (self.in_def || self.in_single > 0) then
83
- debug 1
84
- yyerror "BEGIN in method"
85
- end
86
- self.env.extend
87
- }
88
- begin_block
89
- {
90
- (_, lineno), _, iter = val
91
- iter.line lineno
92
-
93
- (_, preexe,) = iter
94
- preexe.line lineno
95
-
96
- result = iter
97
- }
98
-
99
- begin_block: tLCURLY top_compstmt tRCURLY
100
- {
101
- (_, line), stmt, _ = val
102
- result = new_iter s(:preexe).line(line), 0, stmt
103
- }
104
-
105
- bodystmt: compstmt opt_rescue k_else
106
- {
107
- res = _values[-2]
108
- yyerror "else without rescue is useless" unless res
109
- }
110
- compstmt
111
- opt_ensure
112
- {
113
- body, resc, _, _, els, ens = val
114
-
115
- result = new_body [body, resc, els, ens]
116
- }
117
- | compstmt opt_rescue opt_ensure
118
- {
119
- body, resc, ens = val
120
-
121
- result = new_body [body, resc, nil, ens]
122
- }
123
-
124
- compstmt: stmts opt_terms
125
- {
126
- result = new_compstmt val
127
- }
128
-
129
- stmts: none
130
- | stmt_or_begin # TODO: newline_node ?
131
- | stmts terms stmt_or_begin
132
- {
133
- result = self.block_append val[0], val[2]
134
- }
135
- | error stmt
136
- {
137
- result = val[1]
138
- debug 2
139
- }
140
-
141
- stmt_or_begin: stmt
142
- | klBEGIN
143
- {
144
- yyerror "BEGIN is permitted only at toplevel"
145
- }
146
- begin_block
147
- {
148
- result = val[2] # wtf?
149
- }
150
-
151
- stmt: kALIAS fitem
152
- {
153
- lexer.lex_state = EXPR_FNAME
154
- }
155
- fitem
156
- {
157
- (_, line), lhs, _, rhs = val
158
- result = s(:alias, lhs, rhs).line(line).line line
159
- }
160
- | kALIAS tGVAR tGVAR
161
- {
162
- (_, line), (lhs, _), (rhs, _) = val
163
- result = s(:valias, lhs.to_sym, rhs.to_sym).line line
164
- }
165
- | kALIAS tGVAR tBACK_REF
166
- {
167
- (_, line), (lhs, _), (rhs, _) = val
168
- result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
169
- }
170
- | kALIAS tGVAR tNTH_REF
171
- {
172
- yyerror "can't make alias for the number variables"
173
- }
174
- | kUNDEF undef_list
175
- {
176
- result = val[1]
177
- }
178
- | stmt kIF_MOD expr_value
179
- {
180
- t, _, c = val
181
- result = new_if c, t, nil
182
- }
183
- | stmt kUNLESS_MOD expr_value
184
- {
185
- f, _, c = val
186
- result = new_if c, nil, f
187
- }
188
- | stmt kWHILE_MOD expr_value
189
- {
190
- e, _, c = val
191
- result = new_while e, c, true
192
- }
193
- | stmt kUNTIL_MOD expr_value
194
- {
195
- e, _, c = val
196
- result = new_until e, c, true
197
- }
198
- | stmt kRESCUE_MOD stmt
199
- {
200
- body, _, resbody = val
201
-
202
- resbody = new_resbody s(:array).line(resbody.line), resbody
203
- result = new_rescue body, resbody
204
- }
205
- | klEND tLCURLY compstmt tRCURLY
206
- {
207
- (_, line), _, stmt, _ = val
208
-
209
- if (self.in_def || self.in_single > 0) then
210
- debug 3
211
- yyerror "END in method; use at_exit"
212
- end
213
-
214
- result = new_iter s(:postexe).line(line), 0, stmt
215
- }
216
- | command_asgn
217
- | mlhs tEQL command_call
218
- {
219
- result = new_masgn val[0], val[2], :wrap
220
- }
221
- | lhs tEQL mrhs
222
- {
223
- lhs, _, rhs = val
224
-
225
- result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
226
- }
227
- | mlhs tEQL mrhs_arg kRESCUE_MOD stmt
228
- {
229
- # unwraps s(:to_ary, rhs)
230
- lhs, _, (_, rhs), _, resbody = val
231
-
232
- resbody = new_resbody s(:array).line(resbody.line), resbody
233
-
234
- result = new_masgn lhs, new_rescue(rhs, resbody), :wrap
235
- }
236
- | mlhs tEQL mrhs_arg
237
- {
238
- result = new_masgn val[0], val[2]
239
- }
240
- | expr
241
-
242
- command_asgn: lhs tEQL command_rhs
243
- {
244
- result = new_assign val[0], val[2]
245
- }
246
- # | lhs tEQL command_asgn
247
- # {
248
- # result = new_assign val[0], val[2]
249
- # }
250
- | var_lhs tOP_ASGN command_rhs
251
- {
252
- result = new_op_asgn val
253
- }
254
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
255
- {
256
- result = new_op_asgn1 val
257
- }
258
- | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
259
- {
260
- prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
261
-
262
- result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
263
- result.sexp_type = :safe_op_asgn if call_op == '&.'
264
- result.line prim.line
265
- }
266
- | primary_value call_op tCONSTANT tOP_ASGN command_rhs
267
- {
268
- prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
269
-
270
- result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
271
- result.sexp_type = :safe_op_asgn if call_op == '&.'
272
- result.line prim.line
273
- }
274
- | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
275
- {
276
- lhs1, _, (lhs2, line), (id, _), rhs = val
277
-
278
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
279
- }
280
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
281
- {
282
- lhs1, _, (lhs2, line), (id, _), rhs = val
283
-
284
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
285
- }
286
- | defn_head f_opt_paren_args tEQL command
287
- {
288
- result = new_endless_defn val
289
- }
290
- | defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
291
- {
292
- result = new_endless_defn val
293
- }
294
- | defs_head f_opt_paren_args tEQL command
295
- {
296
- result = new_endless_defs val
297
- }
298
- | defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
299
- {
300
- result = new_endless_defs val
301
- }
302
- | backref tOP_ASGN command_rhs
303
- {
304
- self.backref_assign_error val[0]
305
- }
306
-
307
- command_rhs: command_call =tOP_ASGN
308
- {
309
- expr, = val
310
- result = value_expr expr
311
- }
312
- | command_call kRESCUE_MOD stmt
313
- {
314
- expr, (_, line), resbody = val
315
-
316
- expr = value_expr expr
317
- ary = s(:array).line line
318
- result = new_rescue(expr, new_resbody(ary, resbody))
319
- }
320
- | command_asgn
321
-
322
- expr: command_call
323
- | expr kAND expr
324
- {
325
- lhs, _, rhs = val
326
- result = logical_op :and, lhs, rhs
327
- }
328
- | expr kOR expr
329
- {
330
- lhs, _, rhs = val
331
- result = logical_op :or, lhs, rhs
332
- }
333
- | kNOT opt_nl expr
334
- {
335
- (_, line), _, expr = val
336
- result = new_call(expr, :"!").line line
337
- # REFACTOR: call_uni_op
338
- }
339
- | tBANG command_call
340
- {
341
- _, cmd = val
342
- result = new_call(cmd, :"!").line cmd.line
343
- # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
344
- # REFACTOR: call_uni_op -- see parse26.y
345
- }
346
- | arg tASSOC
347
- {
348
- # value_expr($1);
349
- self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
350
- self.lexer.command_start = false
351
- result = self.in_kwarg
352
- self.in_kwarg = true
353
- self.env.extend
354
- }
355
- p_top_expr_body
356
- {
357
- lhs, _, in_kwarg, rhs = val
358
-
359
- self.env.unextend
360
- self.in_kwarg = in_kwarg
361
-
362
- rhs = new_in rhs, nil, nil, rhs.line
363
- result = new_case lhs, rhs, rhs.line
364
- }
365
- | arg
366
- kIN
367
- {
368
- # TODO? value_expr($1);
369
- self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
370
- self.lexer.command_start = false
371
- result = self.in_kwarg
372
- self.in_kwarg = true
373
- self.env.extend
374
- }
375
- p_top_expr_body
376
- {
377
- self.env.unextend
378
-
379
- expr, _, old_kwarg, pat = val
380
-
381
- expr = value_expr expr
382
-
383
- self.in_kwarg = old_kwarg
384
- pat_in = new_in pat, nil, nil, expr.line
385
- result = new_case expr, pat_in, expr.line
386
- }
387
- | arg =tLBRACE_ARG
388
-
389
- def_name: fname
390
- {
391
- # TODO: numparam_name(p, fname);
392
-
393
- (id, line), = val
394
- old_in_def = self.in_def
395
-
396
- self.in_def = true # group = local_push
397
- self.env.extend
398
- lexer.cmdarg.push false
399
- lexer.cond.push false
400
-
401
- result = [id.to_sym, line, old_in_def]
402
- }
403
- defn_head: k_def def_name
404
- {
405
- _, name = val
406
- result = name
407
- }
408
- defs_head: k_def singleton dot_or_colon
409
- {
410
- lexer.lex_state = EXPR_FNAME
411
- self.in_argdef = true
412
- }
413
- def_name
414
- {
415
- lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
416
- self.in_single += 1 # TODO: remove?
417
-
418
- # self.in_def = true # local_push
419
- # self.env.extend
420
- # lexer.cmdarg.push false
421
- # lexer.cond.push false
422
-
423
- _, recv, _, _, name = val
424
-
425
- result = [recv, name]
426
- }
427
-
428
- expr_value: expr
429
- {
430
- result = value_expr(val[0])
431
- }
432
-
433
- expr_value_do: {
434
- lexer.cond.push true
435
- }
436
- expr_value do
437
- {
438
- lexer.cond.pop
439
- }
440
- {
441
- _, expr, _, _ = val
442
- result = expr
443
- }
444
-
445
- command_call: command
446
- | block_command
447
-
448
- block_command: block_call
449
- | block_call call_op2 operation2 command_args
450
- {
451
- blk, _, (msg, _line), args = val
452
- result = new_call(blk, msg.to_sym, args).line blk.line
453
- }
454
-
455
- cmd_brace_block: tLBRACE_ARG
456
- {
457
- # self.env.extend(:dynamic)
458
- result = self.lexer.lineno
459
- }
460
- brace_body tRCURLY
461
- {
462
- _, line, body, _ = val
463
-
464
- result = body
465
- result.line line
466
-
467
- # self.env.unextend
468
- }
469
-
470
- fcall: operation
471
- {
472
- (msg, line), = val
473
- result = new_call(nil, msg.to_sym).line line
474
- }
475
-
476
- command: fcall command_args =tLOWEST
477
- {
478
- call, args = val
479
- result = call.concat args.sexp_body
480
- }
481
- | fcall command_args cmd_brace_block
482
- {
483
- call, args, block = val
484
-
485
- result = call.concat args.sexp_body
486
-
487
- if block then
488
- block_dup_check result, block
489
-
490
- result, operation = block, result
491
- result.insert 1, operation
492
- end
493
- }
494
- | primary_value call_op operation2 command_args =tLOWEST
495
- {
496
- lhs, callop, (op, _), args = val
497
-
498
- result = new_call lhs, op.to_sym, args, callop
499
- result.line lhs.line
500
- }
501
- | primary_value call_op operation2 command_args cmd_brace_block
502
- {
503
- recv, _, (msg, _line), args, block = val
504
- call = new_call recv, msg.to_sym, args, val[1]
505
-
506
- block_dup_check call, block
507
-
508
- block.insert 1, call
509
- result = block
510
- }
511
- | primary_value tCOLON2 operation2 command_args =tLOWEST
512
- {
513
- lhs, _, (id, line), args = val
514
-
515
- result = new_call lhs, id.to_sym, args
516
- result.line line
517
- }
518
- | primary_value tCOLON2 operation2 command_args cmd_brace_block
519
- {
520
- recv, _, (msg, _line), args, block = val
521
- call = new_call recv, msg.to_sym, args
522
-
523
- block_dup_check call, block
524
-
525
- block.insert 1, call
526
- result = block
527
- }
528
- | kSUPER command_args
529
- {
530
- result = new_super val[1]
531
- }
532
- | kYIELD command_args
533
- {
534
- (_, line), args = val
535
- result = new_yield args
536
- result.line line # TODO: push to new_yield
537
- }
538
- | k_return call_args
539
- {
540
- line = val[0].last
541
- result = s(:return, ret_args(val[1])).line(line)
542
- }
543
- | kBREAK call_args
544
- {
545
- (_, line), args = val
546
- result = s(:break, ret_args(args)).line line
547
- }
548
- | kNEXT call_args
549
- {
550
- line = val[0].last
551
- result = s(:next, ret_args(val[1])).line(line)
552
- }
553
-
554
- mlhs: mlhs_basic
555
- | tLPAREN mlhs_inner rparen
556
- {
557
- result = val[1]
558
- }
559
-
560
- mlhs_inner: mlhs_basic
561
- | tLPAREN mlhs_inner rparen
562
- {
563
- _, arg, _ = val
564
- l = arg.line
565
-
566
- result = s(:masgn, s(:array, arg).line(l)).line l
567
- }
568
-
569
- mlhs_basic: mlhs_head
570
- {
571
- head, = val
572
- result = s(:masgn, head).line head.line
573
- }
574
- | mlhs_head mlhs_item
575
- {
576
- lhs, rhs = val
577
- result = s(:masgn, lhs << rhs.compact).line lhs.line
578
- }
579
- | mlhs_head tSTAR mlhs_node
580
- {
581
- head, _, tail = val
582
- head << s(:splat, tail).line(tail.line)
583
- result = s(:masgn, head).line head.line
584
- }
585
- | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
586
- {
587
- ary1, _, splat, _, ary2 = val
588
-
589
- result = list_append ary1, s(:splat, splat).line(splat.line)
590
- result.concat ary2.sexp_body
591
- result = s(:masgn, result).line result.line
592
- }
593
- | mlhs_head tSTAR
594
- {
595
- head, _ = val
596
- l = head.line
597
- result = s(:masgn, head << s(:splat).line(l)).line l
598
- }
599
- | mlhs_head tSTAR tCOMMA mlhs_post
600
- {
601
- head, _, _, post = val
602
- ary = list_append head, s(:splat).line(head.line)
603
- ary.concat post.sexp_body
604
- result = s(:masgn, ary).line ary.line
605
- }
606
- | tSTAR mlhs_node
607
- {
608
- _, node = val
609
- l = node.line
610
- splat = s(:splat, node).line l
611
- ary = s(:array, splat).line l
612
- result = s(:masgn, ary).line l
613
- }
614
- | tSTAR mlhs_node tCOMMA mlhs_post
615
- {
616
- _, node, _, post = val
617
-
618
- splat = s(:splat, node).line node.line
619
- ary = s(:array, splat).line splat.line
620
- ary.concat post.sexp_body
621
- result = s(:masgn, ary).line ary.line
622
- }
623
- | tSTAR
624
- {
625
- (_, l), = val
626
- result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
627
- }
628
- | tSTAR tCOMMA mlhs_post
629
- {
630
- _, _, post = val
631
- l = post.line
632
-
633
- splat = s(:splat).line l
634
- ary = s(:array, splat, *post.sexp_body).line l
635
- result = s(:masgn, ary).line l
636
- }
637
-
638
- mlhs_item: mlhs_node
639
- | tLPAREN mlhs_inner rparen
640
- {
641
- result = val[1]
642
- }
643
-
644
- mlhs_head: mlhs_item tCOMMA
645
- {
646
- lhs, _ = val
647
- result = s(:array, lhs).line lhs.line
648
- }
649
- | mlhs_head mlhs_item tCOMMA
650
- {
651
- result = val[0] << val[1].compact
652
- }
653
-
654
- mlhs_post: mlhs_item
655
- {
656
- item, = val
657
- result = s(:array, item).line item.line
658
- }
659
- | mlhs_post tCOMMA mlhs_item
660
- {
661
- result = list_append val[0], val[2]
662
- }
663
-
664
- mlhs_node: user_variable
665
- {
666
- result = self.assignable val[0]
667
- }
668
- | keyword_variable
669
- {
670
- result = self.assignable val[0]
671
- }
672
- | primary_value tLBRACK2 opt_call_args rbracket
673
- {
674
- result = self.aryset val[0], val[2]
675
- }
676
- | primary_value call_op tIDENTIFIER
677
- {
678
- lhs, call_op, (id, _line) = val
679
-
680
- result = new_attrasgn lhs, id, call_op
681
- }
682
- | primary_value tCOLON2 tIDENTIFIER
683
- {
684
- recv, _, (id, _line) = val
685
- result = new_attrasgn recv, id
686
- }
687
- | primary_value call_op tCONSTANT
688
- {
689
- lhs, call_op, (id, _line) = val
690
-
691
- result = new_attrasgn lhs, id, call_op
692
- }
693
- | primary_value tCOLON2 tCONSTANT
694
- {
695
- if (self.in_def || self.in_single > 0) then
696
- debug 4
697
- yyerror "dynamic constant assignment"
698
- end
699
-
700
- expr, _, (id, _line) = val
701
- l = expr.line
702
-
703
- result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
704
- }
705
- | tCOLON3 tCONSTANT
706
- {
707
- if (self.in_def || self.in_single > 0) then
708
- debug 5
709
- yyerror "dynamic constant assignment"
710
- end
711
-
712
- _, (id, l) = val
713
-
714
- result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
715
- }
716
- | backref
717
- {
718
- ref, = val
719
-
720
- self.backref_assign_error ref
721
- }
722
-
723
- lhs: user_variable
724
- {
725
- var, = val
726
-
727
- result = self.assignable var
728
- }
729
- | keyword_variable
730
- {
731
- var, = val
732
-
733
- result = self.assignable var
734
-
735
- debug 6
736
- }
737
- | primary_value tLBRACK2 opt_call_args rbracket
738
- {
739
- lhs, _, args, _ = val
740
-
741
- result = self.aryset lhs, args
742
- }
743
- | primary_value call_op tIDENTIFIER # REFACTOR
744
- {
745
- lhs, op, (id, _line) = val
746
-
747
- result = new_attrasgn lhs, id, op
748
- }
749
- | primary_value tCOLON2 tIDENTIFIER
750
- {
751
- lhs, _, (id, _line) = val
752
-
753
- result = new_attrasgn lhs, id
754
- }
755
- | primary_value call_op tCONSTANT # REFACTOR?
756
- {
757
- lhs, call_op, (id, _line) = val
758
-
759
- result = new_attrasgn lhs, id, call_op
760
- }
761
- | primary_value tCOLON2 tCONSTANT
762
- {
763
- expr, _, (id, _line) = val
764
-
765
- if (self.in_def || self.in_single > 0) then
766
- debug 7
767
- yyerror "dynamic constant assignment"
768
- end
769
-
770
- l = expr.line
771
- result = s(:const, s(:colon2, expr, id.to_sym).line(l)).line l
772
- }
773
- | tCOLON3 tCONSTANT
774
- {
775
- _, (id, l) = val
776
-
777
- if (self.in_def || self.in_single > 0) then
778
- debug 8
779
- yyerror "dynamic constant assignment"
780
- end
781
-
782
- result = s(:const, s(:colon3, id.to_sym).line(l)).line l
783
- }
784
- | backref
785
- {
786
- self.backref_assign_error val[0]
787
- }
788
-
789
- cname: tIDENTIFIER
790
- {
791
- yyerror "class/module name must be CONSTANT"
792
- }
793
- | tCONSTANT
794
-
795
- cpath: tCOLON3 cname
796
- {
797
- result = wrap :colon3, val[1]
798
- }
799
- | cname
800
- {
801
- (id, line), = val
802
- result = [id.to_sym, line] # TODO: sexp?
803
- }
804
- | primary_value tCOLON2 cname
805
- {
806
- pval, _, (name, _line) = val
807
-
808
- result = s(:colon2, pval, name.to_sym)
809
- result.line pval.line
810
- }
811
-
812
- fname: tIDENTIFIER | tCONSTANT | tFID
813
- | op
814
- {
815
- lexer.lex_state = EXPR_END
816
- }
817
-
818
- | reswords
819
-
820
- fitem: fname
821
- {
822
- result = wrap :lit, val[0]
823
- }
824
- | symbol
825
-
826
- undef_list: fitem
827
- {
828
- result = new_undef val[0]
829
- }
830
- |
831
- undef_list tCOMMA
832
- {
833
- lexer.lex_state = EXPR_FNAME
834
- }
835
- fitem
836
- {
837
- result = new_undef val[0], val[3]
838
- }
839
-
840
- op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
841
- | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
842
- | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
843
- | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
844
- | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
845
-
846
- reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
847
- | kALIAS | kAND | kBEGIN | kBREAK | kCASE
848
- | kCLASS | kDEF | kDEFINED | kDO | kELSE
849
- | kELSIF | kEND | kENSURE | kFALSE | kFOR
850
- | kIN | kMODULE | kNEXT | kNIL | kNOT
851
- | kOR | kREDO | kRESCUE | kRETRY | kRETURN
852
- | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
853
- | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
854
- | kUNTIL
855
-
856
- arg: lhs tEQL arg_rhs
857
- {
858
- result = new_assign val[0], val[2]
859
- }
860
- | var_lhs tOP_ASGN arg_rhs
861
- {
862
- result = new_op_asgn val
863
- }
864
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
865
- {
866
- result = new_op_asgn1 val
867
- }
868
- | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
869
- {
870
- result = new_op_asgn2 val
871
- }
872
- | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
873
- {
874
- result = new_op_asgn2 val
875
- }
876
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
877
- {
878
- lhs, _, (id, _line), (op, _), rhs = val
879
-
880
- result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
881
- }
882
- | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
883
- {
884
- lhs1, _, (lhs2, _line), op, rhs = val
885
-
886
- lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
887
- result = new_const_op_asgn [lhs, op, rhs]
888
- }
889
- | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
890
- {
891
- _, lhs, op, rhs = val
892
-
893
- lhs = wrap :colon3, lhs
894
- result = new_const_op_asgn [lhs, op, rhs]
895
- }
896
- | backref tOP_ASGN arg_rhs
897
- {
898
- # TODO: lhs = var_field val[0]
899
- asgn = new_op_asgn val
900
- result = self.backref_assign_error asgn
901
- }
902
- | arg tDOT2 arg
903
- {
904
- v1, v2 = val[0], val[2]
905
- if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
906
- result = s(:lit, (v1.last)..(v2.last)).line v1.line
907
- else
908
- result = s(:dot2, v1, v2).line v1.line
909
- end
910
- }
911
- | arg tDOT3 arg
912
- {
913
- v1, v2 = val[0], val[2]
914
- if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
915
- result = s(:lit, (v1.last)...(v2.last)).line v1.line
916
- else
917
- result = s(:dot3, v1, v2).line v1.line
918
- end
919
- }
920
- | arg tDOT2
921
- {
922
- v1, _ = val
923
- v2 = nil
924
-
925
- result = s(:dot2, v1, v2).line v1.line
926
- }
927
- | arg tDOT3
928
- {
929
- v1, _ = val
930
- v2 = nil
931
-
932
- result = s(:dot3, v1, v2).line v1.line
933
- }
934
-
935
- | tBDOT2 arg
936
- {
937
- _, v2, = val
938
- v1 = nil
939
-
940
- result = s(:dot2, v1, v2).line v2.line
941
- }
942
- | tBDOT3 arg
943
- {
944
- _, v2 = val
945
- v1 = nil
946
-
947
- result = s(:dot3, v1, v2).line v2.line
948
- }
949
-
950
- | arg tPLUS arg
951
- {
952
- result = new_call val[0], :+, argl(val[2])
953
- }
954
- | arg tMINUS arg
955
- {
956
- result = new_call val[0], :-, argl(val[2])
957
- }
958
- | arg tSTAR2 arg # TODO: rename
959
- {
960
- result = new_call val[0], :*, argl(val[2])
961
- }
962
- | arg tDIVIDE arg
963
- {
964
- result = new_call val[0], :"/", argl(val[2])
965
- }
966
- | arg tPERCENT arg
967
- {
968
- result = new_call val[0], :"%", argl(val[2])
969
- }
970
- | arg tPOW arg
971
- {
972
- result = new_call val[0], :**, argl(val[2])
973
- }
974
- | tUMINUS_NUM simple_numeric tPOW arg
975
- {
976
- _, num, _, arg = val
977
- lit = wrap :lit, num
978
- result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
979
-
980
- }
981
- | tUPLUS arg
982
- {
983
- result = new_call val[1], :"+@"
984
- }
985
- | tUMINUS arg
986
- {
987
- result = new_call val[1], :"-@"
988
- }
989
- | arg tPIPE arg
990
- {
991
- result = new_call val[0], :"|", argl(val[2])
992
- }
993
- | arg tCARET arg
994
- {
995
- result = new_call val[0], :"^", argl(val[2])
996
- }
997
- | arg tAMPER2 arg
998
- {
999
- result = new_call val[0], :"&", argl(val[2])
1000
- }
1001
- | arg tCMP arg
1002
- {
1003
- result = new_call val[0], :"<=>", argl(val[2])
1004
- }
1005
- | rel_expr =tCMP
1006
- | arg tEQ arg
1007
- {
1008
- result = new_call val[0], :"==", argl(val[2])
1009
- }
1010
- | arg tEQQ arg
1011
- {
1012
- result = new_call val[0], :"===", argl(val[2])
1013
- }
1014
- | arg tNEQ arg
1015
- {
1016
- result = new_call val[0], :"!=", argl(val[2])
1017
- }
1018
- | arg tMATCH arg
1019
- {
1020
- lhs, _, rhs = val
1021
- result = new_match lhs, rhs
1022
- }
1023
- | arg tNMATCH arg
1024
- {
1025
- lhs, _, rhs = val
1026
- result = s(:not, new_match(lhs, rhs)).line lhs.line
1027
- }
1028
- | tBANG arg
1029
- {
1030
- _, arg = val
1031
- result = new_call arg, :"!"
1032
- result.line arg.line
1033
- }
1034
- | tTILDE arg
1035
- {
1036
- result = new_call value_expr(val[1]), :"~"
1037
- }
1038
- | arg tLSHFT arg
1039
- {
1040
- val[0] = value_expr val[0]
1041
- val[2] = value_expr val[2]
1042
- result = new_call val[0], :"\<\<", argl(val[2])
1043
- }
1044
- | arg tRSHFT arg
1045
- {
1046
- val[0] = value_expr val[0]
1047
- val[2] = value_expr val[2]
1048
- result = new_call val[0], :">>", argl(val[2])
1049
- }
1050
- | arg tANDOP arg
1051
- {
1052
- result = logical_op :and, val[0], val[2]
1053
- }
1054
- | arg tOROP arg
1055
- {
1056
- result = logical_op :or, val[0], val[2]
1057
- }
1058
- | kDEFINED opt_nl arg
1059
- {
1060
- (_, line), _, arg = val
1061
- result = s(:defined, arg).line line
1062
- }
1063
- | arg tEH arg opt_nl tCOLON arg
1064
- {
1065
- c, _, t, _, _, f = val
1066
- result = s(:if, c, t, f).line c.line
1067
- }
1068
- | defn_head f_opt_paren_args tEQL arg
1069
- {
1070
- result = new_endless_defn val
1071
- }
1072
- | defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
1073
- {
1074
- result = new_endless_defn val
1075
- }
1076
- | defs_head f_opt_paren_args tEQL arg
1077
- {
1078
- result = new_endless_defs val
1079
- }
1080
- | defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
1081
- {
1082
- result = new_endless_defs val
1083
- }
1084
- | primary
1085
-
1086
- relop: tGT
1087
- | tLT
1088
- | tGEQ
1089
- | tLEQ
1090
-
1091
- rel_expr: arg relop arg =tGT
1092
- {
1093
- lhs, (op, _), rhs = val
1094
- result = new_call lhs, op.to_sym, argl(rhs)
1095
- }
1096
- | rel_expr relop arg =tGT
1097
- {
1098
- lhs, (op, _), rhs = val
1099
- warn "comparison '%s' after comparison", op
1100
- result = new_call lhs, op.to_sym, argl(rhs)
1101
- }
1102
-
1103
- arg_value: arg
1104
- {
1105
- result = value_expr(val[0])
1106
- }
1107
-
1108
- aref_args: none
1109
- | args trailer
1110
- {
1111
- result = args [val[0]]
1112
- }
1113
- | args tCOMMA assocs trailer
1114
- {
1115
- result = args [val[0], array_to_hash(val[2])]
1116
- }
1117
- | assocs trailer
1118
- {
1119
- result = args [array_to_hash(val[0])]
1120
- }
1121
-
1122
- arg_rhs: arg =tOP_ASGN
1123
- | arg kRESCUE_MOD arg
1124
- {
1125
- body, (_, line), resbody = val
1126
- body = value_expr body
1127
- resbody = remove_begin resbody
1128
-
1129
- ary = s(:array).line line
1130
- result = new_rescue(body, new_resbody(ary, resbody))
1131
- }
1132
-
1133
- paren_args: tLPAREN2 opt_call_args rparen
1134
- {
1135
- _, args, (_, line_max) = val
1136
-
1137
- result = args
1138
- result.line_max = line_max if args
1139
- }
1140
- | tLPAREN2 args tCOMMA args_forward rparen
1141
- {
1142
- yyerror "Unexpected ..." unless
1143
- self.lexer.is_local_id(:"*") &&
1144
- self.lexer.is_local_id(:"**") &&
1145
- self.lexer.is_local_id(:"&")
1146
-
1147
- result = call_args val
1148
- }
1149
- | tLPAREN2 args_forward rparen
1150
- {
1151
- yyerror "Unexpected ..." unless
1152
- self.lexer.is_local_id(:"*") &&
1153
- self.lexer.is_local_id(:"**") &&
1154
- self.lexer.is_local_id(:"&")
1155
-
1156
- result = call_args val
1157
- }
1158
-
1159
- opt_paren_args: none
1160
- | paren_args
1161
-
1162
- opt_call_args: none
1163
- | call_args
1164
- | args tCOMMA
1165
- {
1166
- result = args val
1167
- }
1168
- | args tCOMMA assocs tCOMMA
1169
- {
1170
- result = args [val[0], array_to_hash(val[2])]
1171
- }
1172
- | assocs tCOMMA
1173
- {
1174
- result = args [array_to_hash(val[0])]
1175
- }
1176
-
1177
- call_args: command
1178
- {
1179
- warning "parenthesize argument(s) for future version"
1180
- result = call_args val
1181
- }
1182
- | args opt_block_arg
1183
- {
1184
- result = call_args val
1185
- }
1186
- | assocs opt_block_arg
1187
- {
1188
- result = call_args [array_to_hash(val[0]), val[1]]
1189
- }
1190
- | args tCOMMA assocs opt_block_arg
1191
- {
1192
- result = call_args [val[0], array_to_hash(val[2]), val[3]]
1193
- }
1194
- | block_arg
1195
- {
1196
- result = call_args val
1197
- }
1198
-
1199
- command_args: {
1200
- # parse26.y line 2200
1201
-
1202
- # If call_args starts with a open paren '(' or
1203
- # '[', look-ahead reading of the letters calls
1204
- # CMDARG_PUSH(0), but the push must be done
1205
- # after CMDARG_PUSH(1). So this code makes them
1206
- # consistent by first cancelling the premature
1207
- # CMDARG_PUSH(0), doing CMDARG_PUSH(1), and
1208
- # finally redoing CMDARG_PUSH(0).
1209
-
1210
- result = yychar = self.last_token_type.first
1211
- lookahead = [:tLPAREN, :tLPAREN_ARG, :tLPAREN2, :tLBRACK, :tLBRACK2].include?(yychar)
1212
- lexer.cmdarg.pop if lookahead
1213
- lexer.cmdarg.push true
1214
- lexer.cmdarg.push false if lookahead
1215
- }
1216
- call_args
1217
- {
1218
- yychar, args = val
1219
-
1220
- # call_args can be followed by tLBRACE_ARG (that
1221
- # does CMDARG_PUSH(0) in the lexer) but the push
1222
- # must be done after CMDARG_POP() in the parser.
1223
- # So this code does CMDARG_POP() to pop 0 pushed
1224
- # by tLBRACE_ARG, CMDARG_POP() to pop 1 pushed
1225
- # by command_args, and CMDARG_PUSH(0) to restore
1226
- # back the flag set by tLBRACE_ARG.
1227
-
1228
- lookahead = [:tLBRACE_ARG].include?(yychar)
1229
- lexer.cmdarg.pop if lookahead
1230
- lexer.cmdarg.pop
1231
- lexer.cmdarg.push false if lookahead
1232
- result = args
1233
- }
1234
-
1235
- block_arg: tAMPER arg_value
1236
- {
1237
- _, arg = val
1238
- result = s(:block_pass, arg).line arg.line
1239
- }
1240
- | tAMPER
1241
- {
1242
- (_, line), = val
1243
- result = s(:block_pass).line line
1244
- }
1245
-
1246
- opt_block_arg: tCOMMA block_arg
1247
- {
1248
- result = val[1]
1249
- }
1250
- | none
1251
-
1252
- args: arg_value
1253
- {
1254
- arg, = val
1255
- lineno = arg.line
1256
-
1257
- result = s(:array, arg).line lineno
1258
- }
1259
- | tSTAR arg_value
1260
- {
1261
- _, arg = val
1262
- result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1263
- }
1264
- | args tCOMMA arg_value
1265
- {
1266
- args, _, id = val
1267
- result = self.list_append args, id
1268
- }
1269
- | args tCOMMA tSTAR arg_value
1270
- {
1271
- args, _, (_, line), id = val
1272
- result = self.list_append args, s(:splat, id).line(line)
1273
- }
1274
-
1275
- mrhs_arg: mrhs
1276
- {
1277
- result = new_masgn_arg val[0]
1278
- }
1279
- | arg_value
1280
- {
1281
- result = new_masgn_arg val[0], :wrap
1282
- }
1283
-
1284
- mrhs: args tCOMMA arg_value
1285
- {
1286
- result = val[0] << val[2]
1287
- }
1288
- | args tCOMMA tSTAR arg_value
1289
- {
1290
- arg, _, _, splat = val
1291
- result = self.arg_concat arg, splat
1292
- }
1293
- | tSTAR arg_value
1294
- {
1295
- _, arg = val
1296
- result = s(:splat, arg).line arg.line
1297
- }
1298
-
1299
- primary: literal
1300
- | strings
1301
- | xstring
1302
- | regexp
1303
- | words
1304
- | qwords
1305
- | symbols
1306
- | qsymbols
1307
- | var_ref
1308
- | backref
1309
- | tFID
1310
- {
1311
- (msg, line), = val
1312
- result = new_call nil, msg.to_sym
1313
- result.line line
1314
- }
1315
- | k_begin
1316
- {
1317
- lexer.cmdarg.push false
1318
- }
1319
- bodystmt k_end
1320
- {
1321
- lexer.cmdarg.pop
1322
- result = new_begin val
1323
- }
1324
- | tLPAREN_ARG
1325
- {
1326
- lexer.lex_state = EXPR_ENDARG
1327
- }
1328
- rparen
1329
- {
1330
- (_, line), _, _ = val
1331
- result = s(:begin).line line
1332
- }
1333
- | tLPAREN_ARG
1334
- stmt
1335
- {
1336
- lexer.lex_state = EXPR_ENDARG
1337
- }
1338
- rparen
1339
- {
1340
- _, stmt, _, _, = val
1341
- # warning "(...) interpreted as grouped expression"
1342
- result = stmt
1343
- }
1344
- | tLPAREN compstmt tRPAREN
1345
- {
1346
- (_, line), stmt, _ = val
1347
- result = stmt || s(:nil).line(line)
1348
- result.paren = true
1349
- }
1350
- | primary_value tCOLON2 tCONSTANT
1351
- {
1352
- expr, _, (id, _line) = val
1353
-
1354
- result = s(:colon2, expr, id.to_sym).line expr.line
1355
- }
1356
- | tCOLON3 tCONSTANT
1357
- {
1358
- result = wrap :colon3, val[1]
1359
- }
1360
- | tLBRACK aref_args rbracket
1361
- {
1362
- (_, line), args, (_, line_max) = val
1363
-
1364
- result = args || s(:array)
1365
- result.sexp_type = :array # aref_args is :args
1366
- result.line line
1367
- result.line_max = line_max
1368
- }
1369
- | tLBRACE
1370
- {
1371
- result = self.lexer.lineno
1372
- }
1373
- assoc_list tRCURLY
1374
- {
1375
- result = new_hash val
1376
- }
1377
- | k_return
1378
- {
1379
- (_, line), = val
1380
- result = s(:return).line line
1381
- }
1382
- | kYIELD tLPAREN2 call_args rparen
1383
- {
1384
- (_, line), _, args, _ = val
1385
-
1386
- result = new_yield(args).line line
1387
- }
1388
- | kYIELD tLPAREN2 rparen
1389
- {
1390
- (_, line), _, _ = val
1391
-
1392
- result = new_yield.line line
1393
- }
1394
- | kYIELD
1395
- {
1396
- (_, line), = val
1397
-
1398
- result = new_yield.line line
1399
- }
1400
- | kDEFINED opt_nl tLPAREN2 expr rparen
1401
- {
1402
- (_, line), _, _, arg, _ = val
1403
-
1404
- result = s(:defined, arg).line line
1405
- }
1406
- | kNOT tLPAREN2 expr rparen
1407
- {
1408
- _, _, lhs, _ = val
1409
- result = new_call lhs, :"!"
1410
- }
1411
- | kNOT tLPAREN2 rparen
1412
- {
1413
- debug 9
1414
- }
1415
- | fcall brace_block
1416
- {
1417
- call, iter = val
1418
-
1419
- iter.insert 1, call
1420
- result = iter
1421
- # FIX: probably not: call.line = iter.line
1422
- }
1423
- | method_call
1424
- | method_call brace_block
1425
- {
1426
- call, iter = val[0], val[1]
1427
- block_dup_check call, iter
1428
- iter.insert 1, call # FIX
1429
- result = iter
1430
- }
1431
- | lambda
1432
- {
1433
- expr, = val
1434
- result = expr
1435
- }
1436
- | k_if expr_value then compstmt if_tail k_end
1437
- {
1438
- _, c, _, t, f, _ = val
1439
- result = new_if c, t, f
1440
- }
1441
- | k_unless expr_value then compstmt opt_else k_end
1442
- {
1443
- _, c, _, t, f, _ = val
1444
- result = new_if c, f, t
1445
- }
1446
- | k_while expr_value_do compstmt k_end
1447
- {
1448
- _, cond, body, _ = val
1449
- result = new_while body, cond, true
1450
- }
1451
- | k_until expr_value_do compstmt k_end
1452
- {
1453
- _, cond, body, _ = val
1454
- result = new_until body, cond, true
1455
- }
1456
- | k_case expr_value opt_terms case_body k_end
1457
- {
1458
- (_, line), expr, _, body, _ = val
1459
- result = new_case expr, body, line
1460
- }
1461
- | k_case opt_terms case_body k_end
1462
- {
1463
- (_, line), _, body, _ = val
1464
- result = new_case nil, body, line
1465
- }
1466
- | k_case expr_value opt_terms p_case_body k_end
1467
- {
1468
- (_, line), expr, _, body, _ = val
1469
-
1470
- result = new_case expr, body, line
1471
- }
1472
- | k_for for_var kIN expr_value_do compstmt k_end
1473
- {
1474
- _, var, _, iter, body, _ = val
1475
- result = new_for iter, var, body
1476
- }
1477
- | k_class
1478
- cpath superclass
1479
- {
1480
- if (self.in_def || self.in_single > 0) then
1481
- yyerror "class definition in method body"
1482
- end
1483
- self.env.extend
1484
- }
1485
- bodystmt k_end
1486
- {
1487
- result = new_class val
1488
- self.env.unextend
1489
- self.lexer.ignore_body_comments
1490
- }
1491
- | k_class tLSHFT
1492
- expr
1493
- {
1494
- result = self.in_def
1495
- self.in_def = false
1496
- }
1497
- term
1498
- {
1499
- result = self.in_single
1500
- self.in_single = 0
1501
- self.env.extend
1502
- }
1503
- bodystmt
1504
- k_end
1505
- {
1506
- result = new_sclass val
1507
- self.env.unextend
1508
- self.lexer.ignore_body_comments
1509
- }
1510
- | k_module
1511
- cpath
1512
- {
1513
- yyerror "module definition in method body" if
1514
- self.in_def or self.in_single > 0
1515
-
1516
- self.env.extend
1517
- }
1518
- bodystmt k_end
1519
- {
1520
- result = new_module val
1521
- self.env.unextend
1522
- self.lexer.ignore_body_comments
1523
- }
1524
- | defn_head f_arglist bodystmt k_end
1525
- {
1526
- # [ [:f, 1, false], s(:args)...]
1527
- # =>
1528
- # [[:k_def, 666], [:f, 1], false, s(:args)...]
1529
- val.insert 1, val.first.pop
1530
- val.insert 0, [:k_def, 666]
1531
-
1532
- result, in_def = new_defn val
1533
-
1534
- lexer.cond.pop # group = local_pop
1535
- lexer.cmdarg.pop
1536
- self.env.unextend
1537
- self.in_def = in_def
1538
-
1539
- self.lexer.ignore_body_comments
1540
- }
1541
- | defs_head f_arglist bodystmt k_end
1542
- {
1543
- # [ [recv, [:name, 1, false]], s(:args...]
1544
- # =>
1545
- # [ recv, [:name, 1, false], s(:args...]
1546
- # =>
1547
- # [ recv, [:name, 1], false, s(:args...]
1548
- # =>
1549
- # [ :k_def, recv, [:name, 1], false, s(:args...]
1550
-
1551
- val.prepend(*val.shift)
1552
- val.insert 2, val[1].pop
1553
- val.insert 0, [:k_def, 666]
1554
-
1555
- result, in_def = new_defs val
1556
-
1557
- lexer.cond.pop # group = local_pop
1558
- lexer.cmdarg.pop
1559
- self.env.unextend
1560
- self.in_def = in_def
1561
-
1562
- self.in_single -= 1
1563
-
1564
- # TODO: restore cur_arg ? what's cur_arg?
1565
-
1566
- self.lexer.ignore_body_comments
1567
- }
1568
- | kBREAK
1569
- {
1570
- (_, line), = val
1571
- result = s(:break).line line
1572
- }
1573
- | kNEXT
1574
- {
1575
- (_, line), = val
1576
- result = s(:next).line line
1577
- }
1578
- | kREDO
1579
- {
1580
- (_, line), = val
1581
- result = s(:redo).line line
1582
- }
1583
- | kRETRY
1584
- {
1585
- (_, line), = val
1586
- result = s(:retry).line line
1587
- }
1588
-
1589
- primary_value: primary
1590
- {
1591
- result = value_expr(val[0])
1592
- }
1593
-
1594
- # These are really stupid
1595
- k_begin: kBEGIN
1596
- k_if: kIF
1597
- k_unless: kUNLESS
1598
- k_while: kWHILE
1599
- k_until: kUNTIL
1600
- k_case: kCASE
1601
- k_for: kFOR
1602
- k_class: kCLASS
1603
- {
1604
- self.comments.push self.lexer.comments
1605
- }
1606
- k_module: kMODULE
1607
- {
1608
- self.comments.push self.lexer.comments
1609
- }
1610
- k_def: kDEF
1611
- {
1612
- self.comments.push self.lexer.comments
1613
- self.in_argdef = true
1614
- }
1615
- k_do: kDO
1616
- k_do_block: kDO_BLOCK
1617
- k_rescue: kRESCUE
1618
- k_ensure: kENSURE
1619
- k_when: kWHEN
1620
- k_else: kELSE
1621
- k_elsif: kELSIF
1622
- k_end: kEND
1623
- k_return: kRETURN
1624
-
1625
- then: term
1626
- | kTHEN
1627
- | term kTHEN
1628
-
1629
- do: term
1630
- | kDO_COND
1631
-
1632
- if_tail: opt_else
1633
- | k_elsif expr_value then compstmt if_tail
1634
- {
1635
- (_, line), c, _, t, rest = val
1636
-
1637
- result = s(:if, c, t, rest).line line
1638
- }
1639
-
1640
- opt_else: none
1641
- | kELSE compstmt
1642
- {
1643
- result = val[1]
1644
- }
1645
-
1646
- for_var: lhs
1647
- | mlhs
1648
- {
1649
- val[0].delete_at 1 if val[0][1].nil? # HACK
1650
- }
1651
-
1652
- f_marg: f_norm_arg
1653
- {
1654
- (sym, line), = val
1655
-
1656
- result = s(:dummy, sym).line line
1657
- }
1658
- | tLPAREN f_margs rparen
1659
- {
1660
- _, args, _ = val
1661
- result = args
1662
- }
1663
-
1664
- f_marg_list: f_marg
1665
- {
1666
- arg, = val
1667
- line = arg.line
1668
-
1669
- arg = arg.last if arg.sexp_type == :dummy
1670
-
1671
- result = s(:array, arg).line line
1672
- }
1673
- | f_marg_list tCOMMA f_marg
1674
- {
1675
- args, _, arg = val
1676
-
1677
- arg = arg.last if arg.sexp_type == :dummy
1678
-
1679
- result = list_append args, arg
1680
- }
1681
-
1682
- f_margs: f_marg_list
1683
- {
1684
- args, = val
1685
-
1686
- result = block_var args
1687
- }
1688
- | f_marg_list tCOMMA f_rest_marg
1689
- {
1690
- args, _, rest = val
1691
-
1692
- result = block_var args, rest
1693
- }
1694
- | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1695
- {
1696
- lhs, _, splat, _, rhs = val
1697
-
1698
- result = block_var lhs, splat, rhs
1699
- }
1700
- | f_rest_marg
1701
- {
1702
- rest, = val
1703
-
1704
- result = block_var rest
1705
- }
1706
- | f_rest_marg tCOMMA f_marg_list
1707
- {
1708
- splat, _, rest = val
1709
-
1710
- result = block_var splat, rest
1711
- }
1712
-
1713
- f_rest_marg: tSTAR f_norm_arg
1714
- {
1715
- _, (id, line) = val
1716
-
1717
- result = args ["*#{id}".to_sym]
1718
- result.line line
1719
- }
1720
- | tSTAR
1721
- {
1722
- (_, line), = val
1723
- result = args([:*]).line line
1724
- }
1725
-
1726
- f_any_kwrest: f_kwrest
1727
- | f_no_kwarg
1728
-
1729
- f_eq: { self.in_argdef = false } tEQL
1730
-
1731
- block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1732
- {
1733
- result = call_args val
1734
- }
1735
- | f_block_kwarg opt_f_block_arg
1736
- {
1737
- result = call_args val
1738
- }
1739
- | f_any_kwrest opt_f_block_arg
1740
- {
1741
- result = call_args val
1742
- }
1743
- | f_block_arg
1744
- {
1745
- (id, line), = val
1746
- result = call_args [id]
1747
- result.line line
1748
- }
1749
-
1750
- opt_block_args_tail: tCOMMA block_args_tail
1751
- {
1752
- result = args val
1753
- }
1754
- | none
1755
-
1756
- excessed_comma: tCOMMA
1757
- {
1758
- result = s(:WTF_COMMA!)
1759
- }
1760
-
1761
- block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1762
- {
1763
- result = args val
1764
- }
1765
- | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1766
- {
1767
- result = args val
1768
- }
1769
- | f_arg tCOMMA f_block_optarg opt_block_args_tail
1770
- {
1771
- result = args val
1772
- }
1773
- | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1774
- {
1775
- result = args val
1776
- }
1777
- | f_arg tCOMMA f_rest_arg opt_block_args_tail
1778
- {
1779
- result = args val
1780
- }
1781
- | f_arg excessed_comma
1782
- {
1783
- arg, _ = val
1784
- result = arg << nil
1785
- }
1786
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1787
- {
1788
- result = args val
1789
- }
1790
- | f_arg opt_block_args_tail
1791
- {
1792
- result = args val
1793
- }
1794
- | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1795
- {
1796
- result = args val
1797
- }
1798
- | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1799
- {
1800
- result = args val
1801
- }
1802
- | f_block_optarg opt_block_args_tail
1803
- {
1804
- result = args val
1805
- }
1806
- | f_block_optarg tCOMMA f_arg opt_block_args_tail
1807
- {
1808
- result = args val
1809
- }
1810
- | f_rest_arg opt_block_args_tail
1811
- {
1812
- result = args val
1813
- }
1814
- | f_rest_arg tCOMMA f_arg opt_block_args_tail
1815
- {
1816
- result = args val
1817
- }
1818
- | block_args_tail
1819
- {
1820
- result = args val
1821
- }
1822
-
1823
- opt_block_param: none { result = 0 }
1824
- | block_param_def
1825
- {
1826
- self.lexer.command_start = true
1827
- }
1828
-
1829
- block_param_def: tPIPE opt_bv_decl tPIPE
1830
- {
1831
- # TODO: current_arg = 0
1832
- result = args val
1833
- self.in_argdef = false
1834
- }
1835
- | tOROP
1836
- {
1837
- (_, line), = val
1838
-
1839
- result = s(:args).line line
1840
- }
1841
- | tPIPE block_param opt_bv_decl tPIPE
1842
- {
1843
- # TODO: current_arg = 0
1844
- result = args val
1845
- self.in_argdef = false
1846
- }
1847
-
1848
- opt_bv_decl: opt_nl
1849
- | opt_nl tSEMI bv_decls opt_nl
1850
- {
1851
- result = args val
1852
- }
1853
-
1854
- bv_decls: bvar
1855
- {
1856
- result = args val
1857
- }
1858
- | bv_decls tCOMMA bvar
1859
- {
1860
- result = args val
1861
- }
1862
-
1863
- bvar: tIDENTIFIER
1864
- {
1865
- result = wrap :shadow, val[0]
1866
- }
1867
- | f_bad_arg
1868
-
1869
- lambda: tLAMBDA
1870
- {
1871
- self.env.extend :dynamic
1872
- result = lexer.lpar_beg
1873
- lexer.paren_nest += 1
1874
- lexer.lpar_beg = lexer.paren_nest
1875
- }
1876
- f_larglist
1877
- {
1878
- lexer.cmdarg.push false
1879
- }
1880
- lambda_body
1881
- {
1882
- (_, line), lpar, args, _cmdarg, body = val
1883
- lexer.lpar_beg = lpar
1884
-
1885
- lexer.cmdarg.pop
1886
-
1887
- call = s(:lambda).line line
1888
- result = new_iter call, args, body
1889
- result.line line
1890
- self.env.unextend # TODO: dynapush & dynapop
1891
- }
1892
-
1893
- f_larglist: tLPAREN2 f_args opt_bv_decl rparen
1894
- {
1895
- self.in_argdef = false
1896
- result = args val
1897
- }
1898
- | f_args
1899
- {
1900
- self.in_argdef = false
1901
- result = val[0]
1902
- result = 0 if result == s(:args)
1903
- }
1904
-
1905
- lambda_body: tLAMBEG compstmt tRCURLY
1906
- {
1907
- result = val[1]
1908
- }
1909
- | kDO_LAMBDA bodystmt kEND
1910
- {
1911
- result = val[1]
1912
- }
1913
-
1914
- do_block: k_do_block do_body kEND
1915
- {
1916
- (_, line), iter, _ = val
1917
- result = iter.line line
1918
- }
1919
-
1920
- block_call: command do_block
1921
- {
1922
- # TODO:
1923
- ## if (nd_type($1) == NODE_YIELD) {
1924
- ## compile_error(PARSER_ARG "block given to yield");
1925
-
1926
- cmd, blk = val
1927
-
1928
- syntax_error "Both block arg and actual block given." if
1929
- cmd.block_pass?
1930
-
1931
- if inverted? val then
1932
- val = invert_block_call val
1933
- cmd, blk = val
1934
- end
1935
-
1936
- result = blk
1937
- result.insert 1, cmd
1938
- }
1939
- | block_call call_op2 operation2 opt_paren_args
1940
- {
1941
- lhs, _, (id, _line), args = val
1942
-
1943
- result = new_call lhs, id.to_sym, args
1944
- }
1945
- | block_call call_op2 operation2 opt_paren_args brace_block
1946
- {
1947
- iter1, _, (name, _line), args, iter2 = val
1948
-
1949
- call = new_call iter1, name.to_sym, args
1950
- iter2.insert 1, call
1951
-
1952
- result = iter2
1953
- }
1954
- | block_call call_op2 operation2 command_args do_block
1955
- {
1956
- iter1, _, (name, _line), args, iter2 = val
1957
-
1958
- call = new_call iter1, name.to_sym, args
1959
- iter2.insert 1, call
1960
-
1961
- result = iter2
1962
- }
1963
-
1964
- method_call: fcall paren_args
1965
- {
1966
- call, args = val
1967
-
1968
- result = call
1969
-
1970
- if args then
1971
- call.concat args.sexp_body
1972
- result.line_max = args.line_max
1973
- end
1974
- }
1975
- | primary_value call_op operation2 opt_paren_args
1976
- {
1977
- recv, call_op, (op, op_line), args = val
1978
-
1979
- result = new_call recv, op.to_sym, args, call_op
1980
- result.line_max = op_line unless args
1981
- }
1982
- | primary_value tCOLON2 operation2 paren_args
1983
- {
1984
- recv, _, (op, _line), args = val
1985
-
1986
- result = new_call recv, op.to_sym, args
1987
- }
1988
- | primary_value tCOLON2 operation3
1989
- {
1990
- lhs, _, (id, _line) = val
1991
-
1992
- result = new_call lhs, id.to_sym
1993
- }
1994
- | primary_value call_op paren_args
1995
- {
1996
- result = new_call val[0], :call, val[2], val[1]
1997
- }
1998
- | primary_value tCOLON2 paren_args
1999
- {
2000
- result = new_call val[0], :call, val[2]
2001
- }
2002
- | kSUPER paren_args
2003
- {
2004
- result = new_super val[1]
2005
- }
2006
- | kSUPER
2007
- {
2008
- (_, line), = val
2009
- result = s(:zsuper).line line
2010
- }
2011
- | primary_value tLBRACK2 opt_call_args rbracket
2012
- {
2013
- result = new_aref val
2014
- }
2015
-
2016
- brace_block: tLCURLY
2017
- {
2018
- self.env.extend :dynamic
2019
- }
2020
- brace_body
2021
- tRCURLY
2022
- {
2023
- (_, line), _, body, _ = val
2024
-
2025
- result = body
2026
- result.line line
2027
-
2028
- self.env.unextend
2029
- }
2030
- | k_do
2031
- {
2032
- self.env.extend :dynamic
2033
- }
2034
- do_body
2035
- kEND
2036
- {
2037
- (_, line), _, body, _ = val
2038
-
2039
- result = body
2040
- result.line line
2041
-
2042
- self.env.unextend
2043
- }
2044
-
2045
- brace_body: { self.env.extend :dynamic; result = self.lexer.lineno }
2046
- { result = lexer.cmdarg.store(false) }
2047
- opt_block_param compstmt
2048
- {
2049
- line, cmdarg, param, cmpstmt = val
2050
-
2051
- result = new_brace_body param, cmpstmt, line
2052
- self.env.unextend
2053
- lexer.cmdarg.restore cmdarg
2054
- lexer.cmdarg.pop # because of: cmdarg_stack >> 1 ?
2055
- }
2056
-
2057
- do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
2058
- { lexer.cmdarg.push false }
2059
- opt_block_param
2060
- bodystmt
2061
- {
2062
- line, _cmdarg, param, cmpstmt = val
2063
-
2064
- result = new_do_body param, cmpstmt, line
2065
- lexer.cmdarg.pop
2066
- self.env.unextend
2067
- }
2068
-
2069
- case_args: arg_value
2070
- {
2071
- arg, = val
2072
-
2073
- result = s(:array, arg).line arg.line
2074
- }
2075
- | tSTAR arg_value
2076
- {
2077
- _, arg = val
2078
-
2079
- result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
2080
- }
2081
- | case_args tCOMMA arg_value
2082
- {
2083
- args, _, id = val
2084
-
2085
- result = self.list_append args, id
2086
- }
2087
- | case_args tCOMMA tSTAR arg_value
2088
- {
2089
- args, _, _, id = val
2090
-
2091
- result = self.list_append args, s(:splat, id).line(id.line)
2092
- }
2093
-
2094
- case_body: k_when
2095
- case_args then compstmt cases
2096
- {
2097
- (_, line), case_args, _then, body, cases = val
2098
-
2099
- result = new_when case_args, body
2100
- result.line line
2101
- result << cases if cases
2102
- }
2103
-
2104
- cases: opt_else | case_body
2105
- ######################################################################
2106
-
2107
- p_case_body: kIN
2108
- {
2109
- self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
2110
- self.lexer.command_start = false
2111
- result = self.in_kwarg
2112
- self.in_kwarg = true
2113
- push_pvtbl
2114
- push_pktbl
2115
- }
2116
- p_top_expr then
2117
- {
2118
- pop_pktbl
2119
- pop_pvtbl
2120
- old_kwargs = _values[-3]
2121
- self.in_kwarg = old_kwargs
2122
- }
2123
- compstmt
2124
- p_cases
2125
- {
2126
- (_, line), _, pat, _, _, body, cases = val
2127
-
2128
- result = new_in pat, body, cases, line
2129
- }
2130
-
2131
- p_cases: opt_else
2132
- | p_case_body
2133
-
2134
- p_top_expr: p_top_expr_body
2135
- | p_top_expr_body kIF_MOD expr_value
2136
- {
2137
- body, _, cond = val
2138
- body = remove_begin body
2139
-
2140
- result = s(:if, cond, body, nil).line body.line
2141
- }
2142
- | p_top_expr_body kUNLESS_MOD expr_value
2143
- {
2144
- body, _, cond = val
2145
- body = remove_begin body
2146
-
2147
- result = s(:if, cond, nil, body).line body.line
2148
- }
2149
-
2150
- p_top_expr_body: p_expr
2151
- | p_expr tCOMMA
2152
- {
2153
- expr, _ = val
2154
-
2155
- tail = new_array_pattern_tail nil, true, nil, nil
2156
- result = new_array_pattern nil, expr, tail, expr.line
2157
- }
2158
- | p_expr tCOMMA p_args
2159
- {
2160
- expr, _, args = val
2161
-
2162
- result = new_array_pattern nil, expr, args, expr.line
2163
- }
2164
- | p_find
2165
- {
2166
- find, = val
2167
-
2168
- result = new_find_pattern nil, find
2169
- }
2170
- | p_args_tail
2171
- {
2172
- args, = val
2173
- result = new_array_pattern nil, nil, args, args.line
2174
- }
2175
- | p_kwargs
2176
- {
2177
- kwargs, = val
2178
- result = new_hash_pattern nil, kwargs, kwargs.line
2179
- }
2180
-
2181
- p_expr: p_as
2182
-
2183
- p_as: p_expr tASSOC p_variable
2184
- {
2185
- # NODE *n = NEW_LIST($1, &@$);
2186
- # n = list_append(p, n, $3);
2187
- # $$ = new_hash(p, n, &@$);
2188
-
2189
- expr, _, var = val
2190
-
2191
- id = var.last
2192
-
2193
- self.env[id] = :lvar # HACK: need to extend env
2194
- lhs = s(:lasgn, id).line var.line
2195
-
2196
- result = new_assign lhs, expr
2197
- }
2198
- | p_alt
2199
-
2200
- p_alt: p_alt tPIPE p_expr_basic
2201
- {
2202
- lhs, _, rhs = val
2203
-
2204
- result = s(:or, lhs, rhs).line lhs.line
2205
- }
2206
- | p_expr_basic
2207
-
2208
- p_lparen: tLPAREN2 { push_pktbl }
2209
- p_lbracket: tLBRACK2 { push_pktbl }
2210
-
2211
- p_expr_basic: p_value
2212
- | p_variable
2213
- | p_const p_lparen p_args tRPAREN
2214
- {
2215
- lhs, _, args, _ = val
2216
-
2217
- pop_pktbl
2218
- result = new_array_pattern(lhs, nil, args, lhs.line)
2219
- }
2220
- | p_const p_lparen p_find tRPAREN
2221
- {
2222
- const, _, find, _ = val
2223
-
2224
- pop_pktbl
2225
- result = new_find_pattern(const, find).line const.line
2226
- }
2227
- | p_const p_lparen p_kwargs tRPAREN
2228
- {
2229
- lhs, _, kwargs, _ = val
2230
-
2231
- pop_pktbl
2232
- result = new_hash_pattern(lhs, kwargs, lhs.line)
2233
- }
2234
- | p_const tLPAREN2 tRPAREN
2235
- {
2236
- const, _, _ = val
2237
-
2238
- tail = new_array_pattern_tail nil, nil, nil, nil
2239
- result = new_array_pattern const, nil, tail, const.line
2240
- }
2241
- | p_const p_lbracket p_args rbracket
2242
- {
2243
- const, _, pre_arg, _ = val
2244
-
2245
- pop_pktbl
2246
- result = new_array_pattern const, nil, pre_arg, const.line
2247
- }
2248
- | p_const p_lbracket p_find rbracket
2249
- {
2250
- const, _, find, _ = val
2251
-
2252
- pop_pktbl
2253
- result = new_find_pattern(const, find).line const.line
2254
- }
2255
- | p_const p_lbracket p_kwargs rbracket
2256
- {
2257
- const, _, kwargs, _ = val
2258
-
2259
- result = new_hash_pattern const, kwargs, const.line
2260
- }
2261
- | p_const tLBRACK2 rbracket
2262
- {
2263
- const, _, _ = val
2264
-
2265
- tail = new_array_pattern_tail nil, nil, nil, nil
2266
- result = new_array_pattern const, nil, tail, const.line
2267
- }
2268
- | tLBRACK p_args rbracket
2269
- {
2270
- _, pat, _ = val
2271
-
2272
- result = new_array_pattern nil, nil, pat, pat.line
2273
- }
2274
- | tLBRACK p_find rbracket
2275
- {
2276
- _, find, _ = val
2277
-
2278
- result = new_find_pattern nil, find
2279
- }
2280
- | tLBRACK rbracket
2281
- {
2282
- (_, line), _ = val
2283
-
2284
- result = s(:array_pat).line line
2285
- }
2286
- | tLBRACE
2287
- {
2288
- push_pktbl
2289
- result = self.in_kwarg
2290
- self.in_kwarg = false
2291
- }
2292
- p_kwargs rbrace
2293
- {
2294
- _, in_kwarg, kwargs, _ = val
2295
-
2296
- pop_pktbl
2297
- self.in_kwarg = in_kwarg
2298
-
2299
- result = new_hash_pattern(nil, kwargs, kwargs.line)
2300
- }
2301
- | tLBRACE rbrace
2302
- {
2303
- (_, line), _ = val
2304
-
2305
- tail = new_hash_pattern_tail nil, nil, line
2306
- result = new_hash_pattern nil, tail, line
2307
- }
2308
- | tLPAREN { push_pktbl } p_expr tRPAREN
2309
- {
2310
- _, _, expr, _ = val
2311
-
2312
- pop_pktbl
2313
- result = expr
2314
- }
2315
-
2316
- p_args: p_expr
2317
- {
2318
- expr, = val
2319
-
2320
- ary = s(:array_TAIL, expr).line expr.line
2321
- result = new_array_pattern_tail(ary, nil, nil, nil).line expr.line
2322
- }
2323
- | p_args_head
2324
- {
2325
- head, = val
2326
-
2327
- result = new_array_pattern_tail head, true, nil, nil
2328
- }
2329
- | p_args_head p_arg
2330
- {
2331
- head, tail = val
2332
-
2333
- both = array_pat_concat head, tail
2334
-
2335
- result = new_array_pattern_tail both, nil, nil, nil
2336
- result.line head.line
2337
- }
2338
- | p_args_head tSTAR tIDENTIFIER
2339
- {
2340
- head, _, (id, _line) = val
2341
-
2342
- result = new_array_pattern_tail head, true, id.to_sym, nil
2343
- result.line head.line
2344
- }
2345
- | p_args_head tSTAR tIDENTIFIER tCOMMA p_args_post
2346
- {
2347
- head, _, (id, _line), _, post = val
2348
-
2349
- result = new_array_pattern_tail head, true, id.to_sym, post
2350
- result.line head.line
2351
- }
2352
- | p_args_head tSTAR
2353
- {
2354
- expr, _ = val
2355
-
2356
- result = new_array_pattern_tail(expr, true, nil, nil).line expr.line
2357
- }
2358
- | p_args_head tSTAR tCOMMA p_args_post
2359
- {
2360
- head, _, _, post = val
2361
-
2362
- result = new_array_pattern_tail(head, true, nil, post).line head.line
2363
- }
2364
- | p_args_tail
2365
-
2366
- p_args_head: p_arg tCOMMA
2367
- {
2368
- arg, _ = val
2369
- result = arg
2370
- }
2371
- | p_args_head p_arg tCOMMA
2372
- {
2373
- head, tail, _ = val
2374
-
2375
- result = s(:PATTERN, *head.sexp_body, *tail.sexp_body)
2376
- result.line head.line
2377
- }
2378
-
2379
- p_args_tail: p_rest
2380
- {
2381
- (id, line), = val
2382
-
2383
- result = new_array_pattern_tail nil, true, id, nil
2384
- result.line line
2385
- }
2386
- | p_rest tCOMMA p_args_post
2387
- {
2388
- (id, line), _, rhs = val
2389
-
2390
- result = new_array_pattern_tail nil, true, id, rhs
2391
- result.line line
2392
- }
2393
-
2394
- p_find: p_rest tCOMMA p_args_post tCOMMA p_rest
2395
- {
2396
- lhs, _, mid, _, rhs = val
2397
-
2398
- result = new_find_pattern_tail lhs, mid, rhs
2399
- }
2400
-
2401
- p_rest: tSTAR tIDENTIFIER
2402
- {
2403
- _, (id, line) = val
2404
-
2405
- result = [id.to_sym, line]
2406
- }
2407
- | tSTAR
2408
- {
2409
- (_id, line), = val
2410
-
2411
- result = [nil, line]
2412
- }
2413
-
2414
- p_args_post: p_arg
2415
- | p_args_post tCOMMA p_arg
2416
- {
2417
- lhs, _, rhs = val
2418
-
2419
- result = array_pat_concat lhs, rhs
2420
- }
2421
-
2422
- p_arg: p_expr
2423
- {
2424
- expr, = val
2425
- expr = s(:array_TAIL, expr).line expr.line unless
2426
- expr.sexp_type == :array_TAIL
2427
- result = expr
2428
- }
2429
-
2430
- p_kwargs: p_kwarg tCOMMA p_any_kwrest
2431
- {
2432
- kw_arg, _, rest = val
2433
- # TODO? new_unique_key_hash(p, $1, &@$)
2434
- result = new_hash_pattern_tail kw_arg, rest, kw_arg.line
2435
- }
2436
- | p_kwarg
2437
- {
2438
- kwarg, = val
2439
- # TODO? new_unique_key_hash(p, $1, &@$)
2440
- result = new_hash_pattern_tail kwarg, nil, kwarg.line
2441
- }
2442
- | p_kwarg tCOMMA
2443
- {
2444
- kwarg, _ = val
2445
- # TODO? new_unique_key_hash(p, $1, &@$)
2446
- result = new_hash_pattern_tail kwarg, nil, kwarg.line
2447
- }
2448
- | p_any_kwrest
2449
- {
2450
- rest, = val
2451
-
2452
- result = new_hash_pattern_tail nil, rest, rest.line
2453
- }
2454
-
2455
- p_kwarg: p_kw # TODO? rb_ary_new_from_args(1, $1)
2456
- | p_kwarg tCOMMA p_kw
2457
- {
2458
- kwarg, _, kw = val
2459
- kwarg.concat kw.sexp_body
2460
- result = kwarg
2461
- }
2462
-
2463
- p_kw: p_kw_label p_expr
2464
- {
2465
- # TODO: error_duplicate_pattern_key(p, get_id($1), &@1);
2466
- lhs, rhs = val
2467
-
2468
- result = s(:PAIR, lhs, rhs).line lhs.line
2469
- }
2470
- | p_kw_label
2471
- {
2472
- lhs, = val
2473
-
2474
- # TODO: error_duplicate_pattern_variable(p, get_id($1), &@1);
2475
-
2476
- # TODO: if ($1 && !is_local_id(get_id($1))) {
2477
- # yyerror1(&@1, "key must be valid as local variables");
2478
- # }
2479
-
2480
- # $$ = list_append(p, NEW_LIST(NEW_LIT(ID2SYM($1), &@$), &@$),
2481
- # assignable(p, $1, 0, &@$));
2482
-
2483
- case lhs.sexp_type
2484
- when :lit then
2485
- assignable [lhs.value, lhs.line]
2486
- else
2487
- # TODO or done?
2488
- debug 10
2489
- end
2490
-
2491
- # TODO PAIR -> LIST ?
2492
- result = s(:PAIR, lhs, nil).line lhs.line
2493
- }
2494
-
2495
- p_kw_label: tLABEL
2496
- {
2497
- result = wrap :lit, val[0]
2498
- }
2499
- | tSTRING_BEG string_contents tLABEL_END
2500
- {
2501
- # you can't actually get here the way I lex labels
2502
- debug 11
2503
- }
2504
-
2505
- p_kwrest: kwrest_mark tIDENTIFIER
2506
- {
2507
- _, (id, line) = val
2508
-
2509
- name = id.to_sym
2510
- self.assignable [name, line]
2511
- result = s(:kwrest, :"**#{name}").line line
2512
- }
2513
- | kwrest_mark
2514
- {
2515
- (_, line), = val
2516
-
2517
- result = s(:kwrest, :"**").line line
2518
- }
2519
-
2520
- p_kwnorest: kwrest_mark kNIL
2521
- {
2522
- (_, line), _ = val
2523
-
2524
- # TODO: or s(:norest)? s(:**nil)?
2525
- result = s(:kwrest, :"**nil").line line
2526
- }
2527
-
2528
- p_any_kwrest: p_kwrest
2529
- | p_kwnorest
2530
-
2531
- p_value: p_primitive
2532
- | p_primitive tDOT2 p_primitive
2533
- {
2534
- lhs, _, rhs = val
2535
-
2536
- lhs = value_expr lhs
2537
- rhs = value_expr rhs
2538
-
2539
- result = s(:dot2, lhs, rhs).line lhs.line
2540
- }
2541
- | p_primitive tDOT3 p_primitive
2542
- {
2543
- lhs, _, rhs = val
2544
-
2545
- lhs = value_expr lhs
2546
- rhs = value_expr rhs
2547
-
2548
- result = s(:dot3, lhs, rhs).line lhs.line
2549
- }
2550
- | p_primitive tDOT2
2551
- {
2552
- v1, _ = val
2553
-
2554
- result = s(:dot2, v1, nil).line v1.line
2555
- }
2556
- | p_primitive tDOT3
2557
- {
2558
- v1, _ = val
2559
-
2560
- result = s(:dot3, v1, nil).line v1.line
2561
- }
2562
- | p_var_ref
2563
- | p_expr_ref
2564
- | p_const
2565
- | tBDOT2 p_primitive
2566
- {
2567
- _, v1 = val
2568
-
2569
- result = s(:dot2, nil, v1).line v1.line
2570
- }
2571
- | tBDOT3 p_primitive
2572
- {
2573
- _, v1 = val
2574
-
2575
- result = s(:dot3, nil, v1).line v1.line
2576
- }
2577
-
2578
- p_primitive: literal
2579
- | strings
2580
- | xstring
2581
- | regexp
2582
- | words
2583
- {
2584
- result = ary_to_pat val[0]
2585
- }
2586
- | qwords
2587
- {
2588
- result = ary_to_pat val[0]
2589
- }
2590
- | symbols
2591
- {
2592
- result = ary_to_pat val[0]
2593
- }
2594
- | qsymbols
2595
- {
2596
- result = ary_to_pat val[0]
2597
- }
2598
- | keyword_variable
2599
- {
2600
- # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
2601
- var, = val
2602
-
2603
- result = var
2604
- }
2605
- | lambda
2606
-
2607
- p_variable: tIDENTIFIER
2608
- {
2609
- # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2610
- # TODO: assignable(p, $1, 0, &@$);
2611
- result = wrap :lasgn, val[0]
2612
- }
2613
-
2614
- p_var_ref: tCARET tIDENTIFIER
2615
- {
2616
- # TODO: check id against env for lvar or dvar
2617
- result = wrap :lvar, val[1]
2618
- }
2619
- | tCARET nonlocal_var
2620
- {
2621
- _, var = val
2622
- result = var
2623
- }
2624
-
2625
- p_expr_ref: tCARET tLPAREN expr_value rparen
2626
- {
2627
- _, _, expr, _ = val
2628
- result = expr # TODO? s(:begin, expr).line expr.line
2629
- }
2630
-
2631
- p_const: tCOLON3 cname
2632
- {
2633
- result = wrap :colon3, val[1]
2634
- }
2635
- | p_const tCOLON2 cname
2636
- {
2637
- lhs, _, (id, _line) = val
2638
-
2639
- l = lhs.line
2640
- result = s(:const, s(:colon2, lhs, id.to_sym).line(l)).line l
2641
- }
2642
- | tCONSTANT
2643
- {
2644
- # TODO $$ = gettable(p, $1, &@$);
2645
- result = wrap :const, val[0]
2646
- }
2647
- ######################################################################
2648
-
2649
- opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
2650
- {
2651
- (_, line), klasses, var, _, body, rest = val
2652
-
2653
- klasses ||= s(:array)
2654
- klasses << new_assign(var, s(:gvar, :"$!").line(var.line)) if var
2655
- klasses.line line
2656
-
2657
- result = new_resbody(klasses, body)
2658
- result << rest if rest # UGH, rewritten above
2659
- }
2660
- |
2661
- {
2662
- result = nil
2663
- }
2664
-
2665
- exc_list: arg_value
2666
- {
2667
- arg, = val
2668
- result = s(:array, arg).line arg.line
2669
- }
2670
- | mrhs
2671
- | none
2672
-
2673
- exc_var: tASSOC lhs
2674
- {
2675
- result = val[1]
2676
- }
2677
- | none
2678
-
2679
- opt_ensure: k_ensure compstmt
2680
- {
2681
- (_, line), body = val
2682
-
2683
- result = body || s(:nil).line(line)
2684
- }
2685
- | none
2686
-
2687
- literal: numeric
2688
- {
2689
- (lit, line), = val
2690
- result = s(:lit, lit).line line
2691
- }
2692
- | symbol
2693
-
2694
- strings: string
2695
- {
2696
- str, = val
2697
- str = s(:dstr, str.value) if str.sexp_type == :evstr
2698
- result = str
2699
- }
2700
-
2701
- string: tCHAR
2702
- {
2703
- debug 12
2704
- }
2705
- | string1
2706
- | string string1
2707
- {
2708
- result = self.literal_concat val[0], val[1]
2709
- }
2710
-
2711
- string1: tSTRING_BEG string_contents tSTRING_END
2712
- {
2713
- (_, line), str, (_, func) = val
2714
-
2715
- str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
2716
-
2717
- result = str.line line
2718
- }
2719
- | tSTRING
2720
- {
2721
- result = new_string val
2722
- }
2723
-
2724
- xstring: tXSTRING_BEG xstring_contents tSTRING_END
2725
- {
2726
- result = new_xstring val
2727
- # TODO: dedent?!?! SERIOUSLY?!?
2728
- }
2729
-
2730
- regexp: tREGEXP_BEG regexp_contents tREGEXP_END
2731
- {
2732
- result = new_regexp val
2733
- }
2734
-
2735
- words: tWORDS_BEG tSPACE tSTRING_END
2736
- {
2737
- (_, line), _, (_, line_max) = val
2738
-
2739
- result = s(:array).line line
2740
- result.line_max = line_max
2741
- }
2742
- | tWORDS_BEG word_list tSTRING_END
2743
- {
2744
- (_, line), list, (_, line_max) = val
2745
-
2746
- result = list.line line
2747
- result.line_max = line_max
2748
- }
2749
-
2750
- word_list: none
2751
- {
2752
- result = new_word_list
2753
- }
2754
- | word_list word tSPACE
2755
- {
2756
- result = val[0].dup << new_word_list_entry(val)
2757
- }
2758
-
2759
- word: string_content
2760
- | word string_content
2761
- {
2762
- result = self.literal_concat val[0], val[1]
2763
- }
2764
-
2765
- symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2766
- {
2767
- (_, line), _, (_, line_max) = val
2768
-
2769
- result = s(:array).line line
2770
- result.line_max = line_max
2771
- }
2772
- | tSYMBOLS_BEG symbol_list tSTRING_END
2773
- {
2774
- (_, line), list, (_, line_max), = val
2775
-
2776
- result = list.line line
2777
- result.line_max = line_max
2778
- }
2779
-
2780
- symbol_list: none
2781
- {
2782
- result = new_symbol_list
2783
- }
2784
- | symbol_list word tSPACE
2785
- {
2786
- list, * = val
2787
- result = list.dup << new_symbol_list_entry(val)
2788
- }
2789
-
2790
- qwords: tQWORDS_BEG tSPACE tSTRING_END
2791
- {
2792
- (_, line), _, (_, line_max) = val
2793
-
2794
- result = s(:array).line line
2795
- result.line_max = line_max
2796
- }
2797
- | tQWORDS_BEG qword_list tSTRING_END
2798
- {
2799
- (_, line), list, (_, line_max) = val
2800
-
2801
- result = list.line line
2802
- result.line_max = line_max
2803
- }
2804
-
2805
- qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2806
- {
2807
- (_, line), _, (_, line_max) = val
2808
-
2809
- result = s(:array).line line
2810
- result.line_max = line_max
2811
- }
2812
- | tQSYMBOLS_BEG qsym_list tSTRING_END
2813
- {
2814
- (_, line), list, (_, line_max) = val
2815
-
2816
- result = list.line line
2817
- result.line_max = line_max
2818
- }
2819
-
2820
- qword_list: none
2821
- {
2822
- result = new_qword_list
2823
- }
2824
- | qword_list tSTRING_CONTENT tSPACE
2825
- {
2826
- result = val[0].dup << new_qword_list_entry(val)
2827
- }
2828
-
2829
- qsym_list: none
2830
- {
2831
- result = new_qsym_list
2832
- }
2833
- | qsym_list tSTRING_CONTENT tSPACE
2834
- {
2835
- result = val[0].dup << new_qsym_list_entry(val)
2836
- }
2837
-
2838
- string_contents: none
2839
- {
2840
- line = prev_value_to_lineno _values.last
2841
- result = s(:str, +"").line line
2842
- }
2843
- | string_contents string_content
2844
- {
2845
- v1, v2 = val
2846
- result = literal_concat v1, v2
2847
- }
2848
-
2849
- xstring_contents: none
2850
- {
2851
- result = nil
2852
- }
2853
- | xstring_contents string_content
2854
- {
2855
- v1, v2 = val
2856
- result = literal_concat v1, v2
2857
- }
2858
-
2859
- regexp_contents: none
2860
- {
2861
- result = nil
2862
- }
2863
- | regexp_contents string_content
2864
- {
2865
- v1, v2 = val
2866
- result = literal_concat v1, v2
2867
- }
2868
-
2869
- string_content: tSTRING_CONTENT
2870
- {
2871
- result = new_string val
2872
- }
2873
- | tSTRING_DVAR
2874
- {
2875
- result = lexer.lex_strterm
2876
-
2877
- lexer.lex_strterm = nil
2878
- lexer.lex_state = EXPR_BEG
2879
- }
2880
- string_dvar
2881
- {
2882
- _, strterm, str = val
2883
- lexer.lex_strterm = strterm
2884
- result = s(:evstr, str).line str.line
2885
- }
2886
- | tSTRING_DBEG
2887
- {
2888
- result = [lexer.lex_strterm,
2889
- lexer.brace_nest,
2890
- lexer.string_nest, # TODO: remove
2891
- lexer.lex_state,
2892
- ]
2893
-
2894
- lexer.cmdarg.push false
2895
- lexer.cond.push false
2896
-
2897
- lexer.lex_strterm = nil
2898
- lexer.brace_nest = 0
2899
- lexer.string_nest = 0
2900
-
2901
- lexer.lex_state = EXPR_BEG
2902
- }
2903
- compstmt
2904
- tSTRING_DEND
2905
- {
2906
- (_, line), memo, stmt, _ = val
2907
-
2908
- lex_strterm, brace_nest, string_nest, oldlex_state = memo
2909
- # TODO: heredoc_indent
2910
-
2911
- lexer.lex_strterm = lex_strterm
2912
- lexer.brace_nest = brace_nest
2913
- lexer.string_nest = string_nest
2914
-
2915
- lexer.cond.pop
2916
- lexer.cmdarg.pop
2917
-
2918
- lexer.lex_state = oldlex_state
2919
-
2920
- case stmt
2921
- when Sexp then
2922
- case stmt.sexp_type
2923
- when :str, :dstr, :evstr then
2924
- result = stmt
2925
- else
2926
- result = s(:evstr, stmt).line line
2927
- end
2928
- when nil then
2929
- result = s(:evstr).line line
2930
- else
2931
- debug 13
2932
- raise "unknown string body: #{stmt.inspect}"
2933
- end
2934
- }
2935
-
2936
- string_dvar: tGVAR
2937
- {
2938
- result = wrap :gvar, val[0]
2939
- }
2940
- | tIVAR
2941
- {
2942
- result = wrap :ivar, val[0]
2943
- }
2944
- | tCVAR
2945
- {
2946
- result = wrap :cvar, val[0]
2947
- }
2948
- | backref
2949
-
2950
- symbol: ssym
2951
- | dsym
2952
-
2953
- ssym: tSYMBEG sym
2954
- {
2955
- lexer.lex_state = EXPR_END
2956
- result = wrap :lit, val[1]
2957
- }
2958
- | tSYMBOL
2959
- {
2960
- lexer.lex_state = EXPR_END
2961
- result = wrap :lit, val[0]
2962
- }
2963
-
2964
- sym: fname | tIVAR | tGVAR | tCVAR
2965
-
2966
- dsym: tSYMBEG string_contents tSTRING_END
2967
- {
2968
- (_, line), result, _ = val
2969
-
2970
- lexer.lex_state = EXPR_END
2971
-
2972
- result ||= s(:str, "").line line
2973
-
2974
- case result.sexp_type
2975
- when :dstr then
2976
- result.sexp_type = :dsym
2977
- when :str then
2978
- result = s(:lit, result.last.to_sym).line result.line
2979
- when :evstr then
2980
- result = s(:dsym, "", result).line result.line
2981
- else
2982
- debug 14
2983
- end
2984
- }
2985
-
2986
- numeric: simple_numeric
2987
- | tUMINUS_NUM simple_numeric =tLOWEST
2988
- {
2989
- _, (num, line) = val
2990
- result = [-num, line]
2991
- }
2992
-
2993
- simple_numeric: tINTEGER
2994
- | tFLOAT
2995
- | tRATIONAL
2996
- | tIMAGINARY
2997
-
2998
- nonlocal_var: tIVAR { result = wrap :ivar, val[0] }
2999
- | tGVAR { result = wrap :gvar, val[0] }
3000
- | tCVAR { result = wrap :cvar, val[0] }
3001
-
3002
- user_variable: tIDENTIFIER
3003
- | tIVAR
3004
- | tGVAR
3005
- | tCONSTANT
3006
- | tCVAR
3007
-
3008
- keyword_variable: kNIL { (_, line), = val; result = s(:nil).line line }
3009
- | kSELF { (_, line), = val; result = s(:self).line line }
3010
- | kTRUE { (_, line), = val; result = s(:true).line line }
3011
- | kFALSE { (_, line), = val; result = s(:false).line line }
3012
- | k__FILE__ { (_, line), = val; result = s(:str, self.file).line line }
3013
- | k__LINE__ { (_, line), = val; result = s(:lit, line).line line }
3014
- | k__ENCODING__
3015
- {
3016
- (_, l), = val
3017
- result =
3018
- if defined? Encoding then
3019
- s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
3020
- else
3021
- s(:str, "Unsupported!").line l
3022
- end
3023
- }
3024
-
3025
- var_ref: user_variable
3026
- {
3027
- raise "NO: #{val.inspect}" if Sexp === val.first
3028
- (var, line), = val
3029
- result = Sexp === var ? var : self.gettable(var)
3030
-
3031
- result.line line
3032
- }
3033
- | keyword_variable
3034
- {
3035
- var = val[0]
3036
- result = Sexp === var ? var : self.gettable(var)
3037
- }
3038
-
3039
- var_lhs: user_variable
3040
- {
3041
- result = self.assignable val[0]
3042
- }
3043
- | keyword_variable
3044
- {
3045
- result = self.assignable val[0]
3046
- debug 15
3047
- }
3048
-
3049
- backref: tNTH_REF
3050
- {
3051
- (ref, line), = val
3052
- result = s(:nth_ref, ref).line line
3053
- }
3054
- | tBACK_REF
3055
- {
3056
- (ref, line), = val
3057
- result = s(:back_ref, ref).line line
3058
- }
3059
-
3060
- superclass: tLT
3061
- {
3062
- lexer.lex_state = EXPR_BEG
3063
- lexer.command_start = true
3064
- }
3065
- expr_value term
3066
- {
3067
- result = val[2]
3068
- }
3069
- | none
3070
- {
3071
- result = nil
3072
- }
3073
-
3074
- f_opt_paren_args: f_paren_args
3075
- | none
3076
- {
3077
- self.in_argdef = false
3078
- result = end_args val
3079
- }
3080
-
3081
- f_paren_args: tLPAREN2 f_args rparen
3082
- {
3083
- self.in_argdef = false
3084
- result = end_args val
3085
- }
3086
-
3087
- f_arglist: f_paren_args
3088
- | {
3089
- result = self.in_kwarg
3090
- self.in_kwarg = true
3091
- self.in_argdef = true
3092
- self.lexer.lex_state |= EXPR_LABEL
3093
- }
3094
- f_args term
3095
- {
3096
- self.in_argdef = false
3097
- result = end_args val
3098
- }
3099
-
3100
- args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
3101
- {
3102
- result = args val
3103
- }
3104
- | f_kwarg opt_f_block_arg
3105
- {
3106
- result = args val
3107
- }
3108
- | f_any_kwrest opt_f_block_arg
3109
- {
3110
- result = args val
3111
- }
3112
- | f_block_arg
3113
- | args_forward
3114
-
3115
- opt_args_tail: tCOMMA args_tail
3116
- {
3117
- result = val[1]
3118
- }
3119
- |
3120
- {
3121
- result = nil
3122
- }
3123
-
3124
- f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
3125
- {
3126
- result = args val
3127
- }
3128
- | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
3129
- {
3130
- result = args val
3131
- }
3132
- | f_arg tCOMMA f_optarg opt_args_tail
3133
- {
3134
- result = args val
3135
- }
3136
- | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
3137
- {
3138
- result = args val
3139
- }
3140
- | f_arg tCOMMA f_rest_arg opt_args_tail
3141
- {
3142
- result = args val
3143
- }
3144
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
3145
- {
3146
- result = args val
3147
- }
3148
- | f_arg opt_args_tail
3149
- {
3150
- result = args val
3151
- }
3152
- | f_optarg tCOMMA f_rest_arg opt_args_tail
3153
- {
3154
- result = args val
3155
- }
3156
- | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
3157
- {
3158
- result = args val
3159
- }
3160
- | f_optarg opt_args_tail
3161
- {
3162
- result = args val
3163
- }
3164
- | f_optarg tCOMMA f_arg opt_args_tail
3165
- {
3166
- result = args val
3167
- }
3168
- | f_rest_arg opt_args_tail
3169
- {
3170
- result = args val
3171
- }
3172
- | f_rest_arg tCOMMA f_arg opt_args_tail
3173
- {
3174
- result = args val
3175
- }
3176
- | args_tail
3177
- {
3178
- result = args val
3179
- }
3180
- |
3181
- {
3182
- result = args val
3183
- }
3184
-
3185
- args_forward: tBDOT3
3186
- {
3187
- (_, line), = val
3188
- result = s(:forward_args).line line
3189
- }
3190
-
3191
- f_bad_arg: tCONSTANT
3192
- {
3193
- yyerror "formal argument cannot be a constant"
3194
- }
3195
- | tIVAR
3196
- {
3197
- yyerror "formal argument cannot be an instance variable"
3198
- }
3199
- | tGVAR
3200
- {
3201
- yyerror "formal argument cannot be a global variable"
3202
- }
3203
- | tCVAR
3204
- {
3205
- yyerror "formal argument cannot be a class variable"
3206
- }
3207
-
3208
- f_norm_arg: f_bad_arg
3209
- | tIDENTIFIER
3210
- {
3211
- (id, line), = val
3212
- identifier = id.to_sym
3213
- self.env[identifier] = :lvar
3214
-
3215
- result = [identifier, line]
3216
- }
3217
-
3218
- f_arg_asgn: f_norm_arg
3219
-
3220
- f_arg_item: f_arg_asgn
3221
- | tLPAREN f_margs rparen
3222
- {
3223
- _, margs, _ = val
3224
-
3225
- result = margs
3226
- }
3227
-
3228
- f_arg: f_arg_item
3229
- {
3230
- result = new_arg val
3231
- }
3232
- | f_arg tCOMMA f_arg_item
3233
- {
3234
- list, _, item = val
3235
-
3236
- if list.sexp_type == :args then
3237
- result = list
3238
- else
3239
- result = s(:args, list).line list.line
3240
- end
3241
-
3242
- if Sexp === item then
3243
- line_max = item.line_max
3244
- else
3245
- item, line_max = item
3246
- end
3247
-
3248
- result << item
3249
- result.line_max = line_max
3250
- }
3251
-
3252
- f_label: tLABEL
3253
- {
3254
- label, = val
3255
- # arg_var(p, formal_argument(p, $1));
3256
- # p->cur_arg = get_id($1);
3257
- # p->max_numparam = ORDINAL_PARAM;
3258
- self.in_argdef = false
3259
- result = label
3260
- }
3261
-
3262
- f_kw: f_label arg_value
3263
- {
3264
- # TODO: new_kw_arg
3265
- (label, line), arg = val
3266
-
3267
- identifier = label.to_sym
3268
- self.env[identifier] = :lvar
3269
- self.in_argdef = true
3270
-
3271
- kwarg = s(:kwarg, identifier, arg).line line
3272
- result = s(:array, kwarg).line line
3273
- }
3274
- | f_label
3275
- {
3276
- (label, line), = val
3277
-
3278
- id = label.to_sym
3279
- self.env[id] = :lvar
3280
- self.in_argdef = true
3281
-
3282
- result = s(:array, s(:kwarg, id).line(line)).line line
3283
- }
3284
-
3285
- f_block_kw: f_label primary_value
3286
- {
3287
- # TODO: new_kw_arg
3288
- (label, line), expr = val
3289
- id = label.to_sym
3290
- self.env[id] = :lvar
3291
- self.in_argdef = true
3292
-
3293
- result = s(:array, s(:kwarg, id, expr).line(line)).line line
3294
- }
3295
- | f_label
3296
- {
3297
- # TODO: new_kw_arg
3298
- (label, line), = val
3299
- id = label.to_sym
3300
- self.env[id] = :lvar
3301
- self.in_argdef = true
3302
-
3303
- result = s(:array, s(:kwarg, id).line(line)).line line
3304
- }
3305
-
3306
- f_block_kwarg: f_block_kw
3307
- | f_block_kwarg tCOMMA f_block_kw
3308
- {
3309
- list, _, item = val
3310
- result = list << item.last
3311
- }
3312
-
3313
- f_kwarg: f_kw
3314
- | f_kwarg tCOMMA f_kw
3315
- {
3316
- result = args val
3317
- }
3318
-
3319
- kwrest_mark: tPOW
3320
- | tDSTAR
3321
-
3322
- f_no_kwarg: kwrest_mark kNIL
3323
- {
3324
- (_, line), _ = val
3325
- result = [:"**nil", line]
3326
- }
3327
-
3328
- f_kwrest: kwrest_mark tIDENTIFIER
3329
- {
3330
- _, (id, line) = val
3331
-
3332
- name = id.to_sym
3333
- self.assignable [name, line]
3334
- result = [:"**#{name}", line]
3335
- }
3336
- | kwrest_mark
3337
- {
3338
- (_, line), = val
3339
- id = :"**"
3340
- self.env[id] = :lvar
3341
- result = [id, line]
3342
- }
3343
-
3344
- f_opt: f_arg_asgn
3345
- f_eq
3346
- arg_value
3347
- {
3348
- lhs, _, rhs = val
3349
- self.in_argdef = true
3350
- result = self.assignable lhs, rhs
3351
- # TODO: detect duplicate names
3352
- # TODO? p->cur_arg = 0;
3353
- }
3354
-
3355
- f_block_opt: f_arg_asgn
3356
- f_eq
3357
- primary_value
3358
- {
3359
- lhs, _, rhs = val
3360
- self.in_argdef = true
3361
- result = self.assignable lhs, rhs
3362
- # TODO? p->cur_arg = 0;
3363
- }
3364
-
3365
- f_block_optarg: f_block_opt
3366
- {
3367
- optblk, = val
3368
- result = s(:block, optblk).line optblk.line
3369
- }
3370
- | f_block_optarg tCOMMA f_block_opt
3371
- {
3372
- optarg, _, optblk = val
3373
- result = optarg
3374
- result << optblk
3375
- }
3376
-
3377
- f_optarg: f_opt
3378
- {
3379
- opt, = val
3380
- result = s(:block, opt).line opt.line
3381
- }
3382
- | f_optarg tCOMMA f_opt
3383
- {
3384
- result = self.block_append val[0], val[2]
3385
- }
3386
-
3387
- restarg_mark: tSTAR2 | tSTAR
3388
-
3389
- f_rest_arg: restarg_mark tIDENTIFIER
3390
- {
3391
- # TODO: differs from parse.y - needs tests
3392
- _, (id, line) = val
3393
- name = id.to_sym
3394
- self.assignable [name, line]
3395
- result = [:"*#{name}", line]
3396
- }
3397
- | restarg_mark
3398
- {
3399
- (_, line), = val
3400
- name = :"*"
3401
- self.env[name] = :lvar
3402
- result = [name, line]
3403
- }
3404
-
3405
- blkarg_mark: tAMPER2 | tAMPER
3406
-
3407
- f_block_arg: blkarg_mark tIDENTIFIER
3408
- {
3409
- _, (id, line) = val
3410
- identifier = id.to_sym
3411
-
3412
- self.env[identifier] = :lvar
3413
- result = ["&#{identifier}".to_sym, line]
3414
- }
3415
- | blkarg_mark
3416
- {
3417
- (_, line), = val
3418
-
3419
- result = [:&, line]
3420
- }
3421
-
3422
- opt_f_block_arg: tCOMMA f_block_arg
3423
- {
3424
- _, arg = val
3425
- result = arg
3426
- }
3427
- |
3428
- {
3429
- result = nil
3430
- }
3431
-
3432
- singleton: var_ref
3433
- | tLPAREN2
3434
- {
3435
- lexer.lex_state = EXPR_BEG
3436
- }
3437
- expr rparen
3438
- {
3439
- result = val[2]
3440
- yyerror "Can't define single method for literals." if
3441
- result.sexp_type == :lit
3442
- }
3443
-
3444
- assoc_list: none
3445
- {
3446
- result = s(:array).line lexer.lineno
3447
- }
3448
- | assocs trailer
3449
-
3450
- assocs: assoc
3451
- | assocs tCOMMA assoc
3452
- {
3453
- list = val[0].dup
3454
- more = val[2].sexp_body
3455
- list.push(*more) unless more.empty?
3456
- result = list
3457
- result.sexp_type = :hash
3458
- }
3459
-
3460
- assoc: arg_value tASSOC arg_value
3461
- {
3462
- v1, _, v2 = val
3463
- result = s(:array, v1, v2).line v1.line
3464
- }
3465
- | tLABEL arg_value
3466
- {
3467
- label, arg = val
3468
-
3469
- lit = wrap :lit, label
3470
- result = s(:array, lit, arg).line lit.line
3471
- }
3472
- | tLABEL
3473
- {
3474
- lit = wrap :lit, val[0]
3475
- arg = nil
3476
-
3477
- result = s(:array, lit, arg).line lit.line
3478
- }
3479
- | tSTRING_BEG string_contents tLABEL_END arg_value
3480
- {
3481
- (_, line), sym, _, value = val
3482
-
3483
- sym.sexp_type = :dsym
3484
-
3485
- result = s(:array, sym, value).line line
3486
- }
3487
- | tDSTAR arg_value
3488
- {
3489
- _, arg = val
3490
- line = arg.line
3491
- result = s(:array, s(:kwsplat, arg).line(line)).line line
3492
- }
3493
-
3494
- operation: tIDENTIFIER | tCONSTANT | tFID
3495
- operation2: tIDENTIFIER | tCONSTANT | tFID | op
3496
- operation3: tIDENTIFIER | tFID | op
3497
- dot_or_colon: tDOT | tCOLON2
3498
- call_op: tDOT
3499
- | tLONELY # TODO: rename tANDDOT?
3500
-
3501
- call_op2: call_op
3502
- | tCOLON2
3503
-
3504
- opt_terms: | terms
3505
- opt_nl: | tNL
3506
- rparen: opt_nl tRPAREN
3507
- {
3508
- _, close = val # TODO: include lineno in close?
3509
- result = [close, lexer.lineno]
3510
- }
3511
- rbracket: opt_nl tRBRACK
3512
- {
3513
- _, close = val
3514
- result = [close, lexer.lineno]
3515
- }
3516
- rbrace: opt_nl tRCURLY
3517
- {
3518
- _, close = val
3519
- result = [close, lexer.lineno]
3520
- }
3521
- trailer: | tNL | tCOMMA
3522
-
3523
- term: tSEMI { yyerrok }
3524
- | tNL
3525
-
3526
- terms: term
3527
- | terms tSEMI { yyerrok }
3528
-
3529
- none: { result = nil; }
3530
- end
3531
-
3532
- ---- inner
3533
-
3534
- require "ruby_lexer"
3535
- require "ruby_parser_extras"
3536
- include RubyLexer::State::Values
3537
-
3538
- # :stopdoc:
3539
-
3540
- # Local Variables: **
3541
- # racc-token-length-max:14 **
3542
- # End: **