ruby_parser 3.20.2 → 3.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/History.rdoc +44 -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 +22 -23
  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} +32 -36
  21. data/lib/{ruby30_parser.rb → ruby_parser30.rb} +38 -39
  22. data/lib/{ruby31_parser.rb → ruby_parser31.rb} +2788 -2704
  23. data/lib/{ruby32_parser.rb → ruby_parser32.rb} +2735 -2741
  24. data/lib/ruby_parser33.rb +13577 -0
  25. data/lib/ruby_parser_extras.rb +36 -18
  26. data/test/test_ruby_lexer.rb +5 -5
  27. data/test/test_ruby_parser.rb +29 -19
  28. data/tools/munge.rb +8 -2
  29. data/tools/ripper.rb +14 -12
  30. data.tar.gz.sig +0 -0
  31. metadata +41 -51
  32. metadata.gz.sig +0 -0
  33. data/lib/ruby20_parser.y +0 -2707
  34. data/lib/ruby21_parser.y +0 -2724
  35. data/lib/ruby22_parser.y +0 -2735
  36. data/lib/ruby23_parser.y +0 -2737
  37. data/lib/ruby24_parser.y +0 -2745
  38. data/lib/ruby25_parser.y +0 -2745
  39. data/lib/ruby26_parser.y +0 -2760
  40. data/lib/ruby27_parser.y +0 -3360
  41. data/lib/ruby30_parser.y +0 -3486
  42. data/lib/ruby31_parser.y +0 -3520
  43. data/lib/ruby32_parser.y +0 -3521
