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