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/ruby32_parser.y DELETED
@@ -1,3543 +0,0 @@
1
- # -*- racc -*-
2
-
3
- class Ruby32Parser
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
- | tSTAR
1265
- {
1266
- (_, line), = val
1267
- result = s(:array, s(:splat).line(line)).line line
1268
- }
1269
- | args tCOMMA arg_value
1270
- {
1271
- args, _, id = val
1272
- result = self.list_append args, id
1273
- }
1274
- | args tCOMMA tSTAR arg_value
1275
- {
1276
- args, _, (_, line), id = val
1277
- result = self.list_append args, s(:splat, id).line(line)
1278
- }
1279
- | args tCOMMA tSTAR
1280
- {
1281
- args, _, (_, line) = val
1282
- result = self.list_append args, s(:splat).line(line)
1283
- }
1284
-
1285
- mrhs_arg: mrhs
1286
- {
1287
- result = new_masgn_arg val[0]
1288
- }
1289
- | arg_value
1290
- {
1291
- result = new_masgn_arg val[0], :wrap
1292
- }
1293
-
1294
- mrhs: args tCOMMA arg_value
1295
- {
1296
- result = val[0] << val[2]
1297
- }
1298
- | args tCOMMA tSTAR arg_value
1299
- {
1300
- arg, _, _, splat = val
1301
- result = self.arg_concat arg, splat
1302
- }
1303
- | tSTAR arg_value
1304
- {
1305
- _, arg = val
1306
- result = s(:splat, arg).line arg.line
1307
- }
1308
-
1309
- primary: literal
1310
- | strings
1311
- | xstring
1312
- | regexp
1313
- | words
1314
- | qwords
1315
- | symbols
1316
- | qsymbols
1317
- | var_ref
1318
- | backref
1319
- | tFID
1320
- {
1321
- (msg, line), = val
1322
- result = new_call nil, msg.to_sym
1323
- result.line line
1324
- }
1325
- | k_begin
1326
- {
1327
- lexer.cmdarg.push false
1328
- }
1329
- bodystmt k_end
1330
- {
1331
- lexer.cmdarg.pop
1332
- result = new_begin val
1333
- }
1334
- | tLPAREN_ARG
1335
- {
1336
- lexer.lex_state = EXPR_ENDARG
1337
- }
1338
- rparen
1339
- {
1340
- (_, line), _, _ = val
1341
- result = s(:begin).line line
1342
- }
1343
- | tLPAREN_ARG
1344
- stmt
1345
- {
1346
- lexer.lex_state = EXPR_ENDARG
1347
- }
1348
- rparen
1349
- {
1350
- _, stmt, _, _, = val
1351
- # warning "(...) interpreted as grouped expression"
1352
- result = stmt
1353
- }
1354
- | tLPAREN compstmt tRPAREN
1355
- {
1356
- (_, line), stmt, _ = val
1357
- result = stmt || s(:nil).line(line)
1358
- result.paren = true
1359
- }
1360
- | primary_value tCOLON2 tCONSTANT
1361
- {
1362
- expr, _, (id, _line) = val
1363
-
1364
- result = s(:colon2, expr, id.to_sym).line expr.line
1365
- }
1366
- | tCOLON3 tCONSTANT
1367
- {
1368
- result = wrap :colon3, val[1]
1369
- }
1370
- | tLBRACK aref_args rbracket
1371
- {
1372
- (_, line), args, (_, line_max) = val
1373
-
1374
- result = args || s(:array)
1375
- result.sexp_type = :array # aref_args is :args
1376
- result.line line
1377
- result.line_max = line_max
1378
- }
1379
- | tLBRACE
1380
- {
1381
- result = self.lexer.lineno
1382
- }
1383
- assoc_list tRCURLY
1384
- {
1385
- result = new_hash val
1386
- }
1387
- | k_return
1388
- {
1389
- (_, line), = val
1390
- result = s(:return).line line
1391
- }
1392
- | kYIELD tLPAREN2 call_args rparen
1393
- {
1394
- (_, line), _, args, _ = val
1395
-
1396
- result = new_yield(args).line line
1397
- }
1398
- | kYIELD tLPAREN2 rparen
1399
- {
1400
- (_, line), _, _ = val
1401
-
1402
- result = new_yield.line line
1403
- }
1404
- | kYIELD
1405
- {
1406
- (_, line), = val
1407
-
1408
- result = new_yield.line line
1409
- }
1410
- | kDEFINED opt_nl tLPAREN2 expr rparen
1411
- {
1412
- (_, line), _, _, arg, _ = val
1413
-
1414
- result = s(:defined, arg).line line
1415
- }
1416
- | kNOT tLPAREN2 expr rparen
1417
- {
1418
- _, _, lhs, _ = val
1419
- result = new_call lhs, :"!"
1420
- }
1421
- | kNOT tLPAREN2 rparen
1422
- {
1423
- debug 9
1424
- }
1425
- | fcall brace_block
1426
- {
1427
- call, iter = val
1428
-
1429
- iter.insert 1, call
1430
- result = iter
1431
- # FIX: probably not: call.line = iter.line
1432
- }
1433
- | method_call
1434
- | method_call brace_block
1435
- {
1436
- call, iter = val[0], val[1]
1437
- block_dup_check call, iter
1438
- iter.insert 1, call # FIX
1439
- result = iter
1440
- }
1441
- | lambda
1442
- {
1443
- expr, = val
1444
- result = expr
1445
- }
1446
- | k_if expr_value then compstmt if_tail k_end
1447
- {
1448
- _, c, _, t, f, _ = val
1449
- result = new_if c, t, f
1450
- }
1451
- | k_unless expr_value then compstmt opt_else k_end
1452
- {
1453
- _, c, _, t, f, _ = val
1454
- result = new_if c, f, t
1455
- }
1456
- | k_while expr_value_do compstmt k_end
1457
- {
1458
- _, cond, body, _ = val
1459
- result = new_while body, cond, true
1460
- }
1461
- | k_until expr_value_do compstmt k_end
1462
- {
1463
- _, cond, body, _ = val
1464
- result = new_until body, cond, true
1465
- }
1466
- | k_case expr_value opt_terms case_body k_end
1467
- {
1468
- (_, line), expr, _, body, _ = val
1469
- result = new_case expr, body, line
1470
- }
1471
- | k_case opt_terms case_body k_end
1472
- {
1473
- (_, line), _, body, _ = val
1474
- result = new_case nil, body, line
1475
- }
1476
- | k_case expr_value opt_terms p_case_body k_end
1477
- {
1478
- (_, line), expr, _, body, _ = val
1479
-
1480
- result = new_case expr, body, line
1481
- }
1482
- | k_for for_var kIN expr_value_do compstmt k_end
1483
- {
1484
- _, var, _, iter, body, _ = val
1485
- result = new_for iter, var, body
1486
- }
1487
- | k_class
1488
- cpath superclass
1489
- {
1490
- if (self.in_def || self.in_single > 0) then
1491
- yyerror "class definition in method body"
1492
- end
1493
- self.env.extend
1494
- }
1495
- bodystmt k_end
1496
- {
1497
- result = new_class val
1498
- self.env.unextend
1499
- self.lexer.ignore_body_comments
1500
- }
1501
- | k_class tLSHFT
1502
- expr
1503
- {
1504
- result = self.in_def
1505
- self.in_def = false
1506
- }
1507
- term
1508
- {
1509
- result = self.in_single
1510
- self.in_single = 0
1511
- self.env.extend
1512
- }
1513
- bodystmt
1514
- k_end
1515
- {
1516
- result = new_sclass val
1517
- self.env.unextend
1518
- self.lexer.ignore_body_comments
1519
- }
1520
- | k_module
1521
- cpath
1522
- {
1523
- yyerror "module definition in method body" if
1524
- self.in_def or self.in_single > 0
1525
-
1526
- self.env.extend
1527
- }
1528
- bodystmt k_end
1529
- {
1530
- result = new_module val
1531
- self.env.unextend
1532
- self.lexer.ignore_body_comments
1533
- }
1534
- | defn_head f_arglist bodystmt k_end
1535
- {
1536
- # [ [:f, 1, false], s(:args)...]
1537
- # =>
1538
- # [[:k_def, 666], [:f, 1], false, s(:args)...]
1539
- val.insert 1, val.first.pop
1540
- val.insert 0, [:k_def, 666]
1541
-
1542
- result, in_def = new_defn val
1543
-
1544
- lexer.cond.pop # group = local_pop
1545
- lexer.cmdarg.pop
1546
- self.env.unextend
1547
- self.in_def = in_def
1548
-
1549
- self.lexer.ignore_body_comments
1550
- }
1551
- | defs_head f_arglist bodystmt k_end
1552
- {
1553
- # [ [recv, [:name, 1, false]], s(:args...]
1554
- # =>
1555
- # [ recv, [:name, 1, false], s(:args...]
1556
- # =>
1557
- # [ recv, [:name, 1], false, s(:args...]
1558
- # =>
1559
- # [ :k_def, recv, [:name, 1], false, s(:args...]
1560
-
1561
- val.prepend(*val.shift)
1562
- val.insert 2, val[1].pop
1563
- val.insert 0, [:k_def, 666]
1564
-
1565
- result, in_def = new_defs val
1566
-
1567
- lexer.cond.pop # group = local_pop
1568
- lexer.cmdarg.pop
1569
- self.env.unextend
1570
- self.in_def = in_def
1571
-
1572
- self.in_single -= 1
1573
-
1574
- # TODO: restore cur_arg ? what's cur_arg?
1575
-
1576
- self.lexer.ignore_body_comments
1577
- }
1578
- | kBREAK
1579
- {
1580
- (_, line), = val
1581
- result = s(:break).line line
1582
- }
1583
- | kNEXT
1584
- {
1585
- (_, line), = val
1586
- result = s(:next).line line
1587
- }
1588
- | kREDO
1589
- {
1590
- (_, line), = val
1591
- result = s(:redo).line line
1592
- }
1593
- | kRETRY
1594
- {
1595
- (_, line), = val
1596
- result = s(:retry).line line
1597
- }
1598
-
1599
- primary_value: primary
1600
- {
1601
- result = value_expr(val[0])
1602
- }
1603
-
1604
- # These are really stupid
1605
- k_begin: kBEGIN
1606
- k_if: kIF
1607
- k_unless: kUNLESS
1608
- k_while: kWHILE
1609
- k_until: kUNTIL
1610
- k_case: kCASE
1611
- k_for: kFOR
1612
- k_class: kCLASS
1613
- {
1614
- self.comments.push self.lexer.comments
1615
- }
1616
- k_module: kMODULE
1617
- {
1618
- self.comments.push self.lexer.comments
1619
- }
1620
- k_def: kDEF
1621
- {
1622
- self.comments.push self.lexer.comments
1623
- self.in_argdef = true
1624
- }
1625
- k_do: kDO
1626
- k_do_block: kDO_BLOCK
1627
- k_rescue: kRESCUE
1628
- k_ensure: kENSURE
1629
- k_when: kWHEN
1630
- k_else: kELSE
1631
- k_elsif: kELSIF
1632
- k_end: kEND
1633
- k_return: kRETURN
1634
-
1635
- then: term
1636
- | kTHEN
1637
- | term kTHEN
1638
-
1639
- do: term
1640
- | kDO_COND
1641
-
1642
- if_tail: opt_else
1643
- | k_elsif expr_value then compstmt if_tail
1644
- {
1645
- (_, line), c, _, t, rest = val
1646
-
1647
- result = s(:if, c, t, rest).line line
1648
- }
1649
-
1650
- opt_else: none
1651
- | kELSE compstmt
1652
- {
1653
- result = val[1]
1654
- }
1655
-
1656
- for_var: lhs
1657
- | mlhs
1658
- {
1659
- val[0].delete_at 1 if val[0][1].nil? # HACK
1660
- }
1661
-
1662
- f_marg: f_norm_arg
1663
- {
1664
- (sym, line), = val
1665
-
1666
- result = s(:dummy, sym).line line
1667
- }
1668
- | tLPAREN f_margs rparen
1669
- {
1670
- _, args, _ = val
1671
- result = args
1672
- }
1673
-
1674
- f_marg_list: f_marg
1675
- {
1676
- arg, = val
1677
- line = arg.line
1678
-
1679
- arg = arg.last if arg.sexp_type == :dummy
1680
-
1681
- result = s(:array, arg).line line
1682
- }
1683
- | f_marg_list tCOMMA f_marg
1684
- {
1685
- args, _, arg = val
1686
-
1687
- arg = arg.last if arg.sexp_type == :dummy
1688
-
1689
- result = list_append args, arg
1690
- }
1691
-
1692
- f_margs: f_marg_list
1693
- {
1694
- args, = val
1695
-
1696
- result = block_var args
1697
- }
1698
- | f_marg_list tCOMMA f_rest_marg
1699
- {
1700
- args, _, rest = val
1701
-
1702
- result = block_var args, rest
1703
- }
1704
- | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1705
- {
1706
- lhs, _, splat, _, rhs = val
1707
-
1708
- result = block_var lhs, splat, rhs
1709
- }
1710
- | f_rest_marg
1711
- {
1712
- rest, = val
1713
-
1714
- result = block_var rest
1715
- }
1716
- | f_rest_marg tCOMMA f_marg_list
1717
- {
1718
- splat, _, rest = val
1719
-
1720
- result = block_var splat, rest
1721
- }
1722
-
1723
- f_rest_marg: tSTAR f_norm_arg
1724
- {
1725
- _, (id, line) = val
1726
-
1727
- result = args ["*#{id}".to_sym]
1728
- result.line line
1729
- }
1730
- | tSTAR
1731
- {
1732
- (_, line), = val
1733
- result = args([:*]).line line
1734
- }
1735
-
1736
- f_any_kwrest: f_kwrest
1737
- | f_no_kwarg
1738
-
1739
- f_eq: { self.in_argdef = false } tEQL
1740
-
1741
- block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1742
- {
1743
- result = call_args val
1744
- }
1745
- | f_block_kwarg opt_f_block_arg
1746
- {
1747
- result = call_args val
1748
- }
1749
- | f_any_kwrest opt_f_block_arg
1750
- {
1751
- result = call_args val
1752
- }
1753
- | f_block_arg
1754
- {
1755
- (id, line), = val
1756
- result = call_args [id]
1757
- result.line line
1758
- }
1759
-
1760
- opt_block_args_tail: tCOMMA block_args_tail
1761
- {
1762
- result = args val
1763
- }
1764
- | none
1765
-
1766
- excessed_comma: tCOMMA
1767
- {
1768
- result = s(:WTF_COMMA!)
1769
- }
1770
-
1771
- block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1772
- {
1773
- result = args val
1774
- }
1775
- | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1776
- {
1777
- result = args val
1778
- }
1779
- | f_arg tCOMMA f_block_optarg opt_block_args_tail
1780
- {
1781
- result = args val
1782
- }
1783
- | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1784
- {
1785
- result = args val
1786
- }
1787
- | f_arg tCOMMA f_rest_arg opt_block_args_tail
1788
- {
1789
- result = args val
1790
- }
1791
- | f_arg excessed_comma
1792
- {
1793
- arg, _ = val
1794
- result = arg << nil
1795
- }
1796
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1797
- {
1798
- result = args val
1799
- }
1800
- | f_arg opt_block_args_tail
1801
- {
1802
- result = args val
1803
- }
1804
- | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1805
- {
1806
- result = args val
1807
- }
1808
- | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1809
- {
1810
- result = args val
1811
- }
1812
- | f_block_optarg opt_block_args_tail
1813
- {
1814
- result = args val
1815
- }
1816
- | f_block_optarg tCOMMA f_arg opt_block_args_tail
1817
- {
1818
- result = args val
1819
- }
1820
- | f_rest_arg opt_block_args_tail
1821
- {
1822
- result = args val
1823
- }
1824
- | f_rest_arg tCOMMA f_arg opt_block_args_tail
1825
- {
1826
- result = args val
1827
- }
1828
- | block_args_tail
1829
- {
1830
- result = args val
1831
- }
1832
-
1833
- opt_block_param: none { result = 0 }
1834
- | block_param_def
1835
- {
1836
- self.lexer.command_start = true
1837
- }
1838
-
1839
- block_param_def: tPIPE opt_bv_decl tPIPE
1840
- {
1841
- # TODO: current_arg = 0
1842
- result = args val
1843
- self.in_argdef = false
1844
- }
1845
- | tOROP
1846
- {
1847
- (_, line), = val
1848
-
1849
- result = s(:args).line line
1850
- }
1851
- | tPIPE block_param opt_bv_decl tPIPE
1852
- {
1853
- # TODO: current_arg = 0
1854
- result = args val
1855
- self.in_argdef = false
1856
- }
1857
-
1858
- opt_bv_decl: opt_nl
1859
- | opt_nl tSEMI bv_decls opt_nl
1860
- {
1861
- result = args val
1862
- }
1863
-
1864
- bv_decls: bvar
1865
- {
1866
- result = args val
1867
- }
1868
- | bv_decls tCOMMA bvar
1869
- {
1870
- result = args val
1871
- }
1872
-
1873
- bvar: tIDENTIFIER
1874
- {
1875
- result = wrap :shadow, val[0]
1876
- }
1877
- | f_bad_arg
1878
-
1879
- lambda: tLAMBDA
1880
- {
1881
- self.env.extend :dynamic
1882
- result = lexer.lpar_beg
1883
- lexer.paren_nest += 1
1884
- lexer.lpar_beg = lexer.paren_nest
1885
- }
1886
- f_larglist
1887
- {
1888
- lexer.cmdarg.push false
1889
- }
1890
- lambda_body
1891
- {
1892
- (_, line), lpar, args, _cmdarg, body = val
1893
- lexer.lpar_beg = lpar
1894
-
1895
- lexer.cmdarg.pop
1896
-
1897
- call = s(:lambda).line line
1898
- result = new_iter call, args, body
1899
- result.line line
1900
- self.env.unextend # TODO: dynapush & dynapop
1901
- }
1902
-
1903
- f_larglist: tLPAREN2 f_args opt_bv_decl rparen
1904
- {
1905
- self.in_argdef = false
1906
- result = args val
1907
- }
1908
- | f_args
1909
- {
1910
- self.in_argdef = false
1911
- result = val[0]
1912
- result = 0 if result == s(:args)
1913
- }
1914
-
1915
- lambda_body: tLAMBEG compstmt tRCURLY
1916
- {
1917
- result = val[1]
1918
- }
1919
- | kDO_LAMBDA bodystmt kEND
1920
- {
1921
- result = val[1]
1922
- }
1923
-
1924
- do_block: k_do_block do_body kEND
1925
- {
1926
- (_, line), iter, _ = val
1927
- result = iter.line line
1928
- }
1929
-
1930
- block_call: command do_block
1931
- {
1932
- # TODO:
1933
- ## if (nd_type($1) == NODE_YIELD) {
1934
- ## compile_error(PARSER_ARG "block given to yield");
1935
-
1936
- cmd, blk = val
1937
-
1938
- syntax_error "Both block arg and actual block given." if
1939
- cmd.block_pass?
1940
-
1941
- if inverted? val then
1942
- val = invert_block_call val
1943
- cmd, blk = val
1944
- end
1945
-
1946
- result = blk
1947
- result.insert 1, cmd
1948
- }
1949
- | block_call call_op2 operation2 opt_paren_args
1950
- {
1951
- lhs, _, (id, _line), args = val
1952
-
1953
- result = new_call lhs, id.to_sym, args
1954
- }
1955
- | block_call call_op2 operation2 opt_paren_args brace_block
1956
- {
1957
- iter1, _, (name, _line), args, iter2 = val
1958
-
1959
- call = new_call iter1, name.to_sym, args
1960
- iter2.insert 1, call
1961
-
1962
- result = iter2
1963
- }
1964
- | block_call call_op2 operation2 command_args do_block
1965
- {
1966
- iter1, _, (name, _line), args, iter2 = val
1967
-
1968
- call = new_call iter1, name.to_sym, args
1969
- iter2.insert 1, call
1970
-
1971
- result = iter2
1972
- }
1973
-
1974
- method_call: fcall paren_args
1975
- {
1976
- call, args = val
1977
-
1978
- result = call
1979
-
1980
- if args then
1981
- call.concat args.sexp_body
1982
- result.line_max = args.line_max
1983
- end
1984
- }
1985
- | primary_value call_op operation2 opt_paren_args
1986
- {
1987
- recv, call_op, (op, op_line), args = val
1988
-
1989
- result = new_call recv, op.to_sym, args, call_op
1990
- result.line_max = op_line unless args
1991
- }
1992
- | primary_value tCOLON2 operation2 paren_args
1993
- {
1994
- recv, _, (op, _line), args = val
1995
-
1996
- result = new_call recv, op.to_sym, args
1997
- }
1998
- | primary_value tCOLON2 operation3
1999
- {
2000
- lhs, _, (id, _line) = val
2001
-
2002
- result = new_call lhs, id.to_sym
2003
- }
2004
- | primary_value call_op paren_args
2005
- {
2006
- result = new_call val[0], :call, val[2], val[1]
2007
- }
2008
- | primary_value tCOLON2 paren_args
2009
- {
2010
- result = new_call val[0], :call, val[2]
2011
- }
2012
- | kSUPER paren_args
2013
- {
2014
- result = new_super val[1]
2015
- }
2016
- | kSUPER
2017
- {
2018
- (_, line), = val
2019
- result = s(:zsuper).line line
2020
- }
2021
- | primary_value tLBRACK2 opt_call_args rbracket
2022
- {
2023
- result = new_aref val
2024
- }
2025
-
2026
- brace_block: tLCURLY
2027
- {
2028
- self.env.extend :dynamic
2029
- }
2030
- brace_body
2031
- tRCURLY
2032
- {
2033
- (_, line), _, body, _ = val
2034
-
2035
- result = body
2036
- result.line line
2037
-
2038
- self.env.unextend
2039
- }
2040
- | k_do
2041
- {
2042
- self.env.extend :dynamic
2043
- }
2044
- do_body
2045
- kEND
2046
- {
2047
- (_, line), _, body, _ = val
2048
-
2049
- result = body
2050
- result.line line
2051
-
2052
- self.env.unextend
2053
- }
2054
-
2055
- brace_body: { self.env.extend :dynamic; result = self.lexer.lineno }
2056
- { result = lexer.cmdarg.store(false) }
2057
- opt_block_param compstmt
2058
- {
2059
- line, cmdarg, param, cmpstmt = val
2060
-
2061
- result = new_brace_body param, cmpstmt, line
2062
- self.env.unextend
2063
- lexer.cmdarg.restore cmdarg
2064
- lexer.cmdarg.pop # because of: cmdarg_stack >> 1 ?
2065
- }
2066
-
2067
- do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
2068
- { lexer.cmdarg.push false }
2069
- opt_block_param
2070
- bodystmt
2071
- {
2072
- line, _cmdarg, param, cmpstmt = val
2073
-
2074
- result = new_do_body param, cmpstmt, line
2075
- lexer.cmdarg.pop
2076
- self.env.unextend
2077
- }
2078
-
2079
- case_args: arg_value
2080
- {
2081
- arg, = val
2082
-
2083
- result = s(:array, arg).line arg.line
2084
- }
2085
- | tSTAR arg_value
2086
- {
2087
- _, arg = val
2088
-
2089
- result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
2090
- }
2091
- | case_args tCOMMA arg_value
2092
- {
2093
- args, _, id = val
2094
-
2095
- result = self.list_append args, id
2096
- }
2097
- | case_args tCOMMA tSTAR arg_value
2098
- {
2099
- args, _, _, id = val
2100
-
2101
- result = self.list_append args, s(:splat, id).line(id.line)
2102
- }
2103
-
2104
- case_body: k_when
2105
- case_args then compstmt cases
2106
- {
2107
- (_, line), case_args, _then, body, cases = val
2108
-
2109
- result = new_when case_args, body
2110
- result.line line
2111
- result << cases if cases
2112
- }
2113
-
2114
- cases: opt_else | case_body
2115
- ######################################################################
2116
-
2117
- p_case_body: kIN
2118
- {
2119
- self.lexer.lex_state = EXPR_BEG|EXPR_LABEL
2120
- self.lexer.command_start = false
2121
- result = self.in_kwarg
2122
- self.in_kwarg = true
2123
- push_pvtbl
2124
- push_pktbl
2125
- }
2126
- p_top_expr then
2127
- {
2128
- pop_pktbl
2129
- pop_pvtbl
2130
- old_kwargs = _values[-3]
2131
- self.in_kwarg = old_kwargs
2132
- }
2133
- compstmt
2134
- p_cases
2135
- {
2136
- (_, line), _, pat, _, _, body, cases = val
2137
-
2138
- result = new_in pat, body, cases, line
2139
- }
2140
-
2141
- p_cases: opt_else
2142
- | p_case_body
2143
-
2144
- p_top_expr: p_top_expr_body
2145
- | p_top_expr_body kIF_MOD expr_value
2146
- {
2147
- body, _, cond = val
2148
- body = remove_begin body
2149
-
2150
- result = s(:if, cond, body, nil).line body.line
2151
- }
2152
- | p_top_expr_body kUNLESS_MOD expr_value
2153
- {
2154
- body, _, cond = val
2155
- body = remove_begin body
2156
-
2157
- result = s(:if, cond, nil, body).line body.line
2158
- }
2159
-
2160
- p_top_expr_body: p_expr
2161
- | p_expr tCOMMA
2162
- {
2163
- expr, _ = val
2164
-
2165
- tail = new_array_pattern_tail nil, true, nil, nil
2166
- result = new_array_pattern nil, expr, tail, expr.line
2167
- }
2168
- | p_expr tCOMMA p_args
2169
- {
2170
- expr, _, args = val
2171
-
2172
- result = new_array_pattern nil, expr, args, expr.line
2173
- }
2174
- | p_find
2175
- {
2176
- find, = val
2177
-
2178
- result = new_find_pattern nil, find
2179
- }
2180
- | p_args_tail
2181
- {
2182
- args, = val
2183
- result = new_array_pattern nil, nil, args, args.line
2184
- }
2185
- | p_kwargs
2186
- {
2187
- kwargs, = val
2188
- result = new_hash_pattern nil, kwargs, kwargs.line
2189
- }
2190
-
2191
- p_expr: p_as
2192
-
2193
- p_as: p_expr tASSOC p_variable
2194
- {
2195
- # NODE *n = NEW_LIST($1, &@$);
2196
- # n = list_append(p, n, $3);
2197
- # $$ = new_hash(p, n, &@$);
2198
-
2199
- expr, _, var = val
2200
-
2201
- id = var.last
2202
-
2203
- self.env[id] = :lvar # HACK: need to extend env
2204
- lhs = s(:lasgn, id).line var.line
2205
-
2206
- result = new_assign lhs, expr
2207
- }
2208
- | p_alt
2209
-
2210
- p_alt: p_alt tPIPE p_expr_basic
2211
- {
2212
- lhs, _, rhs = val
2213
-
2214
- result = s(:or, lhs, rhs).line lhs.line
2215
- }
2216
- | p_expr_basic
2217
-
2218
- p_lparen: tLPAREN2 { push_pktbl }
2219
- p_lbracket: tLBRACK2 { push_pktbl }
2220
-
2221
- p_expr_basic: p_value
2222
- | p_variable
2223
- | p_const p_lparen p_args tRPAREN
2224
- {
2225
- lhs, _, args, _ = val
2226
-
2227
- pop_pktbl
2228
- result = new_array_pattern(lhs, nil, args, lhs.line)
2229
- }
2230
- | p_const p_lparen p_find tRPAREN
2231
- {
2232
- const, _, find, _ = val
2233
-
2234
- pop_pktbl
2235
- result = new_find_pattern(const, find).line const.line
2236
- }
2237
- | p_const p_lparen p_kwargs tRPAREN
2238
- {
2239
- lhs, _, kwargs, _ = val
2240
-
2241
- pop_pktbl
2242
- result = new_hash_pattern(lhs, kwargs, lhs.line)
2243
- }
2244
- | p_const tLPAREN2 tRPAREN
2245
- {
2246
- const, _, _ = val
2247
-
2248
- tail = new_array_pattern_tail nil, nil, nil, nil
2249
- result = new_array_pattern const, nil, tail, const.line
2250
- }
2251
- | p_const p_lbracket p_args rbracket
2252
- {
2253
- const, _, pre_arg, _ = val
2254
-
2255
- pop_pktbl
2256
- result = new_array_pattern const, nil, pre_arg, const.line
2257
- }
2258
- | p_const p_lbracket p_find rbracket
2259
- {
2260
- const, _, find, _ = val
2261
-
2262
- pop_pktbl
2263
- result = new_find_pattern(const, find).line const.line
2264
- }
2265
- | p_const p_lbracket p_kwargs rbracket
2266
- {
2267
- const, _, kwargs, _ = val
2268
-
2269
- result = new_hash_pattern const, kwargs, const.line
2270
- }
2271
- | p_const tLBRACK2 rbracket
2272
- {
2273
- const, _, _ = val
2274
-
2275
- tail = new_array_pattern_tail nil, nil, nil, nil
2276
- result = new_array_pattern const, nil, tail, const.line
2277
- }
2278
- | tLBRACK p_args rbracket
2279
- {
2280
- _, pat, _ = val
2281
-
2282
- result = new_array_pattern nil, nil, pat, pat.line
2283
- }
2284
- | tLBRACK p_find rbracket
2285
- {
2286
- _, find, _ = val
2287
-
2288
- result = new_find_pattern nil, find
2289
- }
2290
- | tLBRACK rbracket
2291
- {
2292
- (_, line), _ = val
2293
-
2294
- result = s(:array_pat).line line
2295
- }
2296
- | tLBRACE
2297
- {
2298
- push_pktbl
2299
- result = self.in_kwarg
2300
- self.in_kwarg = false
2301
- }
2302
- p_kwargs rbrace
2303
- {
2304
- _, in_kwarg, kwargs, _ = val
2305
-
2306
- pop_pktbl
2307
- self.in_kwarg = in_kwarg
2308
-
2309
- result = new_hash_pattern(nil, kwargs, kwargs.line)
2310
- }
2311
- | tLBRACE rbrace
2312
- {
2313
- (_, line), _ = val
2314
-
2315
- tail = new_hash_pattern_tail nil, nil, line
2316
- result = new_hash_pattern nil, tail, line
2317
- }
2318
- | tLPAREN { push_pktbl } p_expr tRPAREN
2319
- {
2320
- _, _, expr, _ = val
2321
-
2322
- pop_pktbl
2323
- result = expr
2324
- }
2325
-
2326
- p_args: p_expr
2327
- {
2328
- expr, = val
2329
-
2330
- ary = s(:array_TAIL, expr).line expr.line
2331
- result = new_array_pattern_tail(ary, nil, nil, nil).line expr.line
2332
- }
2333
- | p_args_head
2334
- {
2335
- head, = val
2336
-
2337
- result = new_array_pattern_tail head, true, nil, nil
2338
- }
2339
- | p_args_head p_arg
2340
- {
2341
- head, tail = val
2342
-
2343
- both = array_pat_concat head, tail
2344
-
2345
- result = new_array_pattern_tail both, nil, nil, nil
2346
- result.line head.line
2347
- }
2348
- | p_args_head p_rest
2349
- {
2350
- head, (rest, _) = val
2351
-
2352
- result = new_array_pattern_tail(head, true, rest, nil).line head.line
2353
- }
2354
- | p_args_head p_rest tCOMMA p_args_post
2355
- {
2356
- head, (rest, _), _, post = val
2357
-
2358
- result = new_array_pattern_tail(head, true, rest, post).line head.line
2359
- }
2360
- | p_args_tail
2361
-
2362
- p_args_head: p_arg tCOMMA
2363
- {
2364
- arg, _ = val
2365
- result = arg
2366
- }
2367
- | p_args_head p_arg tCOMMA
2368
- {
2369
- head, tail, _ = val
2370
-
2371
- result = s(:PATTERN, *head.sexp_body, *tail.sexp_body)
2372
- result.line head.line
2373
- }
2374
-
2375
- p_args_tail: p_rest
2376
- {
2377
- (id, line), = val
2378
-
2379
- result = new_array_pattern_tail nil, true, id, nil
2380
- result.line line
2381
- }
2382
- | p_rest tCOMMA p_args_post
2383
- {
2384
- (id, line), _, rhs = val
2385
-
2386
- result = new_array_pattern_tail nil, true, id, rhs
2387
- result.line line
2388
- }
2389
-
2390
- p_find: p_rest tCOMMA p_args_post tCOMMA p_rest
2391
- {
2392
- lhs, _, mid, _, rhs = val
2393
-
2394
- result = new_find_pattern_tail lhs, mid, rhs
2395
- }
2396
-
2397
- p_rest: tSTAR tIDENTIFIER
2398
- {
2399
- _, (id, line) = val
2400
-
2401
- result = [id.to_sym, line]
2402
- }
2403
- | tSTAR
2404
- {
2405
- (_id, line), = val
2406
-
2407
- result = [nil, line]
2408
- }
2409
-
2410
- p_args_post: p_arg
2411
- | p_args_post tCOMMA p_arg
2412
- {
2413
- lhs, _, rhs = val
2414
-
2415
- result = array_pat_concat lhs, rhs
2416
- }
2417
-
2418
- p_arg: p_expr
2419
- {
2420
- expr, = val
2421
- expr = s(:array_TAIL, expr).line expr.line unless
2422
- expr.sexp_type == :array_TAIL
2423
- result = expr
2424
- }
2425
-
2426
- p_kwargs: p_kwarg tCOMMA p_any_kwrest
2427
- {
2428
- kw_arg, _, rest = val
2429
- # TODO? new_unique_key_hash(p, $1, &@$)
2430
- result = new_hash_pattern_tail kw_arg, rest, kw_arg.line
2431
- }
2432
- | p_kwarg
2433
- {
2434
- kwarg, = val
2435
- # TODO? new_unique_key_hash(p, $1, &@$)
2436
- result = new_hash_pattern_tail kwarg, nil, kwarg.line
2437
- }
2438
- | p_kwarg tCOMMA
2439
- {
2440
- kwarg, _ = val
2441
- # TODO? new_unique_key_hash(p, $1, &@$)
2442
- result = new_hash_pattern_tail kwarg, nil, kwarg.line
2443
- }
2444
- | p_any_kwrest
2445
- {
2446
- rest, = val
2447
-
2448
- result = new_hash_pattern_tail nil, rest, rest.line
2449
- }
2450
-
2451
- p_kwarg: p_kw # TODO? rb_ary_new_from_args(1, $1)
2452
- | p_kwarg tCOMMA p_kw
2453
- {
2454
- kwarg, _, kw = val
2455
- kwarg.concat kw.sexp_body
2456
- result = kwarg
2457
- }
2458
-
2459
- p_kw: p_kw_label p_expr
2460
- {
2461
- # TODO: error_duplicate_pattern_key(p, get_id($1), &@1);
2462
- lhs, rhs = val
2463
-
2464
- result = s(:PAIR, lhs, rhs).line lhs.line
2465
- }
2466
- | p_kw_label
2467
- {
2468
- lhs, = val
2469
-
2470
- # TODO: error_duplicate_pattern_variable(p, get_id($1), &@1);
2471
-
2472
- # TODO: if ($1 && !is_local_id(get_id($1))) {
2473
- # yyerror1(&@1, "key must be valid as local variables");
2474
- # }
2475
-
2476
- # $$ = list_append(p, NEW_LIST(NEW_LIT(ID2SYM($1), &@$), &@$),
2477
- # assignable(p, $1, 0, &@$));
2478
-
2479
- case lhs.sexp_type
2480
- when :lit then
2481
- assignable [lhs.value, lhs.line]
2482
- else
2483
- # TODO or done?
2484
- debug 10
2485
- end
2486
-
2487
- # TODO PAIR -> LIST ?
2488
- result = s(:PAIR, lhs, nil).line lhs.line
2489
- }
2490
-
2491
- p_kw_label: tLABEL
2492
- {
2493
- result = wrap :lit, val[0]
2494
- }
2495
- | tSTRING_BEG string_contents tLABEL_END
2496
- {
2497
- # you can't actually get here the way I lex labels
2498
- debug 11
2499
- }
2500
-
2501
- p_kwrest: kwrest_mark tIDENTIFIER
2502
- {
2503
- _, (id, line) = val
2504
-
2505
- name = id.to_sym
2506
- self.assignable [name, line]
2507
- result = s(:kwrest, :"**#{name}").line line
2508
- }
2509
- | kwrest_mark
2510
- {
2511
- (_, line), = val
2512
-
2513
- result = s(:kwrest, :"**").line line
2514
- }
2515
-
2516
- p_kwnorest: kwrest_mark kNIL
2517
- {
2518
- (_, line), _ = val
2519
-
2520
- # TODO: or s(:norest)? s(:**nil)?
2521
- result = s(:kwrest, :"**nil").line line
2522
- }
2523
-
2524
- p_any_kwrest: p_kwrest
2525
- | p_kwnorest
2526
-
2527
- p_value: p_primitive
2528
- | p_primitive tDOT2 p_primitive
2529
- {
2530
- lhs, _, rhs = val
2531
-
2532
- lhs = value_expr lhs
2533
- rhs = value_expr rhs
2534
-
2535
- result = s(:dot2, lhs, rhs).line lhs.line
2536
- }
2537
- | p_primitive tDOT3 p_primitive
2538
- {
2539
- lhs, _, rhs = val
2540
-
2541
- lhs = value_expr lhs
2542
- rhs = value_expr rhs
2543
-
2544
- result = s(:dot3, lhs, rhs).line lhs.line
2545
- }
2546
- | p_primitive tDOT2
2547
- {
2548
- v1, _ = val
2549
-
2550
- result = s(:dot2, v1, nil).line v1.line
2551
- }
2552
- | p_primitive tDOT3
2553
- {
2554
- v1, _ = val
2555
-
2556
- result = s(:dot3, v1, nil).line v1.line
2557
- }
2558
- | p_var_ref
2559
- | p_expr_ref
2560
- | p_const
2561
- | tBDOT2 p_primitive
2562
- {
2563
- _, v1 = val
2564
-
2565
- result = s(:dot2, nil, v1).line v1.line
2566
- }
2567
- | tBDOT3 p_primitive
2568
- {
2569
- _, v1 = val
2570
-
2571
- result = s(:dot3, nil, v1).line v1.line
2572
- }
2573
-
2574
- p_primitive: literal
2575
- | strings
2576
- | xstring
2577
- | regexp
2578
- | words
2579
- {
2580
- result = ary_to_pat val[0]
2581
- }
2582
- | qwords
2583
- {
2584
- result = ary_to_pat val[0]
2585
- }
2586
- | symbols
2587
- {
2588
- result = ary_to_pat val[0]
2589
- }
2590
- | qsymbols
2591
- {
2592
- result = ary_to_pat val[0]
2593
- }
2594
- | keyword_variable
2595
- {
2596
- # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
2597
- var, = val
2598
-
2599
- result = var
2600
- }
2601
- | lambda
2602
-
2603
- p_variable: tIDENTIFIER
2604
- {
2605
- # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2606
- # TODO: assignable(p, $1, 0, &@$);
2607
- result = wrap :lasgn, val[0]
2608
- }
2609
-
2610
- p_var_ref: tCARET tIDENTIFIER
2611
- {
2612
- # TODO: check id against env for lvar or dvar
2613
- result = wrap :lvar, val[1]
2614
- }
2615
- | tCARET nonlocal_var
2616
- {
2617
- _, var = val
2618
- result = var
2619
- }
2620
-
2621
- p_expr_ref: tCARET tLPAREN expr_value rparen
2622
- {
2623
- _, _, expr, _ = val
2624
- result = expr # TODO? s(:begin, expr).line expr.line
2625
- }
2626
-
2627
- p_const: tCOLON3 cname
2628
- {
2629
- result = wrap :colon3, val[1]
2630
- }
2631
- | p_const tCOLON2 cname
2632
- {
2633
- lhs, _, (id, _line) = val
2634
-
2635
- l = lhs.line
2636
- result = s(:const, s(:colon2, lhs, id.to_sym).line(l)).line l
2637
- }
2638
- | tCONSTANT
2639
- {
2640
- # TODO $$ = gettable(p, $1, &@$);
2641
- result = wrap :const, val[0]
2642
- }
2643
- ######################################################################
2644
-
2645
- opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
2646
- {
2647
- (_, line), klasses, var, _, body, rest = val
2648
-
2649
- klasses ||= s(:array)
2650
- klasses << new_assign(var, s(:gvar, :"$!").line(var.line)) if var
2651
- klasses.line line
2652
-
2653
- result = new_resbody(klasses, body)
2654
- result << rest if rest # UGH, rewritten above
2655
- }
2656
- |
2657
- {
2658
- result = nil
2659
- }
2660
-
2661
- exc_list: arg_value
2662
- {
2663
- arg, = val
2664
- result = s(:array, arg).line arg.line
2665
- }
2666
- | mrhs
2667
- | none
2668
-
2669
- exc_var: tASSOC lhs
2670
- {
2671
- result = val[1]
2672
- }
2673
- | none
2674
-
2675
- opt_ensure: k_ensure compstmt
2676
- {
2677
- (_, line), body = val
2678
-
2679
- result = body || s(:nil).line(line)
2680
- }
2681
- | none
2682
-
2683
- literal: numeric
2684
- {
2685
- (lit, line), = val
2686
- result = s(:lit, lit).line line
2687
- }
2688
- | symbol
2689
-
2690
- strings: string
2691
- {
2692
- str, = val
2693
- str = s(:dstr, str.value) if str.sexp_type == :evstr
2694
- result = str
2695
- }
2696
-
2697
- string: tCHAR
2698
- {
2699
- debug 12
2700
- }
2701
- | string1
2702
- | string string1
2703
- {
2704
- result = self.literal_concat val[0], val[1]
2705
- }
2706
-
2707
- string1: tSTRING_BEG string_contents tSTRING_END
2708
- {
2709
- (_, line), str, (_, func) = val
2710
-
2711
- str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
2712
-
2713
- result = str.line line
2714
- }
2715
- | tSTRING
2716
- {
2717
- result = new_string val
2718
- }
2719
-
2720
- xstring: tXSTRING_BEG xstring_contents tSTRING_END
2721
- {
2722
- result = new_xstring val
2723
- # TODO: dedent?!?! SERIOUSLY?!?
2724
- }
2725
-
2726
- regexp: tREGEXP_BEG regexp_contents tREGEXP_END
2727
- {
2728
- result = new_regexp val
2729
- }
2730
-
2731
- words: tWORDS_BEG tSPACE tSTRING_END
2732
- {
2733
- (_, line), _, (_, line_max) = val
2734
-
2735
- result = s(:array).line line
2736
- result.line_max = line_max
2737
- }
2738
- | tWORDS_BEG word_list tSTRING_END
2739
- {
2740
- (_, line), list, (_, line_max) = val
2741
-
2742
- result = list.line line
2743
- result.line_max = line_max
2744
- }
2745
-
2746
- word_list: none
2747
- {
2748
- result = new_word_list
2749
- }
2750
- | word_list word tSPACE
2751
- {
2752
- result = val[0].dup << new_word_list_entry(val)
2753
- }
2754
-
2755
- word: string_content
2756
- | word string_content
2757
- {
2758
- result = self.literal_concat val[0], val[1]
2759
- }
2760
-
2761
- symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2762
- {
2763
- (_, line), _, (_, line_max) = val
2764
-
2765
- result = s(:array).line line
2766
- result.line_max = line_max
2767
- }
2768
- | tSYMBOLS_BEG symbol_list tSTRING_END
2769
- {
2770
- (_, line), list, (_, line_max), = val
2771
-
2772
- result = list.line line
2773
- result.line_max = line_max
2774
- }
2775
-
2776
- symbol_list: none
2777
- {
2778
- result = new_symbol_list
2779
- }
2780
- | symbol_list word tSPACE
2781
- {
2782
- list, * = val
2783
- result = list.dup << new_symbol_list_entry(val)
2784
- }
2785
-
2786
- qwords: tQWORDS_BEG tSPACE tSTRING_END
2787
- {
2788
- (_, line), _, (_, line_max) = val
2789
-
2790
- result = s(:array).line line
2791
- result.line_max = line_max
2792
- }
2793
- | tQWORDS_BEG qword_list tSTRING_END
2794
- {
2795
- (_, line), list, (_, line_max) = val
2796
-
2797
- result = list.line line
2798
- result.line_max = line_max
2799
- }
2800
-
2801
- qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2802
- {
2803
- (_, line), _, (_, line_max) = val
2804
-
2805
- result = s(:array).line line
2806
- result.line_max = line_max
2807
- }
2808
- | tQSYMBOLS_BEG qsym_list tSTRING_END
2809
- {
2810
- (_, line), list, (_, line_max) = val
2811
-
2812
- result = list.line line
2813
- result.line_max = line_max
2814
- }
2815
-
2816
- qword_list: none
2817
- {
2818
- result = new_qword_list
2819
- }
2820
- | qword_list tSTRING_CONTENT tSPACE
2821
- {
2822
- result = val[0].dup << new_qword_list_entry(val)
2823
- }
2824
-
2825
- qsym_list: none
2826
- {
2827
- result = new_qsym_list
2828
- }
2829
- | qsym_list tSTRING_CONTENT tSPACE
2830
- {
2831
- result = val[0].dup << new_qsym_list_entry(val)
2832
- }
2833
-
2834
- string_contents: none
2835
- {
2836
- line = prev_value_to_lineno _values.last
2837
- result = s(:str, +"").line line
2838
- }
2839
- | string_contents string_content
2840
- {
2841
- v1, v2 = val
2842
- result = literal_concat v1, v2
2843
- }
2844
-
2845
- xstring_contents: none
2846
- {
2847
- result = nil
2848
- }
2849
- | xstring_contents string_content
2850
- {
2851
- v1, v2 = val
2852
- result = literal_concat v1, v2
2853
- }
2854
-
2855
- regexp_contents: none
2856
- {
2857
- result = nil
2858
- }
2859
- | regexp_contents string_content
2860
- {
2861
- v1, v2 = val
2862
- result = literal_concat v1, v2
2863
- }
2864
-
2865
- string_content: tSTRING_CONTENT
2866
- {
2867
- result = new_string val
2868
- }
2869
- | tSTRING_DVAR
2870
- {
2871
- result = lexer.lex_strterm
2872
-
2873
- lexer.lex_strterm = nil
2874
- lexer.lex_state = EXPR_BEG
2875
- }
2876
- string_dvar
2877
- {
2878
- _, strterm, str = val
2879
- lexer.lex_strterm = strterm
2880
- result = s(:evstr, str).line str.line
2881
- }
2882
- | tSTRING_DBEG
2883
- {
2884
- result = [lexer.lex_strterm,
2885
- lexer.brace_nest,
2886
- lexer.string_nest, # TODO: remove
2887
- lexer.lex_state,
2888
- ]
2889
-
2890
- lexer.cmdarg.push false
2891
- lexer.cond.push false
2892
-
2893
- lexer.lex_strterm = nil
2894
- lexer.brace_nest = 0
2895
- lexer.string_nest = 0
2896
-
2897
- lexer.lex_state = EXPR_BEG
2898
- }
2899
- compstmt
2900
- tSTRING_DEND
2901
- {
2902
- (_, line), memo, stmt, _ = val
2903
-
2904
- lex_strterm, brace_nest, string_nest, oldlex_state = memo
2905
- # TODO: heredoc_indent
2906
-
2907
- lexer.lex_strterm = lex_strterm
2908
- lexer.brace_nest = brace_nest
2909
- lexer.string_nest = string_nest
2910
-
2911
- lexer.cond.pop
2912
- lexer.cmdarg.pop
2913
-
2914
- lexer.lex_state = oldlex_state
2915
-
2916
- case stmt
2917
- when Sexp then
2918
- case stmt.sexp_type
2919
- when :str, :dstr, :evstr then
2920
- result = stmt
2921
- else
2922
- result = s(:evstr, stmt).line line
2923
- end
2924
- when nil then
2925
- result = s(:evstr).line line
2926
- else
2927
- debug 13
2928
- raise "unknown string body: #{stmt.inspect}"
2929
- end
2930
- }
2931
-
2932
- string_dvar: tGVAR
2933
- {
2934
- result = wrap :gvar, val[0]
2935
- }
2936
- | tIVAR
2937
- {
2938
- result = wrap :ivar, val[0]
2939
- }
2940
- | tCVAR
2941
- {
2942
- result = wrap :cvar, val[0]
2943
- }
2944
- | backref
2945
-
2946
- symbol: ssym
2947
- | dsym
2948
-
2949
- ssym: tSYMBEG sym
2950
- {
2951
- lexer.lex_state = EXPR_END
2952
- result = wrap :lit, val[1]
2953
- }
2954
- | tSYMBOL
2955
- {
2956
- lexer.lex_state = EXPR_END
2957
- result = wrap :lit, val[0]
2958
- }
2959
-
2960
- sym: fname | tIVAR | tGVAR | tCVAR
2961
-
2962
- dsym: tSYMBEG string_contents tSTRING_END
2963
- {
2964
- (_, line), result, _ = val
2965
-
2966
- lexer.lex_state = EXPR_END
2967
-
2968
- result ||= s(:str, "").line line
2969
-
2970
- case result.sexp_type
2971
- when :dstr then
2972
- result.sexp_type = :dsym
2973
- when :str then
2974
- result = s(:lit, result.last.to_sym).line result.line
2975
- when :evstr then
2976
- result = s(:dsym, "", result).line result.line
2977
- else
2978
- debug 14
2979
- end
2980
- }
2981
-
2982
- numeric: simple_numeric
2983
- | tUMINUS_NUM simple_numeric =tLOWEST
2984
- {
2985
- _, (num, line) = val
2986
- result = [-num, line]
2987
- }
2988
-
2989
- simple_numeric: tINTEGER
2990
- | tFLOAT
2991
- | tRATIONAL
2992
- | tIMAGINARY
2993
-
2994
- nonlocal_var: tIVAR { result = wrap :ivar, val[0] }
2995
- | tGVAR { result = wrap :gvar, val[0] }
2996
- | tCVAR { result = wrap :cvar, val[0] }
2997
-
2998
- user_variable: tIDENTIFIER
2999
- | tIVAR
3000
- | tGVAR
3001
- | tCONSTANT
3002
- | tCVAR
3003
-
3004
- keyword_variable: kNIL { (_, line), = val; result = s(:nil).line line }
3005
- | kSELF { (_, line), = val; result = s(:self).line line }
3006
- | kTRUE { (_, line), = val; result = s(:true).line line }
3007
- | kFALSE { (_, line), = val; result = s(:false).line line }
3008
- | k__FILE__ { (_, line), = val; result = s(:str, self.file).line line }
3009
- | k__LINE__ { (_, line), = val; result = s(:lit, line).line line }
3010
- | k__ENCODING__
3011
- {
3012
- (_, l), = val
3013
- result =
3014
- if defined? Encoding then
3015
- s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
3016
- else
3017
- s(:str, "Unsupported!").line l
3018
- end
3019
- }
3020
-
3021
- var_ref: user_variable
3022
- {
3023
- raise "NO: #{val.inspect}" if Sexp === val.first
3024
- (var, line), = val
3025
- result = Sexp === var ? var : self.gettable(var)
3026
-
3027
- result.line line
3028
- }
3029
- | keyword_variable
3030
- {
3031
- var = val[0]
3032
- result = Sexp === var ? var : self.gettable(var)
3033
- }
3034
-
3035
- var_lhs: user_variable
3036
- {
3037
- result = self.assignable val[0]
3038
- }
3039
- | keyword_variable
3040
- {
3041
- result = self.assignable val[0]
3042
- debug 15
3043
- }
3044
-
3045
- backref: tNTH_REF
3046
- {
3047
- (ref, line), = val
3048
- result = s(:nth_ref, ref).line line
3049
- }
3050
- | tBACK_REF
3051
- {
3052
- (ref, line), = val
3053
- result = s(:back_ref, ref).line line
3054
- }
3055
-
3056
- superclass: tLT
3057
- {
3058
- lexer.lex_state = EXPR_BEG
3059
- lexer.command_start = true
3060
- }
3061
- expr_value term
3062
- {
3063
- result = val[2]
3064
- }
3065
- | none
3066
- {
3067
- result = nil
3068
- }
3069
-
3070
- f_opt_paren_args: f_paren_args
3071
- | none
3072
- {
3073
- self.in_argdef = false
3074
- result = end_args val
3075
- }
3076
-
3077
- f_paren_args: tLPAREN2 f_args rparen
3078
- {
3079
- self.in_argdef = false
3080
- result = end_args val
3081
- }
3082
-
3083
- f_arglist: f_paren_args
3084
- | {
3085
- result = self.in_kwarg
3086
- self.in_kwarg = true
3087
- self.in_argdef = true
3088
- self.lexer.lex_state |= EXPR_LABEL
3089
- }
3090
- f_args term
3091
- {
3092
- self.in_argdef = false
3093
- result = end_args val
3094
- }
3095
-
3096
- args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
3097
- {
3098
- result = args val
3099
- }
3100
- | f_kwarg opt_f_block_arg
3101
- {
3102
- result = args val
3103
- }
3104
- | f_any_kwrest opt_f_block_arg
3105
- {
3106
- result = args val
3107
- }
3108
- | f_block_arg
3109
- | args_forward
3110
-
3111
- opt_args_tail: tCOMMA args_tail
3112
- {
3113
- result = val[1]
3114
- }
3115
- |
3116
- {
3117
- result = nil
3118
- }
3119
-
3120
- f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
3121
- {
3122
- result = args val
3123
- }
3124
- | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
3125
- {
3126
- result = args val
3127
- }
3128
- | f_arg tCOMMA f_optarg opt_args_tail
3129
- {
3130
- result = args val
3131
- }
3132
- | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
3133
- {
3134
- result = args val
3135
- }
3136
- | f_arg tCOMMA f_rest_arg opt_args_tail
3137
- {
3138
- result = args val
3139
- }
3140
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
3141
- {
3142
- result = args val
3143
- }
3144
- | f_arg opt_args_tail
3145
- {
3146
- result = args val
3147
- }
3148
- | f_optarg tCOMMA f_rest_arg opt_args_tail
3149
- {
3150
- result = args val
3151
- }
3152
- | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
3153
- {
3154
- result = args val
3155
- }
3156
- | f_optarg opt_args_tail
3157
- {
3158
- result = args val
3159
- }
3160
- | f_optarg tCOMMA f_arg opt_args_tail
3161
- {
3162
- result = args val
3163
- }
3164
- | f_rest_arg opt_args_tail
3165
- {
3166
- result = args val
3167
- }
3168
- | f_rest_arg tCOMMA f_arg opt_args_tail
3169
- {
3170
- result = args val
3171
- }
3172
- | args_tail
3173
- {
3174
- result = args val
3175
- }
3176
- |
3177
- {
3178
- result = args val
3179
- }
3180
-
3181
- args_forward: tBDOT3
3182
- {
3183
- (_, line), = val
3184
- result = s(:forward_args).line line
3185
- }
3186
-
3187
- f_bad_arg: tCONSTANT
3188
- {
3189
- yyerror "formal argument cannot be a constant"
3190
- }
3191
- | tIVAR
3192
- {
3193
- yyerror "formal argument cannot be an instance variable"
3194
- }
3195
- | tGVAR
3196
- {
3197
- yyerror "formal argument cannot be a global variable"
3198
- }
3199
- | tCVAR
3200
- {
3201
- yyerror "formal argument cannot be a class variable"
3202
- }
3203
-
3204
- f_norm_arg: f_bad_arg
3205
- | tIDENTIFIER
3206
- {
3207
- (id, line), = val
3208
- identifier = id.to_sym
3209
- self.env[identifier] = :lvar
3210
-
3211
- result = [identifier, line]
3212
- }
3213
-
3214
- f_arg_asgn: f_norm_arg
3215
-
3216
- f_arg_item: f_arg_asgn
3217
- | tLPAREN f_margs rparen
3218
- {
3219
- _, margs, _ = val
3220
-
3221
- result = margs
3222
- }
3223
-
3224
- f_arg: f_arg_item
3225
- {
3226
- result = new_arg val
3227
- }
3228
- | f_arg tCOMMA f_arg_item
3229
- {
3230
- list, _, item = val
3231
-
3232
- if list.sexp_type == :args then
3233
- result = list
3234
- else
3235
- result = s(:args, list).line list.line
3236
- end
3237
-
3238
- if Sexp === item then
3239
- line_max = item.line_max
3240
- else
3241
- item, line_max = item
3242
- end
3243
-
3244
- result << item
3245
- result.line_max = line_max
3246
- }
3247
-
3248
- f_label: tLABEL
3249
- {
3250
- label, = val
3251
- # arg_var(p, formal_argument(p, $1));
3252
- # p->cur_arg = get_id($1);
3253
- # p->max_numparam = ORDINAL_PARAM;
3254
- self.in_argdef = false
3255
- result = label
3256
- }
3257
-
3258
- f_kw: f_label arg_value
3259
- {
3260
- # TODO: new_kw_arg
3261
- (label, line), arg = val
3262
-
3263
- identifier = label.to_sym
3264
- self.env[identifier] = :lvar
3265
- self.in_argdef = true
3266
-
3267
- kwarg = s(:kwarg, identifier, arg).line line
3268
- result = s(:array, kwarg).line line
3269
- }
3270
- | f_label
3271
- {
3272
- (label, line), = val
3273
-
3274
- id = label.to_sym
3275
- self.env[id] = :lvar
3276
- self.in_argdef = true
3277
-
3278
- result = s(:array, s(:kwarg, id).line(line)).line line
3279
- }
3280
-
3281
- f_block_kw: f_label primary_value
3282
- {
3283
- # TODO: new_kw_arg
3284
- (label, line), expr = val
3285
- id = label.to_sym
3286
- self.env[id] = :lvar
3287
- self.in_argdef = true
3288
-
3289
- result = s(:array, s(:kwarg, id, expr).line(line)).line line
3290
- }
3291
- | f_label
3292
- {
3293
- # TODO: new_kw_arg
3294
- (label, line), = val
3295
- id = label.to_sym
3296
- self.env[id] = :lvar
3297
- self.in_argdef = true
3298
-
3299
- result = s(:array, s(:kwarg, id).line(line)).line line
3300
- }
3301
-
3302
- f_block_kwarg: f_block_kw
3303
- | f_block_kwarg tCOMMA f_block_kw
3304
- {
3305
- list, _, item = val
3306
- result = list << item.last
3307
- }
3308
-
3309
- f_kwarg: f_kw
3310
- | f_kwarg tCOMMA f_kw
3311
- {
3312
- result = args val
3313
- }
3314
-
3315
- kwrest_mark: tPOW
3316
- | tDSTAR
3317
-
3318
- f_no_kwarg: kwrest_mark kNIL
3319
- {
3320
- (_, line), _ = val
3321
- result = [:"**nil", line]
3322
- }
3323
-
3324
- f_kwrest: kwrest_mark tIDENTIFIER
3325
- {
3326
- _, (id, line) = val
3327
-
3328
- name = id.to_sym
3329
- self.assignable [name, line]
3330
- result = [:"**#{name}", line]
3331
- }
3332
- | kwrest_mark
3333
- {
3334
- (_, line), = val
3335
- id = :"**"
3336
- self.env[id] = :lvar
3337
- result = [id, line]
3338
- }
3339
-
3340
- f_opt: f_arg_asgn
3341
- f_eq
3342
- arg_value
3343
- {
3344
- lhs, _, rhs = val
3345
- self.in_argdef = true
3346
- result = self.assignable lhs, rhs
3347
- # TODO: detect duplicate names
3348
- # TODO? p->cur_arg = 0;
3349
- }
3350
-
3351
- f_block_opt: f_arg_asgn
3352
- f_eq
3353
- primary_value
3354
- {
3355
- lhs, _, rhs = val
3356
- self.in_argdef = true
3357
- result = self.assignable lhs, rhs
3358
- # TODO? p->cur_arg = 0;
3359
- }
3360
-
3361
- f_block_optarg: f_block_opt
3362
- {
3363
- optblk, = val
3364
- result = s(:block, optblk).line optblk.line
3365
- }
3366
- | f_block_optarg tCOMMA f_block_opt
3367
- {
3368
- optarg, _, optblk = val
3369
- result = optarg
3370
- result << optblk
3371
- }
3372
-
3373
- f_optarg: f_opt
3374
- {
3375
- opt, = val
3376
- result = s(:block, opt).line opt.line
3377
- }
3378
- | f_optarg tCOMMA f_opt
3379
- {
3380
- result = self.block_append val[0], val[2]
3381
- }
3382
-
3383
- restarg_mark: tSTAR2 | tSTAR
3384
-
3385
- f_rest_arg: restarg_mark tIDENTIFIER
3386
- {
3387
- # TODO: differs from parse.y - needs tests
3388
- _, (id, line) = val
3389
- name = id.to_sym
3390
- self.assignable [name, line]
3391
- result = [:"*#{name}", line]
3392
- }
3393
- | restarg_mark
3394
- {
3395
- (_, line), = val
3396
- name = :"*"
3397
- self.env[name] = :lvar
3398
- result = [name, line]
3399
- }
3400
-
3401
- blkarg_mark: tAMPER2 | tAMPER
3402
-
3403
- f_block_arg: blkarg_mark tIDENTIFIER
3404
- {
3405
- _, (id, line) = val
3406
- identifier = id.to_sym
3407
-
3408
- self.env[identifier] = :lvar
3409
- result = ["&#{identifier}".to_sym, line]
3410
- }
3411
- | blkarg_mark
3412
- {
3413
- (_, line), = val
3414
-
3415
- result = [:&, line]
3416
- }
3417
-
3418
- opt_f_block_arg: tCOMMA f_block_arg
3419
- {
3420
- _, arg = val
3421
- result = arg
3422
- }
3423
- |
3424
- {
3425
- result = nil
3426
- }
3427
-
3428
- singleton: var_ref
3429
- | tLPAREN2
3430
- {
3431
- lexer.lex_state = EXPR_BEG
3432
- }
3433
- expr rparen
3434
- {
3435
- result = val[2]
3436
- yyerror "Can't define single method for literals." if
3437
- result.sexp_type == :lit
3438
- }
3439
-
3440
- assoc_list: none
3441
- {
3442
- result = s(:array).line lexer.lineno
3443
- }
3444
- | assocs trailer
3445
-
3446
- assocs: assoc
3447
- | assocs tCOMMA assoc
3448
- {
3449
- list = val[0].dup
3450
- more = val[2].sexp_body
3451
- list.push(*more) unless more.empty?
3452
- result = list
3453
- result.sexp_type = :hash
3454
- }
3455
-
3456
- assoc: arg_value tASSOC arg_value
3457
- {
3458
- v1, _, v2 = val
3459
- result = s(:array, v1, v2).line v1.line
3460
- }
3461
- | tLABEL arg_value
3462
- {
3463
- label, arg = val
3464
-
3465
- lit = wrap :lit, label
3466
- result = s(:array, lit, arg).line lit.line
3467
- }
3468
- | tLABEL
3469
- {
3470
- lit = wrap :lit, val[0]
3471
- arg = nil
3472
-
3473
- result = s(:array, lit, arg).line lit.line
3474
- }
3475
- | tSTRING_BEG string_contents tLABEL_END arg_value
3476
- {
3477
- (_, line), sym, _, value = val
3478
-
3479
- sym.sexp_type = :dsym
3480
-
3481
- result = s(:array, sym, value).line line
3482
- }
3483
- | tDSTAR arg_value
3484
- {
3485
- _, arg = val
3486
- line = arg.line
3487
- result = s(:array, s(:kwsplat, arg).line(line)).line line
3488
- }
3489
- | tDSTAR
3490
- {
3491
- (_, line), = val
3492
- result = s(:array, s(:kwsplat).line(line)).line line
3493
- }
3494
-
3495
- operation: tIDENTIFIER | tCONSTANT | tFID
3496
- operation2: tIDENTIFIER | tCONSTANT | tFID | op
3497
- operation3: tIDENTIFIER | tFID | op
3498
- dot_or_colon: tDOT | tCOLON2
3499
- call_op: tDOT
3500
- | tLONELY # TODO: rename tANDDOT?
3501
-
3502
- call_op2: call_op
3503
- | tCOLON2
3504
-
3505
- opt_terms: | terms
3506
- opt_nl: | tNL
3507
- rparen: opt_nl tRPAREN
3508
- {
3509
- _, close = val # TODO: include lineno in close?
3510
- result = [close, lexer.lineno]
3511
- }
3512
- rbracket: opt_nl tRBRACK
3513
- {
3514
- _, close = val
3515
- result = [close, lexer.lineno]
3516
- }
3517
- rbrace: opt_nl tRCURLY
3518
- {
3519
- _, close = val
3520
- result = [close, lexer.lineno]
3521
- }
3522
- trailer: | tNL | tCOMMA
3523
-
3524
- term: tSEMI { yyerrok }
3525
- | tNL
3526
-
3527
- terms: term
3528
- | terms tSEMI { yyerrok }
3529
-
3530
- none: { result = nil; }
3531
- end
3532
-
3533
- ---- inner
3534
-
3535
- require "ruby_lexer"
3536
- require "ruby_parser_extras"
3537
- include RubyLexer::State::Values
3538
-
3539
- # :stopdoc:
3540
-
3541
- # Local Variables: **
3542
- # racc-token-length-max:14 **
3543
- # End: **