data/lib/ruby20_parser.y DELETED
@@ -1,2707 +0,0 @@
1
- # -*- racc -*-
2
-
3
- class Ruby20Parser
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
-
23
- preclow
24
- nonassoc tLOWEST
25
- nonassoc tLBRACE_ARG
26
- nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
27
- left kOR kAND
28
- right kNOT
29
- nonassoc kDEFINED
30
- right tEQL tOP_ASGN
31
- left kRESCUE_MOD
32
- right tEH tCOLON
33
- nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
34
- left tOROP
35
- left tANDOP
36
- nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
37
- left tGT tGEQ tLT tLEQ
38
- left tPIPE tCARET
39
- left tAMPER2
40
- left tLSHFT tRSHFT
41
- left tPLUS tMINUS
42
- left tSTAR2 tDIVIDE tPERCENT # TODO: tSTAR2 -> tMULT
43
- right tUMINUS_NUM tUMINUS
44
- right tPOW
45
- right tBANG tTILDE tUPLUS
46
- prechigh
47
-
48
- rule
49
-
50
- program: {
51
- self.lexer.lex_state = EXPR_BEG
52
- }
53
- top_compstmt
54
- {
55
- result = new_compstmt val
56
-
57
- lexer.cond.pop # local_pop
58
- lexer.cmdarg.pop
59
- }
60
-
61
- top_compstmt: top_stmts opt_terms
62
- {
63
- stmt, _ = val
64
- result = stmt
65
- }
66
-
67
- top_stmts: none
68
- | top_stmt
69
- | top_stmts terms top_stmt
70
- {
71
- result = self.block_append val[0], val[2]
72
- }
73
- | error top_stmt
74
-
75
- top_stmt: stmt
76
- | klBEGIN
77
- {
78
- if (self.in_def || self.in_single > 0) then
79
- debug 11
80
- yyerror "BEGIN in method"
81
- end
82
- self.env.extend
83
- }
84
- begin_block
85
- {
86
- (_, lineno), _, iter = val
87
- iter.line lineno
88
-
89
- (_, preexe,) = iter
90
- preexe.line lineno
91
-
92
- result = iter
93
- }
94
-
95
- begin_block: tLCURLY { result = lexer.lineno } top_compstmt tRCURLY
96
- {
97
- _, line, stmt, _ = val
98
- result = new_iter s(:preexe).line(line), 0, stmt
99
- }
100
-
101
- bodystmt: compstmt opt_rescue k_else
102
- {
103
- res = _values[-2]
104
- # TODO: move down to main match so I can just use val
105
-
106
- warn "else without rescue is useless" unless res
107
- }
108
- compstmt
109
- opt_ensure
110
- {
111
- body, resc, _, _, els, ens = val
112
-
113
- result = new_body [body, resc, els, ens]
114
- }
115
- | compstmt opt_rescue opt_ensure
116
- {
117
- body, resc, ens = val
118
-
119
- result = new_body [body, resc, nil, ens]
120
- }
121
-
122
- compstmt: stmts opt_terms
123
- {
124
- result = new_compstmt val
125
- }
126
-
127
- stmts: none
128
- | stmt_or_begin # TODO: newline_node ?
129
- | stmts terms stmt_or_begin
130
- {
131
- result = self.block_append val[0], val[2]
132
- }
133
- | error stmt
134
- {
135
- result = val[1]
136
- debug 12
137
- }
138
-
139
- stmt_or_begin: stmt
140
- | klBEGIN
141
- {
142
- yyerror "BEGIN is permitted only at toplevel"
143
- }
144
- begin_block
145
- {
146
- result = val[2] # wtf?
147
- }
148
-
149
- stmt: kALIAS fitem
150
- {
151
- lexer.lex_state = EXPR_FNAME
152
- }
153
- fitem
154
- {
155
- (_, line), lhs, _, rhs = val
156
- result = s(:alias, lhs, rhs).line(line).line line
157
- }
158
- | kALIAS tGVAR tGVAR
159
- {
160
- (_, line), (lhs, _), (rhs, _) = val
161
- result = s(:valias, lhs.to_sym, rhs.to_sym).line line
162
- }
163
- | kALIAS tGVAR tBACK_REF
164
- {
165
- (_, line), (lhs, _), (rhs, _) = val
166
- result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
167
- }
168
- | kALIAS tGVAR tNTH_REF
169
- {
170
- yyerror "can't make alias for the number variables"
171
- }
172
- | kUNDEF undef_list
173
- {
174
- result = val[1]
175
- }
176
- | stmt kIF_MOD expr_value
177
- {
178
- t, _, c = val
179
- result = new_if c, t, nil
180
- }
181
- | stmt kUNLESS_MOD expr_value
182
- {
183
- f, _, c = val
184
- result = new_if c, nil, f
185
- }
186
- | stmt kWHILE_MOD expr_value
187
- {
188
- e, _, c = val
189
- result = new_while e, c, true
190
- }
191
- | stmt kUNTIL_MOD expr_value
192
- {
193
- e, _, c = val
194
- result = new_until e, c, true
195
- }
196
- | stmt kRESCUE_MOD stmt
197
- {
198
- body, _, resbody = val
199
-
200
- resbody = new_resbody s(:array).line(resbody.line), resbody
201
- result = new_rescue body, resbody
202
- }
203
- | klEND tLCURLY compstmt tRCURLY
204
- {
205
- (_, line), _, stmt, _ = val
206
-
207
- if (self.in_def || self.in_single > 0) then
208
- debug 13
209
- yyerror "END in method; use at_exit"
210
- end
211
-
212
- result = new_iter s(:postexe).line(line), 0, stmt
213
- }
214
- | command_asgn
215
- | mlhs tEQL command_call
216
- {
217
- result = new_masgn val[0], val[2], :wrap
218
- }
219
- | lhs tEQL mrhs
220
- {
221
- lhs, _, rhs = val
222
-
223
- result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
224
- }
225
- | mlhs tEQL arg_value
226
- {
227
- result = new_masgn val[0], val[2], :wrap
228
- }
229
- | mlhs tEQL mrhs
230
- {
231
- result = new_masgn val[0], val[2]
232
- }
233
- | expr
234
-
235
- command_asgn: lhs tEQL command_rhs
236
- {
237
- result = new_assign val[0], val[2]
238
- }
239
- # | lhs tEQL command_asgn
240
- # {
241
- # result = new_assign val[0], val[2]
242
- # }
243
- | var_lhs tOP_ASGN command_rhs
244
- {
245
- result = new_op_asgn val
246
- }
247
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
248
- {
249
- result = new_op_asgn1 val
250
- }
251
- | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
252
- {
253
- prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
254
-
255
- result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
256
- result.sexp_type = :safe_op_asgn if call_op == '&.'
257
- result.line prim.line
258
- }
259
- | primary_value call_op tCONSTANT tOP_ASGN command_rhs
260
- {
261
- prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
262
-
263
- result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
264
- result.sexp_type = :safe_op_asgn if call_op == '&.'
265
- result.line prim.line
266
- }
267
- | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
268
- {
269
- lhs1, _, (lhs2, line), (id, _), rhs = val
270
-
271
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
272
- }
273
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
274
- {
275
- lhs1, _, (lhs2, line), (id, _), rhs = val
276
-
277
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
278
- }
279
- | backref tOP_ASGN command_rhs
280
- {
281
- self.backref_assign_error val[0]
282
- }
283
-
284
- command_rhs: command_call =tOP_ASGN
285
- {
286
- expr, = val
287
- result = value_expr expr
288
- }
289
- | command_asgn
290
-
291
- expr: command_call
292
- | expr kAND expr
293
- {
294
- lhs, _, rhs = val
295
- result = logical_op :and, lhs, rhs
296
- }
297
- | expr kOR expr
298
- {
299
- lhs, _, rhs = val
300
- result = logical_op :or, lhs, rhs
301
- }
302
- | kNOT opt_nl expr
303
- {
304
- (_, line), _, expr = val
305
- result = new_call(expr, :"!").line line
306
- # REFACTOR: call_uni_op
307
- }
308
- | tBANG command_call
309
- {
310
- _, cmd = val
311
- result = new_call(cmd, :"!").line cmd.line
312
- # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
313
- # REFACTOR: call_uni_op -- see parse26.y
314
- }
315
- | arg =tLBRACE_ARG
316
-
317
- expr_value: expr
318
- {
319
- result = value_expr(val[0])
320
- }
321
-
322
- expr_value_do: {
323
- lexer.cond.push true
324
- }
325
- expr_value do
326
- {
327
- lexer.cond.pop
328
- }
329
- {
330
- _, expr, _, _ = val
331
- result = expr
332
- }
333
-
334
- command_call: command
335
- | block_command
336
-
337
- block_command: block_call
338
- | block_call call_op2 operation2 command_args
339
- {
340
- blk, _, (msg, _line), args = val
341
- result = new_call(blk, msg.to_sym, args).line blk.line
342
- }
343
-
344
- cmd_brace_block: tLBRACE_ARG
345
- {
346
- # self.env.extend(:dynamic)
347
- result = self.lexer.lineno
348
- }
349
- brace_body tRCURLY
350
- {
351
- _, line, body, _ = val
352
-
353
- result = body
354
- result.line line
355
-
356
- # self.env.unextend
357
- }
358
-
359
- fcall: operation
360
- {
361
- (msg, line), = val
362
- result = new_call(nil, msg.to_sym).line line
363
- }
364
-
365
- command: fcall command_args =tLOWEST
366
- {
367
- call, args = val
368
- result = call.concat args.sexp_body
369
- }
370
- | fcall command_args cmd_brace_block
371
- {
372
- call, args, block = val
373
-
374
- result = call.concat args.sexp_body
375
-
376
- if block then
377
- block_dup_check result, block
378
-
379
- result, operation = block, result
380
- result.insert 1, operation
381
- end
382
- }
383
- | primary_value call_op operation2 command_args =tLOWEST
384
- {
385
- lhs, callop, (op, _), args = val
386
-
387
- result = new_call lhs, op.to_sym, args, callop
388
- result.line lhs.line
389
- }
390
- | primary_value call_op operation2 command_args cmd_brace_block
391
- {
392
- recv, _, (msg, _line), args, block = val
393
- call = new_call recv, msg.to_sym, args, val[1]
394
-
395
- block_dup_check call, block
396
-
397
- block.insert 1, call
398
- result = block
399
- }
400
- | primary_value tCOLON2 operation2 command_args =tLOWEST
401
- {
402
- lhs, _, (id, line), args = val
403
-
404
- result = new_call lhs, id.to_sym, args
405
- result.line line
406
- }
407
- | primary_value tCOLON2 operation2 command_args cmd_brace_block
408
- {
409
- recv, _, (msg, _line), args, block = val
410
- call = new_call recv, msg.to_sym, args
411
-
412
- block_dup_check call, block
413
-
414
- block.insert 1, call
415
- result = block
416
- }
417
- | kSUPER command_args
418
- {
419
- result = new_super val[1]
420
- }
421
- | kYIELD command_args
422
- {
423
- (_, line), args = val
424
- result = new_yield args
425
- result.line line # TODO: push to new_yield
426
- }
427
- | k_return call_args
428
- {
429
- line = val[0].last
430
- result = s(:return, ret_args(val[1])).line(line)
431
- }
432
- | kBREAK call_args
433
- {
434
- (_, line), args = val
435
- result = s(:break, ret_args(args)).line line
436
- }
437
- | kNEXT call_args
438
- {
439
- line = val[0].last
440
- result = s(:next, ret_args(val[1])).line(line)
441
- }
442
-
443
- mlhs: mlhs_basic
444
- | tLPAREN mlhs_inner rparen
445
- {
446
- result = val[1]
447
- }
448
-
449
- mlhs_inner: mlhs_basic
450
- | tLPAREN mlhs_inner rparen
451
- {
452
- _, arg, _ = val
453
- l = arg.line
454
-
455
- result = s(:masgn, s(:array, arg).line(l)).line l
456
- }
457
-
458
- mlhs_basic: mlhs_head
459
- {
460
- head, = val
461
- result = s(:masgn, head).line head.line
462
- }
463
- | mlhs_head mlhs_item
464
- {
465
- lhs, rhs = val
466
- result = s(:masgn, lhs << rhs.compact).line lhs.line
467
- }
468
- | mlhs_head tSTAR mlhs_node
469
- {
470
- head, _, tail = val
471
- head << s(:splat, tail).line(tail.line)
472
- result = s(:masgn, head).line head.line
473
- }
474
- | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
475
- {
476
- ary1, _, splat, _, ary2 = val
477
-
478
- result = list_append ary1, s(:splat, splat).line(splat.line)
479
- result.concat ary2.sexp_body
480
- result = s(:masgn, result).line result.line
481
- }
482
- | mlhs_head tSTAR
483
- {
484
- head, _ = val
485
- l = head.line
486
- result = s(:masgn, head << s(:splat).line(l)).line l
487
- }
488
- | mlhs_head tSTAR tCOMMA mlhs_post
489
- {
490
- head, _, _, post = val
491
- ary = list_append head, s(:splat).line(head.line)
492
- ary.concat post.sexp_body
493
- result = s(:masgn, ary).line ary.line
494
- }
495
- | tSTAR mlhs_node
496
- {
497
- _, node = val
498
- l = node.line
499
- splat = s(:splat, node).line l
500
- ary = s(:array, splat).line l
501
- result = s(:masgn, ary).line l
502
- }
503
- | tSTAR mlhs_node tCOMMA mlhs_post
504
- {
505
- _, node, _, post = val
506
-
507
- splat = s(:splat, node).line node.line
508
- ary = s(:array, splat).line splat.line
509
- ary.concat post.sexp_body
510
- result = s(:masgn, ary).line ary.line
511
- }
512
- | tSTAR
513
- {
514
- l = lexer.lineno
515
- result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
516
- }
517
- | tSTAR tCOMMA mlhs_post
518
- {
519
- _, _, post = val
520
- l = post.line
521
-
522
- splat = s(:splat).line l
523
- ary = s(:array, splat, *post.sexp_body).line l
524
- result = s(:masgn, ary).line l
525
- }
526
-
527
- mlhs_item: mlhs_node
528
- | tLPAREN mlhs_inner rparen
529
- {
530
- result = val[1]
531
- }
532
-
533
- mlhs_head: mlhs_item tCOMMA
534
- {
535
- lhs, _ = val
536
- result = s(:array, lhs).line lhs.line
537
- }
538
- | mlhs_head mlhs_item tCOMMA
539
- {
540
- result = val[0] << val[1].compact
541
- }
542
-
543
- mlhs_post: mlhs_item
544
- {
545
- item, = val
546
- result = s(:array, item).line item.line
547
- }
548
- | mlhs_post tCOMMA mlhs_item
549
- {
550
- result = list_append val[0], val[2]
551
- }
552
-
553
- mlhs_node: user_variable
554
- {
555
- result = self.assignable val[0]
556
- }
557
- | keyword_variable
558
- {
559
- result = self.assignable val[0]
560
- }
561
- | primary_value tLBRACK2 opt_call_args rbracket
562
- {
563
- result = self.aryset val[0], val[2]
564
- }
565
- | primary_value call_op tIDENTIFIER
566
- {
567
- lhs, call_op, (id, _line) = val
568
-
569
- result = new_attrasgn lhs, id, call_op
570
- }
571
- | primary_value tCOLON2 tIDENTIFIER
572
- {
573
- recv, _, (id, _line) = val
574
- result = new_attrasgn recv, id
575
- }
576
- | primary_value call_op tCONSTANT
577
- {
578
- lhs, call_op, (id, _line) = val
579
-
580
- result = new_attrasgn lhs, id, call_op
581
- }
582
- | primary_value tCOLON2 tCONSTANT
583
- {
584
- if (self.in_def || self.in_single > 0) then
585
- debug 14
586
- yyerror "dynamic constant assignment"
587
- end
588
-
589
- expr, _, (id, _line) = val
590
- l = expr.line
591
-
592
- result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
593
- }
594
- | tCOLON3 tCONSTANT
595
- {
596
- if (self.in_def || self.in_single > 0) then
597
- debug 15
598
- yyerror "dynamic constant assignment"
599
- end
600
-
601
- _, (id, l) = val
602
-
603
- result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
604
- }
605
- | backref
606
- {
607
- ref, = val
608
-
609
- self.backref_assign_error ref
610
- }
611
-
612
- lhs: user_variable
613
- {
614
- var, = val
615
-
616
- result = self.assignable var
617
- }
618
- | keyword_variable
619
- {
620
- var, = val
621
-
622
- result = self.assignable var
623
-
624
- debug 16
625
- }
626
- | primary_value tLBRACK2 opt_call_args rbracket
627
- {
628
- lhs, _, args, _ = val
629
-
630
- result = self.aryset lhs, args
631
- }
632
- | primary_value call_op tIDENTIFIER # REFACTOR
633
- {
634
- lhs, op, (id, _line) = val
635
-
636
- result = new_attrasgn lhs, id, op
637
- }
638
- | primary_value tCOLON2 tIDENTIFIER
639
- {
640
- lhs, _, (id, _line) = val
641
-
642
- result = new_attrasgn lhs, id
643
- }
644
- | primary_value call_op tCONSTANT # REFACTOR?
645
- {
646
- lhs, call_op, (id, _line) = val
647
-
648
- result = new_attrasgn lhs, id, call_op
649
- }
650
- | primary_value tCOLON2 tCONSTANT
651
- {
652
- expr, _, (id, _line) = val
653
-
654
- if (self.in_def || self.in_single > 0) then
655
- debug 17
656
- yyerror "dynamic constant assignment"
657
- end
658
-
659
- l = expr.line
660
- result = s(:const, s(:colon2, expr, id.to_sym).line(l)).line l
661
- }
662
- | tCOLON3 tCONSTANT
663
- {
664
- _, (id, l) = val
665
-
666
- if (self.in_def || self.in_single > 0) then
667
- debug 18
668
- yyerror "dynamic constant assignment"
669
- end
670
-
671
- result = s(:const, s(:colon3, id.to_sym).line(l)).line l
672
- }
673
- | backref
674
- {
675
- self.backref_assign_error val[0]
676
- }
677
-
678
- cname: tIDENTIFIER
679
- {
680
- yyerror "class/module name must be CONSTANT"
681
- }
682
- | tCONSTANT
683
-
684
- cpath: tCOLON3 cname
685
- {
686
- result = wrap :colon3, val[1]
687
- }
688
- | cname
689
- {
690
- (id, line), = val
691
- result = [id.to_sym, line] # TODO: sexp?
692
- }
693
- | primary_value tCOLON2 cname
694
- {
695
- pval, _, (name, _line) = val
696
-
697
- result = s(:colon2, pval, name.to_sym)
698
- result.line pval.line
699
- }
700
-
701
- fname: tIDENTIFIER | tCONSTANT | tFID
702
- | op
703
- {
704
- lexer.lex_state = EXPR_END
705
- }
706
-
707
- | reswords
708
-
709
- fitem: fname
710
- {
711
- result = wrap :lit, val[0]
712
- }
713
- | symbol
714
-
715
- undef_list: fitem
716
- {
717
- result = new_undef val[0]
718
- }
719
- |
720
- undef_list tCOMMA
721
- {
722
- lexer.lex_state = EXPR_FNAME
723
- }
724
- fitem
725
- {
726
- result = new_undef val[0], val[3]
727
- }
728
-
729
- op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
730
- | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
731
- | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
732
- | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
733
- | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
734
-
735
- reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
736
- | kALIAS | kAND | kBEGIN | kBREAK | kCASE
737
- | kCLASS | kDEF | kDEFINED | kDO | kELSE
738
- | kELSIF | kEND | kENSURE | kFALSE | kFOR
739
- | kIN | kMODULE | kNEXT | kNIL | kNOT
740
- | kOR | kREDO | kRESCUE | kRETRY | kRETURN
741
- | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
742
- | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
743
- | kUNTIL
744
-
745
- arg: lhs tEQL arg_rhs
746
- {
747
- result = new_assign val[0], val[2]
748
- }
749
- | var_lhs tOP_ASGN arg_rhs
750
- {
751
- result = new_op_asgn val
752
- }
753
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
754
- {
755
- result = new_op_asgn1 val
756
- }
757
- | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
758
- {
759
- result = new_op_asgn2 val
760
- }
761
- | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
762
- {
763
- result = new_op_asgn2 val
764
- }
765
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
766
- {
767
- lhs, _, (id, _line), (op, _), rhs = val
768
-
769
- result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
770
- }
771
- | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
772
- {
773
- lhs1, _, (lhs2, _line), op, rhs = val
774
-
775
- lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
776
- result = new_const_op_asgn [lhs, op, rhs]
777
- }
778
- | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
779
- {
780
- _, lhs, op, rhs = val
781
-
782
- lhs = wrap :colon3, lhs
783
- result = new_const_op_asgn [lhs, op, rhs]
784
- }
785
- | backref tOP_ASGN arg_rhs
786
- {
787
- # TODO: lhs = var_field val[0]
788
- asgn = new_op_asgn val
789
- result = self.backref_assign_error asgn
790
- }
791
- | arg tDOT2 arg
792
- {
793
- v1, v2 = val[0], val[2]
794
- if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
795
- result = s(:lit, (v1.last)..(v2.last)).line v1.line
796
- else
797
- result = s(:dot2, v1, v2).line v1.line
798
- end
799
- }
800
- | arg tDOT3 arg
801
- {
802
- v1, v2 = val[0], val[2]
803
- if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
804
- result = s(:lit, (v1.last)...(v2.last)).line v1.line
805
- else
806
- result = s(:dot3, v1, v2).line v1.line
807
- end
808
- }
809
-
810
-
811
- | arg tPLUS arg
812
- {
813
- result = new_call val[0], :+, argl(val[2])
814
- }
815
- | arg tMINUS arg
816
- {
817
- result = new_call val[0], :-, argl(val[2])
818
- }
819
- | arg tSTAR2 arg # TODO: rename
820
- {
821
- result = new_call val[0], :*, argl(val[2])
822
- }
823
- | arg tDIVIDE arg
824
- {
825
- result = new_call val[0], :"/", argl(val[2])
826
- }
827
- | arg tPERCENT arg
828
- {
829
- result = new_call val[0], :"%", argl(val[2])
830
- }
831
- | arg tPOW arg
832
- {
833
- result = new_call val[0], :**, argl(val[2])
834
- }
835
- | tUMINUS_NUM tINTEGER tPOW arg
836
- {
837
- _, (num, line), _, arg = val
838
- lit = s(:lit, num).line line
839
- result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
840
- }
841
- | tUMINUS_NUM tFLOAT tPOW arg
842
- {
843
- _, (num, line), _, arg = val
844
- lit = s(:lit, num).line line
845
- result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
846
-
847
- ## TODO: why is this 2.0 only?
848
- debug 19
849
- }
850
- | tUPLUS arg
851
- {
852
- result = new_call val[1], :"+@"
853
- }
854
- | tUMINUS arg
855
- {
856
- result = new_call val[1], :"-@"
857
- }
858
- | arg tPIPE arg
859
- {
860
- result = new_call val[0], :"|", argl(val[2])
861
- }
862
- | arg tCARET arg
863
- {
864
- result = new_call val[0], :"^", argl(val[2])
865
- }
866
- | arg tAMPER2 arg
867
- {
868
- result = new_call val[0], :"&", argl(val[2])
869
- }
870
- | arg tCMP arg
871
- {
872
- result = new_call val[0], :"<=>", argl(val[2])
873
- }
874
- | rel_expr =tCMP
875
- | arg tEQ arg
876
- {
877
- result = new_call val[0], :"==", argl(val[2])
878
- }
879
- | arg tEQQ arg
880
- {
881
- result = new_call val[0], :"===", argl(val[2])
882
- }
883
- | arg tNEQ arg
884
- {
885
- result = new_call val[0], :"!=", argl(val[2])
886
- }
887
- | arg tMATCH arg
888
- {
889
- lhs, _, rhs = val
890
- result = new_match lhs, rhs
891
- }
892
- | arg tNMATCH arg
893
- {
894
- lhs, _, rhs = val
895
- result = s(:not, new_match(lhs, rhs)).line lhs.line
896
- }
897
- | tBANG arg
898
- {
899
- _, arg = val
900
- result = new_call arg, :"!"
901
- result.line arg.line
902
- }
903
- | tTILDE arg
904
- {
905
- result = new_call value_expr(val[1]), :"~"
906
- }
907
- | arg tLSHFT arg
908
- {
909
- val[0] = value_expr val[0]
910
- val[2] = value_expr val[2]
911
- result = new_call val[0], :"\<\<", argl(val[2])
912
- }
913
- | arg tRSHFT arg
914
- {
915
- val[0] = value_expr val[0]
916
- val[2] = value_expr val[2]
917
- result = new_call val[0], :">>", argl(val[2])
918
- }
919
- | arg tANDOP arg
920
- {
921
- result = logical_op :and, val[0], val[2]
922
- }
923
- | arg tOROP arg
924
- {
925
- result = logical_op :or, val[0], val[2]
926
- }
927
- | kDEFINED opt_nl arg
928
- {
929
- (_, line), _, arg = val
930
- result = s(:defined, arg).line line
931
- }
932
- | arg tEH arg opt_nl tCOLON arg
933
- {
934
- c, _, t, _, _, f = val
935
- result = s(:if, c, t, f).line c.line
936
- }
937
- | primary
938
-
939
- relop: tGT
940
- | tLT
941
- | tGEQ
942
- | tLEQ
943
-
944
- rel_expr: arg relop arg =tGT
945
- {
946
- lhs, (op, _), rhs = val
947
- result = new_call lhs, op.to_sym, argl(rhs)
948
- }
949
- | rel_expr relop arg =tGT
950
- {
951
- lhs, (op, _), rhs = val
952
- warn "comparison '%s' after comparison", op
953
- result = new_call lhs, op.to_sym, argl(rhs)
954
- }
955
-
956
- arg_value: arg
957
- {
958
- result = value_expr(val[0])
959
- }
960
-
961
- aref_args: none
962
- | args trailer
963
- {
964
- result = args [val[0]]
965
- }
966
- | args tCOMMA assocs trailer
967
- {
968
- result = args [val[0], array_to_hash(val[2])]
969
- }
970
- | assocs trailer
971
- {
972
- result = args [array_to_hash(val[0])]
973
- }
974
-
975
- arg_rhs: arg =tOP_ASGN
976
- | arg kRESCUE_MOD arg
977
- {
978
- body, (_, line), resbody = val
979
- body = value_expr body
980
- resbody = remove_begin resbody
981
-
982
- ary = s(:array).line line
983
- result = new_rescue(body, new_resbody(ary, resbody))
984
- }
985
-
986
- paren_args: tLPAREN2 opt_call_args rparen
987
- {
988
- _, args, (_, line_max) = val
989
-
990
- result = args
991
- result.line_max = line_max if args
992
- }
993
-
994
- opt_paren_args: none
995
- | paren_args
996
-
997
- opt_call_args: none
998
- | call_args
999
- | args tCOMMA
1000
- {
1001
- result = args val
1002
- }
1003
- | args tCOMMA assocs tCOMMA
1004
- {
1005
- result = args [val[0], array_to_hash(val[2])]
1006
- }
1007
- | assocs tCOMMA
1008
- {
1009
- result = args [array_to_hash(val[0])]
1010
- }
1011
-
1012
- call_args: command
1013
- {
1014
- warning "parenthesize argument(s) for future version"
1015
- result = call_args val
1016
- }
1017
- | args opt_block_arg
1018
- {
1019
- result = call_args val
1020
- }
1021
- | assocs opt_block_arg
1022
- {
1023
- result = call_args [array_to_hash(val[0]), val[1]]
1024
- }
1025
- | args tCOMMA assocs opt_block_arg
1026
- {
1027
- result = call_args [val[0], array_to_hash(val[2]), val[3]]
1028
- }
1029
- | block_arg
1030
- {
1031
- result = call_args val
1032
- }
1033
-
1034
- command_args: {
1035
- # parse26.y line 2200
1036
-
1037
- # If call_args starts with a open paren '(' or
1038
- # '[', look-ahead reading of the letters calls
1039
- # CMDARG_PUSH(0), but the push must be done
1040
- # after CMDARG_PUSH(1). So this code makes them
1041
- # consistent by first cancelling the premature
1042
- # CMDARG_PUSH(0), doing CMDARG_PUSH(1), and
1043
- # finally redoing CMDARG_PUSH(0).
1044
-
1045
- result = yychar = self.last_token_type.first
1046
- lookahead = [:tLPAREN, :tLPAREN_ARG, :tLPAREN2, :tLBRACK, :tLBRACK2].include?(yychar)
1047
- lexer.cmdarg.pop if lookahead
1048
- lexer.cmdarg.push true
1049
- lexer.cmdarg.push false if lookahead
1050
- }
1051
- call_args
1052
- {
1053
- yychar, args = val
1054
-
1055
- # call_args can be followed by tLBRACE_ARG (that
1056
- # does CMDARG_PUSH(0) in the lexer) but the push
1057
- # must be done after CMDARG_POP() in the parser.
1058
- # So this code does CMDARG_POP() to pop 0 pushed
1059
- # by tLBRACE_ARG, CMDARG_POP() to pop 1 pushed
1060
- # by command_args, and CMDARG_PUSH(0) to restore
1061
- # back the flag set by tLBRACE_ARG.
1062
-
1063
- lookahead = [:tLBRACE_ARG].include?(yychar)
1064
- lexer.cmdarg.pop if lookahead
1065
- lexer.cmdarg.pop
1066
- lexer.cmdarg.push false if lookahead
1067
- result = args
1068
- }
1069
-
1070
- block_arg: tAMPER arg_value
1071
- {
1072
- _, arg = val
1073
- result = s(:block_pass, arg).line arg.line
1074
- }
1075
-
1076
- opt_block_arg: tCOMMA block_arg
1077
- {
1078
- result = val[1]
1079
- }
1080
- | none
1081
-
1082
- args: arg_value
1083
- {
1084
- arg, = val
1085
- lineno = arg.line || lexer.lineno # HACK
1086
-
1087
- result = s(:array, arg).line lineno
1088
- }
1089
- | tSTAR arg_value
1090
- {
1091
- _, arg = val
1092
- result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1093
- }
1094
- | args tCOMMA arg_value
1095
- {
1096
- args, _, id = val
1097
- result = self.list_append args, id
1098
- }
1099
- | args tCOMMA tSTAR arg_value
1100
- {
1101
- # TODO: the line number from tSTAR has been dropped
1102
- args, _, _, id = val
1103
- line = lexer.lineno
1104
- result = self.list_append args, s(:splat, id).line(line)
1105
- }
1106
-
1107
- mrhs: args tCOMMA arg_value
1108
- {
1109
- result = val[0] << val[2]
1110
- }
1111
- | args tCOMMA tSTAR arg_value
1112
- {
1113
- # TODO: make all tXXXX terminals include lexer.lineno
1114
- arg, _, _, splat = val
1115
- result = self.arg_concat arg, splat
1116
- }
1117
- | tSTAR arg_value
1118
- {
1119
- _, arg = val
1120
- result = s(:splat, arg).line arg.line
1121
- }
1122
-
1123
- primary: literal
1124
- | strings
1125
- | xstring
1126
- | regexp
1127
- | words
1128
- | qwords
1129
- | symbols
1130
- | qsymbols
1131
- | var_ref
1132
- | backref
1133
- | tFID
1134
- {
1135
- (msg, line), = val
1136
- result = new_call nil, msg.to_sym
1137
- result.line line
1138
- }
1139
- | k_begin
1140
- {
1141
- lexer.cmdarg.push false
1142
- }
1143
- bodystmt k_end
1144
- {
1145
- lexer.cmdarg.pop
1146
- result = new_begin val
1147
- }
1148
- | tLPAREN_ARG
1149
- {
1150
- lexer.lex_state = EXPR_ENDARG
1151
- result = lexer.lineno
1152
- }
1153
- rparen
1154
- {
1155
- _, line, _ = val
1156
- result = s(:begin).line line
1157
- }
1158
- | tLPAREN_ARG
1159
- stmt
1160
- {
1161
- lexer.lex_state = EXPR_ENDARG
1162
- }
1163
- rparen
1164
- {
1165
- _, stmt, _, _, = val
1166
- # warning "(...) interpreted as grouped expression"
1167
- result = stmt
1168
- }
1169
- | tLPAREN compstmt tRPAREN
1170
- {
1171
- _, stmt, _ = val
1172
- result = stmt
1173
- result ||= s(:nil).line lexer.lineno
1174
- result.paren = true
1175
- }
1176
- | primary_value tCOLON2 tCONSTANT
1177
- {
1178
- expr, _, (id, _line) = val
1179
-
1180
- result = s(:colon2, expr, id.to_sym).line expr.line
1181
- }
1182
- | tCOLON3 tCONSTANT
1183
- {
1184
- result = wrap :colon3, val[1]
1185
- }
1186
- | tLBRACK { result = lexer.lineno } aref_args rbracket
1187
- {
1188
- _, line, args, (_, line_max) = val
1189
-
1190
- result = args || s(:array)
1191
- result.sexp_type = :array # aref_args is :args
1192
- result.line line
1193
- result.line_max = line_max
1194
- }
1195
- | tLBRACE
1196
- {
1197
- result = self.lexer.lineno
1198
- }
1199
- assoc_list tRCURLY
1200
- {
1201
- result = new_hash val
1202
- }
1203
- | k_return
1204
- {
1205
- (_, line), = val
1206
- result = s(:return).line line
1207
- }
1208
- | kYIELD tLPAREN2 call_args rparen
1209
- {
1210
- (_, line), _, args, _ = val
1211
-
1212
- result = new_yield(args).line line
1213
- }
1214
- | kYIELD tLPAREN2 rparen
1215
- {
1216
- (_, line), _, _ = val
1217
-
1218
- result = new_yield.line line
1219
- }
1220
- | kYIELD
1221
- {
1222
- (_, line), = val
1223
-
1224
- result = new_yield.line line
1225
- }
1226
- | kDEFINED opt_nl tLPAREN2 expr rparen
1227
- {
1228
- (_, line), _, _, arg, _ = val
1229
-
1230
- result = s(:defined, arg).line line
1231
- }
1232
- | kNOT tLPAREN2 expr rparen
1233
- {
1234
- _, _, lhs, _ = val
1235
- result = new_call lhs, :"!"
1236
- }
1237
- | kNOT tLPAREN2 rparen
1238
- {
1239
- debug 20
1240
- }
1241
- | fcall brace_block
1242
- {
1243
- call, iter = val
1244
-
1245
- iter.insert 1, call
1246
- result = iter
1247
- # FIX: probably not: call.line = iter.line
1248
- }
1249
- | method_call
1250
- | method_call brace_block
1251
- {
1252
- call, iter = val[0], val[1]
1253
- block_dup_check call, iter
1254
- iter.insert 1, call # FIX
1255
- result = iter
1256
- }
1257
- | lambda
1258
- {
1259
- expr, = val
1260
- result = expr
1261
- }
1262
- | k_if expr_value then compstmt if_tail k_end
1263
- {
1264
- _, c, _, t, f, _ = val
1265
- result = new_if c, t, f
1266
- }
1267
- | k_unless expr_value then compstmt opt_else k_end
1268
- {
1269
- _, c, _, t, f, _ = val
1270
- result = new_if c, f, t
1271
- }
1272
- | k_while expr_value_do compstmt k_end
1273
- {
1274
- _, cond, body, _ = val
1275
- result = new_while body, cond, true
1276
- }
1277
- | k_until expr_value_do compstmt k_end
1278
- {
1279
- _, cond, body, _ = val
1280
- result = new_until body, cond, true
1281
- }
1282
- | k_case expr_value opt_terms case_body k_end
1283
- {
1284
- (_, line), expr, _, body, _ = val
1285
- result = new_case expr, body, line
1286
- }
1287
- | k_case opt_terms case_body k_end
1288
- {
1289
- (_, line), _, body, _ = val
1290
- result = new_case nil, body, line
1291
- }
1292
- | k_for for_var kIN expr_value_do compstmt k_end
1293
- {
1294
- _, var, _, iter, body, _ = val
1295
- result = new_for iter, var, body
1296
- }
1297
- | k_class
1298
- cpath superclass
1299
- {
1300
- if (self.in_def || self.in_single > 0) then
1301
- yyerror "class definition in method body"
1302
- end
1303
- self.env.extend
1304
- }
1305
- bodystmt k_end
1306
- {
1307
- result = new_class val
1308
- self.env.unextend
1309
- self.lexer.ignore_body_comments
1310
- }
1311
- | k_class tLSHFT
1312
- expr
1313
- {
1314
- result = self.in_def
1315
- self.in_def = false
1316
- }
1317
- term
1318
- {
1319
- result = self.in_single
1320
- self.in_single = 0
1321
- self.env.extend
1322
- }
1323
- bodystmt k_end
1324
- {
1325
- result = new_sclass val
1326
- self.env.unextend
1327
- self.lexer.ignore_body_comments
1328
- }
1329
- | k_module
1330
- cpath
1331
- {
1332
- yyerror "module definition in method body" if
1333
- self.in_def or self.in_single > 0
1334
-
1335
- self.env.extend
1336
- }
1337
- bodystmt k_end
1338
- {
1339
- result = new_module val
1340
- self.env.unextend
1341
- self.lexer.ignore_body_comments
1342
- }
1343
- | k_def fname
1344
- {
1345
- result = self.in_def
1346
-
1347
- self.in_def = true # group = local_push
1348
- self.env.extend
1349
- lexer.cmdarg.push false
1350
- lexer.cond.push false
1351
- }
1352
- f_arglist bodystmt k_end
1353
- {
1354
- result, in_def = new_defn val
1355
-
1356
- lexer.cond.pop # group = local_pop
1357
- lexer.cmdarg.pop
1358
- self.env.unextend
1359
- self.in_def = in_def
1360
-
1361
- self.lexer.ignore_body_comments
1362
- }
1363
- | k_def singleton dot_or_colon
1364
- {
1365
- lexer.lex_state = EXPR_FNAME
1366
- }
1367
- fname
1368
- {
1369
- result = self.in_def
1370
-
1371
- self.in_single += 1 # TODO: remove?
1372
-
1373
- self.in_def = true # local_push
1374
- self.env.extend
1375
- lexer.cmdarg.push false
1376
- lexer.cond.push false
1377
-
1378
- lexer.lex_state = EXPR_ENDFN|EXPR_LABEL
1379
- }
1380
- f_arglist bodystmt k_end
1381
- {
1382
-
1383
- # [kdef, recv, _, _, (name, line), in_def, args, body, kend]
1384
- # =>
1385
- # [kdef, recv, (name, line), in_def, args, body, kend]
1386
-
1387
- val.delete_at 3
1388
- val.delete_at 2
1389
-
1390
- result, in_def = new_defs val
1391
-
1392
- lexer.cond.pop # group = local_pop
1393
- lexer.cmdarg.pop
1394
- self.env.unextend
1395
- self.in_def = in_def
1396
-
1397
- self.in_single -= 1
1398
-
1399
- # TODO: restore cur_arg ? what's cur_arg?
1400
-
1401
- self.lexer.ignore_body_comments
1402
- }
1403
- | kBREAK
1404
- {
1405
- (_, line), = val
1406
- result = s(:break).line line
1407
- }
1408
- | kNEXT
1409
- {
1410
- (_, line), = val
1411
- result = s(:next).line line
1412
- }
1413
- | kREDO
1414
- {
1415
- (_, line), = val
1416
- result = s(:redo).line line
1417
- }
1418
- | kRETRY
1419
- {
1420
- (_, line), = val
1421
- result = s(:retry).line line
1422
- }
1423
-
1424
- primary_value: primary
1425
- {
1426
- result = value_expr(val[0])
1427
- }
1428
-
1429
- # These are really stupid
1430
- k_begin: kBEGIN
1431
- k_if: kIF
1432
- k_unless: kUNLESS
1433
- k_while: kWHILE
1434
- k_until: kUNTIL
1435
- k_case: kCASE
1436
- k_for: kFOR
1437
- k_class: kCLASS
1438
- {
1439
- self.comments.push self.lexer.comments
1440
- }
1441
- k_module: kMODULE
1442
- {
1443
- self.comments.push self.lexer.comments
1444
- }
1445
- k_def: kDEF
1446
- {
1447
- self.comments.push self.lexer.comments
1448
- }
1449
- k_do: kDO
1450
- k_do_block: kDO_BLOCK
1451
- k_rescue: kRESCUE
1452
- k_ensure: kENSURE
1453
- k_when: kWHEN
1454
- k_else: kELSE
1455
- k_elsif: kELSIF
1456
- k_end: kEND
1457
- k_return: kRETURN
1458
-
1459
- then: term
1460
- | kTHEN
1461
- | term kTHEN
1462
-
1463
- do: term
1464
- | kDO_COND
1465
-
1466
- if_tail: opt_else
1467
- | k_elsif expr_value then compstmt if_tail
1468
- {
1469
- (_, line), c, _, t, rest = val
1470
-
1471
- result = s(:if, c, t, rest).line line
1472
- }
1473
-
1474
- opt_else: none
1475
- | kELSE compstmt
1476
- {
1477
- result = val[1]
1478
- }
1479
-
1480
- for_var: lhs
1481
- | mlhs
1482
- {
1483
- val[0].delete_at 1 if val[0][1].nil? # HACK
1484
- }
1485
-
1486
- f_marg: f_norm_arg
1487
- | tLPAREN f_margs rparen
1488
- {
1489
- result = val[1]
1490
- }
1491
-
1492
- f_marg_list: f_marg
1493
- {
1494
- sym, = val
1495
-
1496
- result = s(:array, sym).line lexer.lineno
1497
- }
1498
- | f_marg_list tCOMMA f_marg
1499
- {
1500
- result = list_append val[0], val[2]
1501
- }
1502
-
1503
- f_margs: f_marg_list
1504
- {
1505
- args, = val
1506
-
1507
- result = block_var args
1508
- }
1509
- | f_marg_list tCOMMA f_rest_marg
1510
- {
1511
- args, _, rest = val
1512
-
1513
- result = block_var args, rest
1514
- }
1515
- | f_marg_list tCOMMA f_rest_marg tCOMMA f_marg_list
1516
- {
1517
- lhs, _, splat, _, rhs = val
1518
-
1519
- result = block_var lhs, splat, rhs
1520
- }
1521
- | f_rest_marg
1522
- {
1523
- rest, = val
1524
-
1525
- result = block_var rest
1526
- }
1527
- | f_rest_marg tCOMMA f_marg_list
1528
- {
1529
- splat, _, rest = val
1530
-
1531
- result = block_var splat, rest
1532
- }
1533
-
1534
- f_rest_marg: tSTAR f_norm_arg
1535
- {
1536
- _, (id, line) = val
1537
-
1538
- result = args ["*#{id}".to_sym]
1539
- result.line line
1540
- }
1541
- | tSTAR
1542
- {
1543
- result = args [:*]
1544
- result.line lexer.lineno # FIX: tSTAR -> line
1545
- }
1546
-
1547
- block_args_tail: f_block_kwarg tCOMMA f_kwrest opt_f_block_arg
1548
- {
1549
- result = call_args val
1550
- }
1551
- | f_block_kwarg opt_f_block_arg
1552
- {
1553
- result = call_args val
1554
- }
1555
- | f_kwrest opt_f_block_arg
1556
- {
1557
- result = call_args val
1558
- }
1559
- | f_block_arg
1560
- {
1561
- (id, line), = val
1562
- result = call_args [id]
1563
- result.line line
1564
- }
1565
-
1566
- opt_block_args_tail: tCOMMA block_args_tail
1567
- {
1568
- result = args val
1569
- }
1570
- | none
1571
-
1572
- block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1573
- {
1574
- result = args val
1575
- }
1576
- | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1577
- {
1578
- result = args val
1579
- }
1580
- | f_arg tCOMMA f_block_optarg opt_block_args_tail
1581
- {
1582
- result = args val
1583
- }
1584
- | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_block_args_tail
1585
- {
1586
- result = args val
1587
- }
1588
- | f_arg tCOMMA f_rest_arg opt_block_args_tail
1589
- {
1590
- result = args val
1591
- }
1592
- | f_arg tCOMMA
1593
- {
1594
- result = args(val) << nil
1595
- }
1596
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1597
- {
1598
- result = args val
1599
- }
1600
- | f_arg opt_block_args_tail
1601
- {
1602
- result = args val
1603
- }
1604
- | f_block_optarg tCOMMA f_rest_arg opt_block_args_tail
1605
- {
1606
- result = args val
1607
- }
1608
- | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_block_args_tail
1609
- {
1610
- result = args val
1611
- }
1612
- | f_block_optarg opt_block_args_tail
1613
- {
1614
- result = args val
1615
- }
1616
- | f_block_optarg tCOMMA f_arg opt_block_args_tail
1617
- {
1618
- result = args val
1619
- }
1620
- | f_rest_arg opt_block_args_tail
1621
- {
1622
- result = args val
1623
- }
1624
- | f_rest_arg tCOMMA f_arg opt_block_args_tail
1625
- {
1626
- result = args val
1627
- }
1628
- | block_args_tail
1629
- {
1630
- result = args val
1631
- }
1632
-
1633
- opt_block_param: none { result = 0 }
1634
- | block_param_def
1635
- {
1636
- self.lexer.command_start = true
1637
- }
1638
-
1639
- block_param_def: tPIPE opt_bv_decl tPIPE
1640
- {
1641
- # TODO: current_arg = 0
1642
- result = args val
1643
- }
1644
- | tOROP
1645
- {
1646
- result = s(:args).line lexer.lineno
1647
- }
1648
- | tPIPE block_param opt_bv_decl tPIPE
1649
- {
1650
- # TODO: current_arg = 0
1651
- result = args val
1652
- }
1653
-
1654
- opt_bv_decl: opt_nl
1655
- | opt_nl tSEMI bv_decls opt_nl
1656
- {
1657
- result = args val
1658
- }
1659
-
1660
- bv_decls: bvar
1661
- {
1662
- result = args val
1663
- }
1664
- | bv_decls tCOMMA bvar
1665
- {
1666
- result = args val
1667
- }
1668
-
1669
- bvar: tIDENTIFIER
1670
- {
1671
- result = wrap :shadow, val[0]
1672
- }
1673
- | f_bad_arg
1674
-
1675
- lambda: tLAMBDA
1676
- {
1677
- self.env.extend :dynamic
1678
- result = [lexer.lineno, lexer.lpar_beg]
1679
- lexer.paren_nest += 1
1680
- lexer.lpar_beg = lexer.paren_nest
1681
- }
1682
- f_larglist
1683
- {
1684
- lexer.cmdarg.push false
1685
- }
1686
- lambda_body
1687
- {
1688
- _, (line, lpar), args, _cmdarg, body = val
1689
- lexer.lpar_beg = lpar
1690
-
1691
- lexer.cmdarg.pop
1692
-
1693
- call = s(:lambda).line line
1694
- result = new_iter call, args, body
1695
- result.line line
1696
- self.env.unextend # TODO: dynapush & dynapop
1697
- }
1698
-
1699
- f_larglist: tLPAREN2 f_args opt_bv_decl rparen
1700
- {
1701
- result = args val
1702
- }
1703
- | f_args
1704
- {
1705
- result = val[0]
1706
- result = 0 if result == s(:args)
1707
- }
1708
-
1709
- lambda_body: tLAMBEG compstmt tRCURLY
1710
- {
1711
- result = val[1]
1712
- }
1713
- | kDO_LAMBDA bodystmt kEND
1714
- {
1715
- result = val[1]
1716
- }
1717
-
1718
- do_block: k_do_block do_body kEND
1719
- {
1720
- (_, line), iter, _ = val
1721
- result = iter.line line
1722
- }
1723
-
1724
- block_call: command do_block
1725
- {
1726
- # TODO:
1727
- ## if (nd_type($1) == NODE_YIELD) {
1728
- ## compile_error(PARSER_ARG "block given to yield");
1729
-
1730
- cmd, blk = val
1731
-
1732
- syntax_error "Both block arg and actual block given." if
1733
- cmd.block_pass?
1734
-
1735
- if inverted? val then
1736
- val = invert_block_call val
1737
- cmd, blk = val
1738
- end
1739
-
1740
- result = blk
1741
- result.insert 1, cmd
1742
- }
1743
- | block_call call_op2 operation2 opt_paren_args
1744
- {
1745
- lhs, _, (id, _line), args = val
1746
-
1747
- result = new_call lhs, id.to_sym, args
1748
- }
1749
- | block_call call_op2 operation2 opt_paren_args brace_block
1750
- {
1751
- iter1, _, (name, _line), args, iter2 = val
1752
-
1753
- call = new_call iter1, name.to_sym, args
1754
- iter2.insert 1, call
1755
-
1756
- result = iter2
1757
- }
1758
- | block_call call_op2 operation2 command_args do_block
1759
- {
1760
- iter1, _, (name, _line), args, iter2 = val
1761
-
1762
- call = new_call iter1, name.to_sym, args
1763
- iter2.insert 1, call
1764
-
1765
- result = iter2
1766
- }
1767
-
1768
- method_call: fcall paren_args
1769
- {
1770
- call, args = val
1771
-
1772
- result = call
1773
-
1774
- if args then
1775
- call.concat args.sexp_body
1776
- result.line_max = args.line_max
1777
- end
1778
- }
1779
- | primary_value call_op operation2 opt_paren_args
1780
- {
1781
- recv, call_op, (op, op_line), args = val
1782
-
1783
- result = new_call recv, op.to_sym, args, call_op
1784
- result.line_max = op_line unless args
1785
- }
1786
- | primary_value tCOLON2 operation2 paren_args
1787
- {
1788
- recv, _, (op, _line), args = val
1789
-
1790
- result = new_call recv, op.to_sym, args
1791
- }
1792
- | primary_value tCOLON2 operation3
1793
- {
1794
- lhs, _, (id, _line) = val
1795
-
1796
- result = new_call lhs, id.to_sym
1797
- }
1798
- | primary_value call_op paren_args
1799
- {
1800
- result = new_call val[0], :call, val[2], val[1]
1801
- }
1802
- | primary_value tCOLON2 paren_args
1803
- {
1804
- result = new_call val[0], :call, val[2]
1805
- }
1806
- | kSUPER paren_args
1807
- {
1808
- result = new_super val[1]
1809
- }
1810
- | kSUPER
1811
- {
1812
- result = s(:zsuper).line lexer.lineno
1813
- }
1814
- | primary_value tLBRACK2 opt_call_args rbracket
1815
- {
1816
- result = new_aref val
1817
- }
1818
-
1819
- brace_block: tLCURLY
1820
- {
1821
- self.env.extend :dynamic
1822
- result = self.lexer.lineno
1823
- }
1824
- brace_body tRCURLY
1825
- {
1826
- _, line, body, _ = val
1827
-
1828
- result = body
1829
- result.line line
1830
-
1831
- self.env.unextend
1832
- }
1833
- | k_do
1834
- {
1835
- self.env.extend :dynamic
1836
- result = self.lexer.lineno
1837
- }
1838
- do_body kEND
1839
- {
1840
- _, line, body, _ = val
1841
-
1842
- result = body
1843
- result.line line
1844
-
1845
- self.env.unextend
1846
- }
1847
-
1848
- brace_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1849
- { result = lexer.cmdarg.store(false) }
1850
- opt_block_param compstmt
1851
- {
1852
- line, cmdarg, param, cmpstmt = val
1853
-
1854
- result = new_brace_body param, cmpstmt, line
1855
- self.env.unextend
1856
- lexer.cmdarg.restore cmdarg
1857
- lexer.cmdarg.pop # because of: cmdarg_stack >> 1 ?
1858
- }
1859
-
1860
- do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1861
- { lexer.cmdarg.push false }
1862
- opt_block_param
1863
- compstmt
1864
- {
1865
- line, _cmdarg, param, cmpstmt = val
1866
-
1867
- result = new_do_body param, cmpstmt, line
1868
- lexer.cmdarg.pop
1869
- self.env.unextend
1870
- }
1871
-
1872
- case_args: arg_value
1873
- {
1874
- arg, = val
1875
-
1876
- result = s(:array, arg).line arg.line
1877
- }
1878
- | tSTAR arg_value
1879
- {
1880
- _, arg = val
1881
-
1882
- result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1883
- }
1884
- | case_args tCOMMA arg_value
1885
- {
1886
- args, _, id = val
1887
-
1888
- result = self.list_append args, id
1889
- }
1890
- | case_args tCOMMA tSTAR arg_value
1891
- {
1892
- args, _, _, id = val
1893
-
1894
- result = self.list_append args, s(:splat, id).line(id.line)
1895
- }
1896
-
1897
- case_body: k_when
1898
- {
1899
- result = self.lexer.lineno
1900
- }
1901
- case_args then compstmt cases
1902
- {
1903
- result = new_when(val[2], val[4])
1904
- result.line val[1]
1905
- result << val[5] if val[5]
1906
- }
1907
-
1908
- cases: opt_else | case_body
1909
-
1910
- opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
1911
- {
1912
- (_, line), klasses, var, _, body, rest = val
1913
-
1914
- klasses ||= s(:array)
1915
- klasses << new_assign(var, s(:gvar, :"$!").line(var.line)) if var
1916
- klasses.line line
1917
-
1918
- result = new_resbody(klasses, body)
1919
- result << rest if rest # UGH, rewritten above
1920
- }
1921
- |
1922
- {
1923
- result = nil
1924
- }
1925
-
1926
- exc_list: arg_value
1927
- {
1928
- arg, = val
1929
- result = s(:array, arg).line arg.line
1930
- }
1931
- | mrhs
1932
- | none
1933
-
1934
- exc_var: tASSOC lhs
1935
- {
1936
- result = val[1]
1937
- }
1938
- | none
1939
-
1940
- opt_ensure: k_ensure compstmt
1941
- {
1942
- (_, line), body = val
1943
-
1944
- result = body || s(:nil).line(line)
1945
- }
1946
- | none
1947
-
1948
- literal: numeric
1949
- {
1950
- (lit, line), = val
1951
- result = s(:lit, lit).line line
1952
- }
1953
- | symbol
1954
-
1955
- strings: string
1956
- {
1957
- str, = val
1958
- str = s(:dstr, str.value) if str.sexp_type == :evstr
1959
- result = str
1960
- }
1961
-
1962
- string: tCHAR
1963
- {
1964
- debug 37
1965
- }
1966
- | string1
1967
- | string string1
1968
- {
1969
- result = self.literal_concat val[0], val[1]
1970
- }
1971
-
1972
- string1: tSTRING_BEG string_contents tSTRING_END
1973
- {
1974
- (_, line), str, (_, func) = val
1975
-
1976
- str = dedent str if func =~ RubyLexer::STR_FUNC_DEDENT
1977
-
1978
- result = str.line line
1979
- }
1980
- | tSTRING
1981
- {
1982
- result = new_string val
1983
- }
1984
-
1985
- xstring: tXSTRING_BEG xstring_contents tSTRING_END
1986
- {
1987
- result = new_xstring val
1988
- # TODO: dedent?!?! SERIOUSLY?!?
1989
- }
1990
-
1991
- regexp: tREGEXP_BEG regexp_contents tREGEXP_END
1992
- {
1993
- result = new_regexp val
1994
- }
1995
-
1996
- words: tWORDS_BEG tSPACE tSTRING_END
1997
- {
1998
- (_, line), _, (_, line_max) = val
1999
-
2000
- result = s(:array).line line
2001
- result.line_max = line_max
2002
- }
2003
- | tWORDS_BEG word_list tSTRING_END
2004
- {
2005
- (_, line), list, (_, line_max) = val
2006
-
2007
- result = list.line line
2008
- result.line_max = line_max
2009
- }
2010
-
2011
- word_list: none
2012
- {
2013
- result = new_word_list
2014
- }
2015
- | word_list word tSPACE
2016
- {
2017
- result = val[0].dup << new_word_list_entry(val)
2018
- }
2019
-
2020
- word: string_content
2021
- | word string_content
2022
- {
2023
- result = self.literal_concat val[0], val[1]
2024
- }
2025
-
2026
- symbols: tSYMBOLS_BEG tSPACE tSTRING_END
2027
- {
2028
- (_, line), _, (_, line_max) = val
2029
-
2030
- result = s(:array).line line
2031
- result.line_max = line_max
2032
- }
2033
- | tSYMBOLS_BEG symbol_list tSTRING_END
2034
- {
2035
- (_, line), list, (_, line_max), = val
2036
-
2037
- result = list.line line
2038
- result.line_max = line_max
2039
- }
2040
-
2041
- symbol_list: none
2042
- {
2043
- result = new_symbol_list
2044
- }
2045
- | symbol_list word tSPACE
2046
- {
2047
- list, * = val
2048
- result = list.dup << new_symbol_list_entry(val)
2049
- }
2050
-
2051
- qwords: tQWORDS_BEG tSPACE tSTRING_END
2052
- {
2053
- (_, line), _, (_, line_max) = val
2054
-
2055
- result = s(:array).line line
2056
- result.line_max = line_max
2057
- }
2058
- | tQWORDS_BEG qword_list tSTRING_END
2059
- {
2060
- (_, line), list, (_, line_max) = val
2061
-
2062
- result = list.line line
2063
- result.line_max = line_max
2064
- }
2065
-
2066
- qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
2067
- {
2068
- (_, line), _, (_, line_max) = val
2069
-
2070
- result = s(:array).line line
2071
- result.line_max = line_max
2072
- }
2073
- | tQSYMBOLS_BEG qsym_list tSTRING_END
2074
- {
2075
- (_, line), list, (_, line_max) = val
2076
-
2077
- result = list.line line
2078
- result.line_max = line_max
2079
- }
2080
-
2081
- qword_list: none
2082
- {
2083
- result = new_qword_list
2084
- }
2085
- | qword_list tSTRING_CONTENT tSPACE
2086
- {
2087
- result = val[0].dup << new_qword_list_entry(val)
2088
- }
2089
-
2090
- qsym_list: none
2091
- {
2092
- result = new_qsym_list
2093
- }
2094
- | qsym_list tSTRING_CONTENT tSPACE
2095
- {
2096
- result = val[0].dup << new_qsym_list_entry(val)
2097
- }
2098
-
2099
- string_contents: none
2100
- {
2101
- line = prev_value_to_lineno _values.last
2102
- result = s(:str, +"").line line
2103
- }
2104
- | string_contents string_content
2105
- {
2106
- v1, v2 = val
2107
- result = literal_concat v1, v2
2108
- }
2109
-
2110
- xstring_contents: none
2111
- {
2112
- result = nil
2113
- }
2114
- | xstring_contents string_content
2115
- {
2116
- v1, v2 = val
2117
- result = literal_concat v1, v2
2118
- }
2119
-
2120
- regexp_contents: none
2121
- {
2122
- result = nil
2123
- }
2124
- | regexp_contents string_content
2125
- {
2126
- v1, v2 = val
2127
- result = literal_concat v1, v2
2128
- }
2129
-
2130
- string_content: tSTRING_CONTENT
2131
- {
2132
- result = new_string val
2133
- }
2134
- | tSTRING_DVAR
2135
- {
2136
- result = lexer.lex_strterm
2137
-
2138
- lexer.lex_strterm = nil
2139
- lexer.lex_state = EXPR_BEG
2140
- }
2141
- string_dvar
2142
- {
2143
- _, strterm, str = val
2144
- lexer.lex_strterm = strterm
2145
- result = s(:evstr, str).line str.line
2146
- }
2147
- | tSTRING_DBEG
2148
- {
2149
- result = [lexer.lex_strterm,
2150
- lexer.brace_nest,
2151
- lexer.string_nest, # TODO: remove
2152
- lexer.lex_state,
2153
- lexer.lineno,
2154
- ]
2155
-
2156
- lexer.cmdarg.push false
2157
- lexer.cond.push false
2158
-
2159
- lexer.lex_strterm = nil
2160
- lexer.brace_nest = 0
2161
- lexer.string_nest = 0
2162
-
2163
- lexer.lex_state = EXPR_BEG
2164
- }
2165
- compstmt
2166
- tSTRING_DEND
2167
- {
2168
- _, memo, stmt, _ = val
2169
-
2170
- lex_strterm, brace_nest, string_nest, oldlex_state, line = memo
2171
- # TODO: heredoc_indent
2172
-
2173
- lexer.lex_strterm = lex_strterm
2174
- lexer.brace_nest = brace_nest
2175
- lexer.string_nest = string_nest
2176
-
2177
- lexer.cond.pop
2178
- lexer.cmdarg.pop
2179
-
2180
- lexer.lex_state = oldlex_state
2181
-
2182
- case stmt
2183
- when Sexp then
2184
- case stmt.sexp_type
2185
- when :str, :dstr, :evstr then
2186
- result = stmt
2187
- else
2188
- result = s(:evstr, stmt).line line
2189
- end
2190
- when nil then
2191
- result = s(:evstr).line line
2192
- else
2193
- debug 38
2194
- raise "unknown string body: #{stmt.inspect}"
2195
- end
2196
- }
2197
-
2198
- string_dvar: tGVAR
2199
- {
2200
- result = wrap :gvar, val[0]
2201
- }
2202
- | tIVAR
2203
- {
2204
- result = wrap :ivar, val[0]
2205
- }
2206
- | tCVAR
2207
- {
2208
- result = wrap :cvar, val[0]
2209
- }
2210
- | backref
2211
-
2212
- symbol: ssym
2213
- | dsym
2214
-
2215
- ssym: tSYMBEG sym
2216
- {
2217
- lexer.lex_state = EXPR_END
2218
- result = wrap :lit, val[1]
2219
- }
2220
- | tSYMBOL
2221
- {
2222
- lexer.lex_state = EXPR_END
2223
- result = wrap :lit, val[0]
2224
- }
2225
-
2226
- sym: fname | tIVAR | tGVAR | tCVAR
2227
-
2228
- dsym: tSYMBEG string_contents tSTRING_END
2229
- {
2230
- _, result, _ = val
2231
-
2232
- lexer.lex_state = EXPR_END
2233
-
2234
- result ||= s(:str, "").line lexer.lineno
2235
-
2236
- case result.sexp_type
2237
- when :dstr then
2238
- result.sexp_type = :dsym
2239
- when :str then
2240
- result = s(:lit, result.last.to_sym).line result.line
2241
- when :evstr then
2242
- result = s(:dsym, "", result).line result.line
2243
- else
2244
- debug 39
2245
- end
2246
- }
2247
-
2248
- numeric: tINTEGER
2249
- | tFLOAT
2250
- | tUMINUS_NUM tINTEGER =tLOWEST
2251
- {
2252
- _, (num, line) = val
2253
- result = [-num, line]
2254
- }
2255
- | tUMINUS_NUM tFLOAT =tLOWEST
2256
- {
2257
- _, (num, line) = val
2258
- result = [-num, line]
2259
- }
2260
-
2261
- user_variable: tIDENTIFIER
2262
- | tIVAR
2263
- | tGVAR
2264
- | tCONSTANT
2265
- | tCVAR
2266
-
2267
- keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2268
- | kSELF { result = s(:self).line lexer.lineno }
2269
- | kTRUE { result = s(:true).line lexer.lineno }
2270
- | kFALSE { result = s(:false).line lexer.lineno }
2271
- | k__FILE__ { result = s(:str, self.file).line lexer.lineno }
2272
- | k__LINE__ { result = s(:lit, lexer.lineno).line lexer.lineno }
2273
- | k__ENCODING__
2274
- {
2275
- l = lexer.lineno
2276
- result =
2277
- if defined? Encoding then
2278
- s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
2279
- else
2280
- s(:str, "Unsupported!").line l
2281
- end
2282
- }
2283
-
2284
- var_ref: user_variable
2285
- {
2286
- raise "NO: #{val.inspect}" if Sexp === val.first
2287
- (var, line), = val
2288
- result = Sexp === var ? var : self.gettable(var)
2289
- result.line line
2290
- }
2291
- | keyword_variable
2292
- {
2293
- var = val[0]
2294
- result = Sexp === var ? var : self.gettable(var)
2295
- }
2296
-
2297
- var_lhs: user_variable
2298
- {
2299
- result = self.assignable val[0]
2300
- }
2301
- | keyword_variable
2302
- {
2303
- result = self.assignable val[0]
2304
- debug 40
2305
- }
2306
-
2307
- backref: tNTH_REF
2308
- {
2309
- (ref, line), = val
2310
- result = s(:nth_ref, ref).line line
2311
- }
2312
- | tBACK_REF
2313
- {
2314
- (ref, line), = val
2315
- result = s(:back_ref, ref).line line
2316
- }
2317
-
2318
- superclass: tLT
2319
- {
2320
- lexer.lex_state = EXPR_BEG
2321
- lexer.command_start = true
2322
- }
2323
- expr_value term
2324
- {
2325
- result = val[2]
2326
- }
2327
- | none
2328
- {
2329
- result = nil
2330
- }
2331
-
2332
- f_arglist: tLPAREN2 f_args rparen
2333
- {
2334
- result = end_args val
2335
- }
2336
- | {
2337
- result = self.in_kwarg
2338
- self.in_kwarg = true
2339
- self.lexer.lex_state |= EXPR_LABEL
2340
- }
2341
- f_args term
2342
- {
2343
- result = end_args val
2344
- }
2345
-
2346
- args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
2347
- {
2348
- result = args val
2349
- }
2350
- | f_kwarg opt_f_block_arg
2351
- {
2352
- result = args val
2353
- }
2354
- | f_kwrest opt_f_block_arg
2355
- {
2356
- result = args val
2357
- }
2358
- | f_block_arg
2359
-
2360
- opt_args_tail: tCOMMA args_tail
2361
- {
2362
- result = val[1]
2363
- }
2364
- |
2365
- {
2366
- result = nil
2367
- }
2368
-
2369
- f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
2370
- {
2371
- result = args val
2372
- }
2373
- | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2374
- {
2375
- result = args val
2376
- }
2377
- | f_arg tCOMMA f_optarg opt_args_tail
2378
- {
2379
- result = args val
2380
- }
2381
- | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
2382
- {
2383
- result = args val
2384
- }
2385
- | f_arg tCOMMA f_rest_arg opt_args_tail
2386
- {
2387
- result = args val
2388
- }
2389
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2390
- {
2391
- result = args val
2392
- }
2393
- | f_arg opt_args_tail
2394
- {
2395
- result = args val
2396
- }
2397
- | f_optarg tCOMMA f_rest_arg opt_args_tail
2398
- {
2399
- result = args val
2400
- }
2401
- | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2402
- {
2403
- result = args val
2404
- }
2405
- | f_optarg opt_args_tail
2406
- {
2407
- result = args val
2408
- }
2409
- | f_optarg tCOMMA f_arg opt_args_tail
2410
- {
2411
- result = args val
2412
- }
2413
- | f_rest_arg opt_args_tail
2414
- {
2415
- result = args val
2416
- }
2417
- | f_rest_arg tCOMMA f_arg opt_args_tail
2418
- {
2419
- result = args val
2420
- }
2421
- | args_tail
2422
- {
2423
- result = args val
2424
- }
2425
- |
2426
- {
2427
- result = args val
2428
- # result.line lexer.lineno
2429
- }
2430
-
2431
-
2432
- f_bad_arg: tCONSTANT
2433
- {
2434
- yyerror "formal argument cannot be a constant"
2435
- }
2436
- | tIVAR
2437
- {
2438
- yyerror "formal argument cannot be an instance variable"
2439
- }
2440
- | tGVAR
2441
- {
2442
- yyerror "formal argument cannot be a global variable"
2443
- }
2444
- | tCVAR
2445
- {
2446
- yyerror "formal argument cannot be a class variable"
2447
- }
2448
-
2449
- f_norm_arg: f_bad_arg
2450
- | tIDENTIFIER
2451
- {
2452
- (id, line), = val
2453
- identifier = id.to_sym
2454
- self.env[identifier] = :lvar
2455
-
2456
- result = [identifier, line]
2457
- }
2458
-
2459
- f_arg_item: f_norm_arg
2460
- | tLPAREN f_margs rparen
2461
- {
2462
- _, margs, _ = val
2463
-
2464
- result = margs
2465
- }
2466
-
2467
- f_arg: f_arg_item
2468
- {
2469
- result = new_arg val
2470
- }
2471
- | f_arg tCOMMA f_arg_item
2472
- {
2473
- list, _, item = val
2474
-
2475
- if list.sexp_type == :args then
2476
- result = list
2477
- else
2478
- result = s(:args, list).line list.line
2479
- end
2480
-
2481
- if Sexp === item then
2482
- line_max = item.line_max
2483
- else
2484
- item, line_max = item
2485
- end
2486
-
2487
- result << item
2488
- result.line_max = line_max
2489
- }
2490
-
2491
- f_kw: tLABEL arg_value
2492
- {
2493
- # TODO: new_kw_arg
2494
- (label, line), arg = val
2495
-
2496
- identifier = label.to_sym
2497
- self.env[identifier] = :lvar
2498
-
2499
- kwarg = s(:kwarg, identifier, arg).line line
2500
- result = s(:array, kwarg).line line
2501
- }
2502
-
2503
- f_block_kw: tLABEL primary_value
2504
- {
2505
- # TODO: new_kw_arg
2506
- (label, line), expr = val
2507
- id = label.to_sym
2508
- self.env[id] = :lvar
2509
-
2510
- result = s(:array, s(:kwarg, id, expr).line(line)).line line
2511
- }
2512
-
2513
- f_block_kwarg: f_block_kw
2514
- | f_block_kwarg tCOMMA f_block_kw
2515
- {
2516
- list, _, item = val
2517
- result = list << item.last
2518
- }
2519
-
2520
- f_kwarg: f_kw
2521
- | f_kwarg tCOMMA f_kw
2522
- {
2523
- result = args val
2524
- }
2525
-
2526
- kwrest_mark: tPOW
2527
- | tDSTAR
2528
-
2529
-
2530
- f_kwrest: kwrest_mark tIDENTIFIER
2531
- {
2532
- _, (id, line) = val
2533
-
2534
- name = id.to_sym
2535
- self.assignable [name, line]
2536
- result = [:"**#{name}", line]
2537
- }
2538
- | kwrest_mark
2539
- {
2540
- id = :"**"
2541
- self.env[id] = :lvar # TODO: needed?!?
2542
- result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2543
- }
2544
-
2545
- f_opt: tIDENTIFIER tEQL arg_value
2546
- {
2547
- lhs, _, rhs = val
2548
- result = self.assignable lhs, rhs
2549
- # TODO: detect duplicate names
2550
- }
2551
-
2552
- f_block_opt: tIDENTIFIER tEQL primary_value
2553
- {
2554
- lhs, _, rhs = val
2555
- result = self.assignable lhs, rhs
2556
- }
2557
-
2558
- f_block_optarg: f_block_opt
2559
- {
2560
- optblk, = val
2561
- result = s(:block, optblk).line optblk.line
2562
- }
2563
- | f_block_optarg tCOMMA f_block_opt
2564
- {
2565
- optarg, _, optblk = val
2566
- result = optarg
2567
- result << optblk
2568
- }
2569
-
2570
- f_optarg: f_opt
2571
- {
2572
- opt, = val
2573
- result = s(:block, opt).line opt.line
2574
- }
2575
- | f_optarg tCOMMA f_opt
2576
- {
2577
- result = self.block_append val[0], val[2]
2578
- }
2579
-
2580
- restarg_mark: tSTAR2 | tSTAR
2581
-
2582
- f_rest_arg: restarg_mark tIDENTIFIER
2583
- {
2584
- # TODO: differs from parse.y - needs tests
2585
- _, (id, line) = val
2586
- name = id.to_sym
2587
- self.assignable [name, line]
2588
- result = [:"*#{name}", line]
2589
- }
2590
- | restarg_mark
2591
- {
2592
- name = :"*"
2593
- self.env[name] = :lvar
2594
- result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2595
- }
2596
-
2597
- blkarg_mark: tAMPER2 | tAMPER
2598
-
2599
- f_block_arg: blkarg_mark tIDENTIFIER
2600
- {
2601
- _, (id, line) = val
2602
- identifier = id.to_sym
2603
-
2604
- self.env[identifier] = :lvar
2605
- result = ["&#{identifier}".to_sym, line]
2606
- }
2607
-
2608
- opt_f_block_arg: tCOMMA f_block_arg
2609
- {
2610
- _, arg = val
2611
- result = arg
2612
- }
2613
- |
2614
- {
2615
- result = nil
2616
- }
2617
-
2618
- singleton: var_ref
2619
- | tLPAREN2
2620
- {
2621
- lexer.lex_state = EXPR_BEG
2622
- }
2623
- expr rparen
2624
- {
2625
- result = val[2]
2626
- yyerror "Can't define single method for literals." if
2627
- result.sexp_type == :lit
2628
- }
2629
-
2630
- assoc_list: none
2631
- {
2632
- result = s(:array).line lexer.lineno
2633
- }
2634
- | assocs trailer
2635
-
2636
- assocs: assoc
2637
- | assocs tCOMMA assoc
2638
- {
2639
- list = val[0].dup
2640
- more = val[2].sexp_body
2641
- list.push(*more) unless more.empty?
2642
- result = list
2643
- result.sexp_type = :hash
2644
- }
2645
-
2646
- assoc: arg_value tASSOC arg_value
2647
- {
2648
- v1, _, v2 = val
2649
- result = s(:array, v1, v2).line v1.line
2650
- }
2651
- | tLABEL arg_value
2652
- {
2653
- label, arg = val
2654
-
2655
- lit = wrap :lit, label
2656
- result = s(:array, lit, arg).line lit.line
2657
- }
2658
- | tDSTAR arg_value
2659
- {
2660
- _, arg = val
2661
- line = arg.line
2662
- result = s(:array, s(:kwsplat, arg).line(line)).line line
2663
- }
2664
-
2665
- operation: tIDENTIFIER | tCONSTANT | tFID
2666
- operation2: tIDENTIFIER | tCONSTANT | tFID | op
2667
- operation3: tIDENTIFIER | tFID | op
2668
- dot_or_colon: tDOT | tCOLON2
2669
- call_op: tDOT
2670
-
2671
- call_op2: call_op
2672
- | tCOLON2
2673
-
2674
- opt_terms: | terms
2675
- opt_nl: | tNL
2676
- rparen: opt_nl tRPAREN
2677
- {
2678
- _, close = val
2679
- result = [close, lexer.lineno]
2680
- }
2681
- rbracket: opt_nl tRBRACK
2682
- {
2683
- _, close = val
2684
- result = [close, lexer.lineno]
2685
- }
2686
- trailer: | tNL | tCOMMA
2687
-
2688
- term: tSEMI { yyerrok }
2689
- | tNL
2690
-
2691
- terms: term
2692
- | terms tSEMI { yyerrok }
2693
-
2694
- none: { result = nil; }
2695
- end
2696
-
2697
- ---- inner
2698
-
2699
- require "ruby_lexer"
2700
- require "ruby_parser_extras"
2701
- include RubyLexer::State::Values
2702
-
2703
- # :stopdoc:
2704
-
2705
- # Local Variables: **
2706
- # racc-token-length-max:14 **
2707
- # End: **