ruby_parser 3.20.3 → 3.21.1

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