ruby_parser 3.20.3 → 3.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/ruby23_parser.y DELETED
@@ -1,2737 +0,0 @@
1
- # -*- racc -*-
2
-
3
- class Ruby23Parser
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
-
26
- preclow
27
- nonassoc tLOWEST
28
- nonassoc tLBRACE_ARG
29
- nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
30
- left kOR kAND
31
- right kNOT
32
- nonassoc kDEFINED
33
- right tEQL tOP_ASGN
34
- left kRESCUE_MOD
35
- right tEH tCOLON
36
- nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
37
- left tOROP
38
- left tANDOP
39
- nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
40
- left tGT tGEQ tLT tLEQ
41
- left tPIPE tCARET
42
- left tAMPER2
43
- left tLSHFT tRSHFT
44
- left tPLUS tMINUS
45
- left tSTAR2 tDIVIDE tPERCENT # TODO: tSTAR2 -> tMULT
46
- right tUMINUS_NUM tUMINUS
47
- right tPOW
48
- right tBANG tTILDE tUPLUS
49
- prechigh
50
-
51
- rule
52
-
53
- program: {
54
- self.lexer.lex_state = EXPR_BEG
55
- }
56
- top_compstmt
57
- {
58
- result = new_compstmt val
59
-
60
- lexer.cond.pop # local_pop
61
- lexer.cmdarg.pop
62
- }
63
-
64
- top_compstmt: top_stmts opt_terms
65
- {
66
- stmt, _ = val
67
- result = stmt
68
- }
69
-
70
- top_stmts: none
71
- | top_stmt
72
- | top_stmts terms top_stmt
73
- {
74
- result = self.block_append val[0], val[2]
75
- }
76
- | error top_stmt
77
-
78
- top_stmt: stmt
79
- | klBEGIN
80
- {
81
- if (self.in_def || self.in_single > 0) then
82
- debug 11
83
- yyerror "BEGIN in method"
84
- end
85
- self.env.extend
86
- }
87
- begin_block
88
- {
89
- (_, lineno), _, iter = val
90
- iter.line lineno
91
-
92
- (_, preexe,) = iter
93
- preexe.line lineno
94
-
95
- result = iter
96
- }
97
-
98
- begin_block: tLCURLY { result = lexer.lineno } top_compstmt tRCURLY
99
- {
100
- _, line, stmt, _ = val
101
- result = new_iter s(:preexe).line(line), 0, stmt
102
- }
103
-
104
- bodystmt: compstmt opt_rescue k_else
105
- {
106
- res = _values[-2]
107
- # TODO: move down to main match so I can just use val
108
-
109
- warn "else without rescue is useless" unless res
110
- }
111
- compstmt
112
- opt_ensure
113
- {
114
- body, resc, _, _, els, ens = val
115
-
116
- result = new_body [body, resc, els, ens]
117
- }
118
- | compstmt opt_rescue opt_ensure
119
- {
120
- body, resc, ens = val
121
-
122
- result = new_body [body, resc, nil, ens]
123
- }
124
-
125
- compstmt: stmts opt_terms
126
- {
127
- result = new_compstmt val
128
- }
129
-
130
- stmts: none
131
- | stmt_or_begin # TODO: newline_node ?
132
- | stmts terms stmt_or_begin
133
- {
134
- result = self.block_append val[0], val[2]
135
- }
136
- | error stmt
137
- {
138
- result = val[1]
139
- debug 12
140
- }
141
-
142
- stmt_or_begin: stmt
143
- | klBEGIN
144
- {
145
- yyerror "BEGIN is permitted only at toplevel"
146
- }
147
- begin_block
148
- {
149
- result = val[2] # wtf?
150
- }
151
-
152
- stmt: kALIAS fitem
153
- {
154
- lexer.lex_state = EXPR_FNAME
155
- }
156
- fitem
157
- {
158
- (_, line), lhs, _, rhs = val
159
- result = s(:alias, lhs, rhs).line(line).line line
160
- }
161
- | kALIAS tGVAR tGVAR
162
- {
163
- (_, line), (lhs, _), (rhs, _) = val
164
- result = s(:valias, lhs.to_sym, rhs.to_sym).line line
165
- }
166
- | kALIAS tGVAR tBACK_REF
167
- {
168
- (_, line), (lhs, _), (rhs, _) = val
169
- result = s(:valias, lhs.to_sym, :"$#{rhs}").line line
170
- }
171
- | kALIAS tGVAR tNTH_REF
172
- {
173
- yyerror "can't make alias for the number variables"
174
- }
175
- | kUNDEF undef_list
176
- {
177
- result = val[1]
178
- }
179
- | stmt kIF_MOD expr_value
180
- {
181
- t, _, c = val
182
- result = new_if c, t, nil
183
- }
184
- | stmt kUNLESS_MOD expr_value
185
- {
186
- f, _, c = val
187
- result = new_if c, nil, f
188
- }
189
- | stmt kWHILE_MOD expr_value
190
- {
191
- e, _, c = val
192
- result = new_while e, c, true
193
- }
194
- | stmt kUNTIL_MOD expr_value
195
- {
196
- e, _, c = val
197
- result = new_until e, c, true
198
- }
199
- | stmt kRESCUE_MOD stmt
200
- {
201
- body, _, resbody = val
202
-
203
- resbody = new_resbody s(:array).line(resbody.line), resbody
204
- result = new_rescue body, resbody
205
- }
206
- | klEND tLCURLY compstmt tRCURLY
207
- {
208
- (_, line), _, stmt, _ = val
209
-
210
- if (self.in_def || self.in_single > 0) then
211
- debug 13
212
- yyerror "END in method; use at_exit"
213
- end
214
-
215
- result = new_iter s(:postexe).line(line), 0, stmt
216
- }
217
- | command_asgn
218
- | mlhs tEQL command_call
219
- {
220
- result = new_masgn val[0], val[2], :wrap
221
- }
222
- | lhs tEQL mrhs
223
- {
224
- lhs, _, rhs = val
225
-
226
- result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
227
- }
228
- | mlhs tEQL mrhs_arg
229
- {
230
- result = new_masgn val[0], val[2]
231
- }
232
- | expr
233
-
234
- command_asgn: lhs tEQL command_rhs
235
- {
236
- result = new_assign val[0], val[2]
237
- }
238
- # | lhs tEQL command_asgn
239
- # {
240
- # result = new_assign val[0], val[2]
241
- # }
242
- | var_lhs tOP_ASGN command_rhs
243
- {
244
- result = new_op_asgn val
245
- }
246
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
247
- {
248
- result = new_op_asgn1 val
249
- }
250
- | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
251
- {
252
- prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
253
-
254
- result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
255
- result.sexp_type = :safe_op_asgn if call_op == '&.'
256
- result.line prim.line
257
- }
258
- | primary_value call_op tCONSTANT tOP_ASGN command_rhs
259
- {
260
- prim, (call_op, _), (id, _), (op_asgn, _), rhs = val
261
-
262
- result = s(:op_asgn, prim, rhs, id.to_sym, op_asgn.to_sym)
263
- result.sexp_type = :safe_op_asgn if call_op == '&.'
264
- result.line prim.line
265
- }
266
- | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
267
- {
268
- lhs1, _, (lhs2, line), (id, _), rhs = val
269
-
270
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
271
- }
272
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
273
- {
274
- lhs1, _, (lhs2, line), (id, _), rhs = val
275
-
276
- result = s(:op_asgn, lhs1, rhs, lhs2.to_sym, id.to_sym).line line
277
- }
278
- | backref tOP_ASGN command_rhs
279
- {
280
- self.backref_assign_error val[0]
281
- }
282
-
283
- command_rhs: command_call =tOP_ASGN
284
- {
285
- expr, = val
286
- result = value_expr expr
287
- }
288
- | command_asgn
289
-
290
- expr: command_call
291
- | expr kAND expr
292
- {
293
- lhs, _, rhs = val
294
- result = logical_op :and, lhs, rhs
295
- }
296
- | expr kOR expr
297
- {
298
- lhs, _, rhs = val
299
- result = logical_op :or, lhs, rhs
300
- }
301
- | kNOT opt_nl expr
302
- {
303
- (_, line), _, expr = val
304
- result = new_call(expr, :"!").line line
305
- # REFACTOR: call_uni_op
306
- }
307
- | tBANG command_call
308
- {
309
- _, cmd = val
310
- result = new_call(cmd, :"!").line cmd.line
311
- # TODO: fix line number to tBANG... but causes BAD shift/reduce conflict
312
- # REFACTOR: call_uni_op -- see parse26.y
313
- }
314
- | arg =tLBRACE_ARG
315
-
316
- expr_value: expr
317
- {
318
- result = value_expr(val[0])
319
- }
320
-
321
- expr_value_do: {
322
- lexer.cond.push true
323
- }
324
- expr_value do
325
- {
326
- lexer.cond.pop
327
- }
328
- {
329
- _, expr, _, _ = val
330
- result = expr
331
- }
332
-
333
- command_call: command
334
- | block_command
335
-
336
- block_command: block_call
337
- | block_call call_op2 operation2 command_args
338
- {
339
- blk, _, (msg, _line), args = val
340
- result = new_call(blk, msg.to_sym, args).line blk.line
341
- }
342
-
343
- cmd_brace_block: tLBRACE_ARG
344
- {
345
- # self.env.extend(:dynamic)
346
- result = self.lexer.lineno
347
- }
348
- brace_body tRCURLY
349
- {
350
- _, line, body, _ = val
351
-
352
- result = body
353
- result.line line
354
-
355
- # self.env.unextend
356
- }
357
-
358
- fcall: operation
359
- {
360
- (msg, line), = val
361
- result = new_call(nil, msg.to_sym).line line
362
- }
363
-
364
- command: fcall command_args =tLOWEST
365
- {
366
- call, args = val
367
- result = call.concat args.sexp_body
368
- }
369
- | fcall command_args cmd_brace_block
370
- {
371
- call, args, block = val
372
-
373
- result = call.concat args.sexp_body
374
-
375
- if block then
376
- block_dup_check result, block
377
-
378
- result, operation = block, result
379
- result.insert 1, operation
380
- end
381
- }
382
- | primary_value call_op operation2 command_args =tLOWEST
383
- {
384
- lhs, callop, (op, _), args = val
385
-
386
- result = new_call lhs, op.to_sym, args, callop
387
- result.line lhs.line
388
- }
389
- | primary_value call_op operation2 command_args cmd_brace_block
390
- {
391
- recv, _, (msg, _line), args, block = val
392
- call = new_call recv, msg.to_sym, args, val[1]
393
-
394
- block_dup_check call, block
395
-
396
- block.insert 1, call
397
- result = block
398
- }
399
- | primary_value tCOLON2 operation2 command_args =tLOWEST
400
- {
401
- lhs, _, (id, line), args = val
402
-
403
- result = new_call lhs, id.to_sym, args
404
- result.line line
405
- }
406
- | primary_value tCOLON2 operation2 command_args cmd_brace_block
407
- {
408
- recv, _, (msg, _line), args, block = val
409
- call = new_call recv, msg.to_sym, args
410
-
411
- block_dup_check call, block
412
-
413
- block.insert 1, call
414
- result = block
415
- }
416
- | kSUPER command_args
417
- {
418
- result = new_super val[1]
419
- }
420
- | kYIELD command_args
421
- {
422
- (_, line), args = val
423
- result = new_yield args
424
- result.line line # TODO: push to new_yield
425
- }
426
- | k_return call_args
427
- {
428
- line = val[0].last
429
- result = s(:return, ret_args(val[1])).line(line)
430
- }
431
- | kBREAK call_args
432
- {
433
- (_, line), args = val
434
- result = s(:break, ret_args(args)).line line
435
- }
436
- | kNEXT call_args
437
- {
438
- line = val[0].last
439
- result = s(:next, ret_args(val[1])).line(line)
440
- }
441
-
442
- mlhs: mlhs_basic
443
- | tLPAREN mlhs_inner rparen
444
- {
445
- result = val[1]
446
- }
447
-
448
- mlhs_inner: mlhs_basic
449
- | tLPAREN mlhs_inner rparen
450
- {
451
- _, arg, _ = val
452
- l = arg.line
453
-
454
- result = s(:masgn, s(:array, arg).line(l)).line l
455
- }
456
-
457
- mlhs_basic: mlhs_head
458
- {
459
- head, = val
460
- result = s(:masgn, head).line head.line
461
- }
462
- | mlhs_head mlhs_item
463
- {
464
- lhs, rhs = val
465
- result = s(:masgn, lhs << rhs.compact).line lhs.line
466
- }
467
- | mlhs_head tSTAR mlhs_node
468
- {
469
- head, _, tail = val
470
- head << s(:splat, tail).line(tail.line)
471
- result = s(:masgn, head).line head.line
472
- }
473
- | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
474
- {
475
- ary1, _, splat, _, ary2 = val
476
-
477
- result = list_append ary1, s(:splat, splat).line(splat.line)
478
- result.concat ary2.sexp_body
479
- result = s(:masgn, result).line result.line
480
- }
481
- | mlhs_head tSTAR
482
- {
483
- head, _ = val
484
- l = head.line
485
- result = s(:masgn, head << s(:splat).line(l)).line l
486
- }
487
- | mlhs_head tSTAR tCOMMA mlhs_post
488
- {
489
- head, _, _, post = val
490
- ary = list_append head, s(:splat).line(head.line)
491
- ary.concat post.sexp_body
492
- result = s(:masgn, ary).line ary.line
493
- }
494
- | tSTAR mlhs_node
495
- {
496
- _, node = val
497
- l = node.line
498
- splat = s(:splat, node).line l
499
- ary = s(:array, splat).line l
500
- result = s(:masgn, ary).line l
501
- }
502
- | tSTAR mlhs_node tCOMMA mlhs_post
503
- {
504
- _, node, _, post = val
505
-
506
- splat = s(:splat, node).line node.line
507
- ary = s(:array, splat).line splat.line
508
- ary.concat post.sexp_body
509
- result = s(:masgn, ary).line ary.line
510
- }
511
- | tSTAR
512
- {
513
- l = lexer.lineno
514
- result = s(:masgn, s(:array, s(:splat).line(l)).line(l)).line l
515
- }
516
- | tSTAR tCOMMA mlhs_post
517
- {
518
- _, _, post = val
519
- l = post.line
520
-
521
- splat = s(:splat).line l
522
- ary = s(:array, splat, *post.sexp_body).line l
523
- result = s(:masgn, ary).line l
524
- }
525
-
526
- mlhs_item: mlhs_node
527
- | tLPAREN mlhs_inner rparen
528
- {
529
- result = val[1]
530
- }
531
-
532
- mlhs_head: mlhs_item tCOMMA
533
- {
534
- lhs, _ = val
535
- result = s(:array, lhs).line lhs.line
536
- }
537
- | mlhs_head mlhs_item tCOMMA
538
- {
539
- result = val[0] << val[1].compact
540
- }
541
-
542
- mlhs_post: mlhs_item
543
- {
544
- item, = val
545
- result = s(:array, item).line item.line
546
- }
547
- | mlhs_post tCOMMA mlhs_item
548
- {
549
- result = list_append val[0], val[2]
550
- }
551
-
552
- mlhs_node: user_variable
553
- {
554
- result = self.assignable val[0]
555
- }
556
- | keyword_variable
557
- {
558
- result = self.assignable val[0]
559
- }
560
- | primary_value tLBRACK2 opt_call_args rbracket
561
- {
562
- result = self.aryset val[0], val[2]
563
- }
564
- | primary_value call_op tIDENTIFIER
565
- {
566
- lhs, call_op, (id, _line) = val
567
-
568
- result = new_attrasgn lhs, id, call_op
569
- }
570
- | primary_value tCOLON2 tIDENTIFIER
571
- {
572
- recv, _, (id, _line) = val
573
- result = new_attrasgn recv, id
574
- }
575
- | primary_value call_op tCONSTANT
576
- {
577
- lhs, call_op, (id, _line) = val
578
-
579
- result = new_attrasgn lhs, id, call_op
580
- }
581
- | primary_value tCOLON2 tCONSTANT
582
- {
583
- if (self.in_def || self.in_single > 0) then
584
- debug 14
585
- yyerror "dynamic constant assignment"
586
- end
587
-
588
- expr, _, (id, _line) = val
589
- l = expr.line
590
-
591
- result = s(:const, s(:colon2, expr, id.to_sym).line(l), nil).line l
592
- }
593
- | tCOLON3 tCONSTANT
594
- {
595
- if (self.in_def || self.in_single > 0) then
596
- debug 15
597
- yyerror "dynamic constant assignment"
598
- end
599
-
600
- _, (id, l) = val
601
-
602
- result = s(:const, nil, s(:colon3, id.to_sym).line(l)).line l
603
- }
604
- | backref
605
- {
606
- ref, = val
607
-
608
- self.backref_assign_error ref
609
- }
610
-
611
- lhs: user_variable
612
- {
613
- var, = val
614
-
615
- result = self.assignable var
616
- }
617
- | keyword_variable
618
- {
619
- var, = val
620
-
621
- result = self.assignable var
622
-
623
- debug 16
624
- }
625
- | primary_value tLBRACK2 opt_call_args rbracket
626
- {
627
- lhs, _, args, _ = val
628
-
629
- result = self.aryset lhs, args
630
- }
631
- | primary_value call_op tIDENTIFIER # REFACTOR
632
- {
633
- lhs, op, (id, _line) = val
634
-
635
- result = new_attrasgn lhs, id, op
636
- }
637
- | primary_value tCOLON2 tIDENTIFIER
638
- {
639
- lhs, _, (id, _line) = val
640
-
641
- result = new_attrasgn lhs, id
642
- }
643
- | primary_value call_op tCONSTANT # REFACTOR?
644
- {
645
- lhs, call_op, (id, _line) = val
646
-
647
- result = new_attrasgn lhs, id, call_op
648
- }
649
- | primary_value tCOLON2 tCONSTANT
650
- {
651
- expr, _, (id, _line) = val
652
-
653
- if (self.in_def || self.in_single > 0) then
654
- debug 17
655
- yyerror "dynamic constant assignment"
656
- end
657
-
658
- l = expr.line
659
- result = s(:const, s(:colon2, expr, id.to_sym).line(l)).line l
660
- }
661
- | tCOLON3 tCONSTANT
662
- {
663
- _, (id, l) = val
664
-
665
- if (self.in_def || self.in_single > 0) then
666
- debug 18
667
- yyerror "dynamic constant assignment"
668
- end
669
-
670
- result = s(:const, s(:colon3, id.to_sym).line(l)).line l
671
- }
672
- | backref
673
- {
674
- self.backref_assign_error val[0]
675
- }
676
-
677
- cname: tIDENTIFIER
678
- {
679
- yyerror "class/module name must be CONSTANT"
680
- }
681
- | tCONSTANT
682
-
683
- cpath: tCOLON3 cname
684
- {
685
- result = wrap :colon3, val[1]
686
- }
687
- | cname
688
- {
689
- (id, line), = val
690
- result = [id.to_sym, line] # TODO: sexp?
691
- }
692
- | primary_value tCOLON2 cname
693
- {
694
- pval, _, (name, _line) = val
695
-
696
- result = s(:colon2, pval, name.to_sym)
697
- result.line pval.line
698
- }
699
-
700
- fname: tIDENTIFIER | tCONSTANT | tFID
701
- | op
702
- {
703
- lexer.lex_state = EXPR_END
704
- }
705
-
706
- | reswords
707
-
708
- fitem: fname
709
- {
710
- result = wrap :lit, val[0]
711
- }
712
- | symbol
713
-
714
- undef_list: fitem
715
- {
716
- result = new_undef val[0]
717
- }
718
- |
719
- undef_list tCOMMA
720
- {
721
- lexer.lex_state = EXPR_FNAME
722
- }
723
- fitem
724
- {
725
- result = new_undef val[0], val[3]
726
- }
727
-
728
- op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
729
- | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
730
- | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
731
- | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
732
- | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
733
-
734
- reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
735
- | kALIAS | kAND | kBEGIN | kBREAK | kCASE
736
- | kCLASS | kDEF | kDEFINED | kDO | kELSE
737
- | kELSIF | kEND | kENSURE | kFALSE | kFOR
738
- | kIN | kMODULE | kNEXT | kNIL | kNOT
739
- | kOR | kREDO | kRESCUE | kRETRY | kRETURN
740
- | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
741
- | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
742
- | kUNTIL
743
-
744
- arg: lhs tEQL arg_rhs
745
- {
746
- result = new_assign val[0], val[2]
747
- }
748
- | var_lhs tOP_ASGN arg_rhs
749
- {
750
- result = new_op_asgn val
751
- }
752
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
753
- {
754
- result = new_op_asgn1 val
755
- }
756
- | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
757
- {
758
- result = new_op_asgn2 val
759
- }
760
- | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
761
- {
762
- result = new_op_asgn2 val
763
- }
764
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
765
- {
766
- lhs, _, (id, _line), (op, _), rhs = val
767
-
768
- result = s(:op_asgn, lhs, rhs, id.to_sym, op.to_sym).line lhs.line
769
- }
770
- | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
771
- {
772
- lhs1, _, (lhs2, _line), op, rhs = val
773
-
774
- lhs = s(:colon2, lhs1, lhs2.to_sym).line lhs1.line
775
- result = new_const_op_asgn [lhs, op, rhs]
776
- }
777
- | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
778
- {
779
- _, lhs, op, rhs = val
780
-
781
- lhs = wrap :colon3, lhs
782
- result = new_const_op_asgn [lhs, op, rhs]
783
- }
784
- | backref tOP_ASGN arg_rhs
785
- {
786
- # TODO: lhs = var_field val[0]
787
- asgn = new_op_asgn val
788
- result = self.backref_assign_error asgn
789
- }
790
- | arg tDOT2 arg
791
- {
792
- v1, v2 = val[0], val[2]
793
- if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
794
- result = s(:lit, (v1.last)..(v2.last)).line v1.line
795
- else
796
- result = s(:dot2, v1, v2).line v1.line
797
- end
798
- }
799
- | arg tDOT3 arg
800
- {
801
- v1, v2 = val[0], val[2]
802
- if v1.sexp_type == :lit and v2.sexp_type == :lit and Integer === v1.last and Integer === v2.last then
803
- result = s(:lit, (v1.last)...(v2.last)).line v1.line
804
- else
805
- result = s(:dot3, v1, v2).line v1.line
806
- end
807
- }
808
-
809
-
810
- | arg tPLUS arg
811
- {
812
- result = new_call val[0], :+, argl(val[2])
813
- }
814
- | arg tMINUS arg
815
- {
816
- result = new_call val[0], :-, argl(val[2])
817
- }
818
- | arg tSTAR2 arg # TODO: rename
819
- {
820
- result = new_call val[0], :*, argl(val[2])
821
- }
822
- | arg tDIVIDE arg
823
- {
824
- result = new_call val[0], :"/", argl(val[2])
825
- }
826
- | arg tPERCENT arg
827
- {
828
- result = new_call val[0], :"%", argl(val[2])
829
- }
830
- | arg tPOW arg
831
- {
832
- result = new_call val[0], :**, argl(val[2])
833
- }
834
- | tUMINUS_NUM simple_numeric tPOW arg
835
- {
836
- _, (num, line), _, arg = val
837
- lit = s(:lit, num).line line
838
- result = new_call(new_call(lit, :"**", argl(arg)), :"-@")
839
-
840
- }
841
- | tUPLUS arg
842
- {
843
- result = new_call val[1], :"+@"
844
- }
845
- | tUMINUS arg
846
- {
847
- result = new_call val[1], :"-@"
848
- }
849
- | arg tPIPE arg
850
- {
851
- result = new_call val[0], :"|", argl(val[2])
852
- }
853
- | arg tCARET arg
854
- {
855
- result = new_call val[0], :"^", argl(val[2])
856
- }
857
- | arg tAMPER2 arg
858
- {
859
- result = new_call val[0], :"&", argl(val[2])
860
- }
861
- | arg tCMP arg
862
- {
863
- result = new_call val[0], :"<=>", argl(val[2])
864
- }
865
- | rel_expr =tCMP
866
- | arg tEQ arg
867
- {
868
- result = new_call val[0], :"==", argl(val[2])
869
- }
870
- | arg tEQQ arg
871
- {
872
- result = new_call val[0], :"===", argl(val[2])
873
- }
874
- | arg tNEQ arg
875
- {
876
- result = new_call val[0], :"!=", argl(val[2])
877
- }
878
- | arg tMATCH arg
879
- {
880
- lhs, _, rhs = val
881
- result = new_match lhs, rhs
882
- }
883
- | arg tNMATCH arg
884
- {
885
- lhs, _, rhs = val
886
- result = s(:not, new_match(lhs, rhs)).line lhs.line
887
- }
888
- | tBANG arg
889
- {
890
- _, arg = val
891
- result = new_call arg, :"!"
892
- result.line arg.line
893
- }
894
- | tTILDE arg
895
- {
896
- result = new_call value_expr(val[1]), :"~"
897
- }
898
- | arg tLSHFT arg
899
- {
900
- val[0] = value_expr val[0]
901
- val[2] = value_expr val[2]
902
- result = new_call val[0], :"\<\<", argl(val[2])
903
- }
904
- | arg tRSHFT arg
905
- {
906
- val[0] = value_expr val[0]
907
- val[2] = value_expr val[2]
908
- result = new_call val[0], :">>", argl(val[2])
909
- }
910
- | arg tANDOP arg
911
- {
912
- result = logical_op :and, val[0], val[2]
913
- }
914
- | arg tOROP arg
915
- {
916
- result = logical_op :or, val[0], val[2]
917
- }
918
- | kDEFINED opt_nl arg
919
- {
920
- (_, line), _, arg = val
921
- result = s(:defined, arg).line line
922
- }
923
- | arg tEH arg opt_nl tCOLON arg
924
- {
925
- c, _, t, _, _, f = val
926
- result = s(:if, c, t, f).line c.line
927
- }
928
- | primary
929
-
930
- relop: tGT
931
- | tLT
932
- | tGEQ
933
- | tLEQ
934
-
935
- rel_expr: arg relop arg =tGT
936
- {
937
- lhs, (op, _), rhs = val
938
- result = new_call lhs, op.to_sym, argl(rhs)
939
- }
940
- | rel_expr relop arg =tGT
941
- {
942
- lhs, (op, _), rhs = val
943
- warn "comparison '%s' after comparison", op
944
- result = new_call lhs, op.to_sym, argl(rhs)
945
- }
946
-
947
- arg_value: arg
948
- {
949
- result = value_expr(val[0])
950
- }
951
-
952
- aref_args: none
953
- | args trailer
954
- {
955
- result = args [val[0]]
956
- }
957
- | args tCOMMA assocs trailer
958
- {
959
- result = args [val[0], array_to_hash(val[2])]
960
- }
961
- | assocs trailer
962
- {
963
- result = args [array_to_hash(val[0])]
964
- }
965
-
966
- arg_rhs: arg =tOP_ASGN
967
- | arg kRESCUE_MOD arg
968
- {
969
- body, (_, line), resbody = val
970
- body = value_expr body
971
- resbody = remove_begin resbody
972
-
973
- ary = s(:array).line line
974
- result = new_rescue(body, new_resbody(ary, resbody))
975
- }
976
-
977
- paren_args: tLPAREN2 opt_call_args rparen
978
- {
979
- _, args, (_, line_max) = val
980
-
981
- result = args
982
- result.line_max = line_max if args
983
- }
984
-
985
- opt_paren_args: none
986
- | paren_args
987
-
988
- opt_call_args: none
989
- | call_args
990
- | args tCOMMA
991
- {
992
- result = args val
993
- }
994
- | args tCOMMA assocs tCOMMA
995
- {
996
- result = args [val[0], array_to_hash(val[2])]
997
- }
998
- | assocs tCOMMA
999
- {
1000
- result = args [array_to_hash(val[0])]
1001
- }
1002
-
1003
- call_args: command
1004
- {
1005
- warning "parenthesize argument(s) for future version"
1006
- result = call_args val
1007
- }
1008
- | args opt_block_arg
1009
- {
1010
- result = call_args val
1011
- }
1012
- | assocs opt_block_arg
1013
- {
1014
- result = call_args [array_to_hash(val[0]), val[1]]
1015
- }
1016
- | args tCOMMA assocs opt_block_arg
1017
- {
1018
- result = call_args [val[0], array_to_hash(val[2]), val[3]]
1019
- }
1020
- | block_arg
1021
- {
1022
- result = call_args val
1023
- }
1024
-
1025
- command_args: {
1026
- # parse26.y line 2200
1027
-
1028
- # If call_args starts with a open paren '(' or
1029
- # '[', look-ahead reading of the letters calls
1030
- # CMDARG_PUSH(0), but the push must be done
1031
- # after CMDARG_PUSH(1). So this code makes them
1032
- # consistent by first cancelling the premature
1033
- # CMDARG_PUSH(0), doing CMDARG_PUSH(1), and
1034
- # finally redoing CMDARG_PUSH(0).
1035
-
1036
- result = yychar = self.last_token_type.first
1037
- lookahead = [:tLPAREN, :tLPAREN_ARG, :tLPAREN2, :tLBRACK, :tLBRACK2].include?(yychar)
1038
- lexer.cmdarg.pop if lookahead
1039
- lexer.cmdarg.push true
1040
- lexer.cmdarg.push false if lookahead
1041
- }
1042
- call_args
1043
- {
1044
- yychar, args = val
1045
-
1046
- # call_args can be followed by tLBRACE_ARG (that
1047
- # does CMDARG_PUSH(0) in the lexer) but the push
1048
- # must be done after CMDARG_POP() in the parser.
1049
- # So this code does CMDARG_POP() to pop 0 pushed
1050
- # by tLBRACE_ARG, CMDARG_POP() to pop 1 pushed
1051
- # by command_args, and CMDARG_PUSH(0) to restore
1052
- # back the flag set by tLBRACE_ARG.
1053
-
1054
- lookahead = [:tLBRACE_ARG].include?(yychar)
1055
- lexer.cmdarg.pop if lookahead
1056
- lexer.cmdarg.pop
1057
- lexer.cmdarg.push false if lookahead
1058
- result = args
1059
- }
1060
-
1061
- block_arg: tAMPER arg_value
1062
- {
1063
- _, arg = val
1064
- result = s(:block_pass, arg).line arg.line
1065
- }
1066
-
1067
- opt_block_arg: tCOMMA block_arg
1068
- {
1069
- result = val[1]
1070
- }
1071
- | none
1072
-
1073
- args: arg_value
1074
- {
1075
- arg, = val
1076
- lineno = arg.line || lexer.lineno # HACK
1077
-
1078
- result = s(:array, arg).line lineno
1079
- }
1080
- | tSTAR arg_value
1081
- {
1082
- _, arg = val
1083
- result = s(:array, s(:splat, arg).line(arg.line)).line arg.line
1084
- }
1085
- | args tCOMMA arg_value
1086
- {
1087
- args, _, id = val
1088
- result = self.list_append args, id
1089
- }
1090
- | args tCOMMA tSTAR arg_value
1091
- {
1092
- # TODO: the line number from tSTAR has been dropped
1093
- args, _, _, id = val
1094
- line = lexer.lineno
1095
- result = self.list_append args, s(:splat, id).line(line)
1096
- }
1097
-
1098
- mrhs_arg: mrhs
1099
- {
1100
- result = new_masgn_arg val[0]
1101
- }
1102
- | arg_value
1103
- {
1104
- result = new_masgn_arg val[0], :wrap
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: simple_numeric
2249
- | tUMINUS_NUM simple_numeric =tLOWEST
2250
- {
2251
- _, (num, line) = val
2252
- result = [-num, line]
2253
- }
2254
-
2255
- simple_numeric: tINTEGER
2256
- | tFLOAT
2257
- | tRATIONAL
2258
- | tIMAGINARY
2259
-
2260
- user_variable: tIDENTIFIER
2261
- | tIVAR
2262
- | tGVAR
2263
- | tCONSTANT
2264
- | tCVAR
2265
-
2266
- keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
2267
- | kSELF { result = s(:self).line lexer.lineno }
2268
- | kTRUE { result = s(:true).line lexer.lineno }
2269
- | kFALSE { result = s(:false).line lexer.lineno }
2270
- | k__FILE__ { result = s(:str, self.file).line lexer.lineno }
2271
- | k__LINE__ { result = s(:lit, lexer.lineno).line lexer.lineno }
2272
- | k__ENCODING__
2273
- {
2274
- l = lexer.lineno
2275
- result =
2276
- if defined? Encoding then
2277
- s(:colon2, s(:const, :Encoding).line(l), :UTF_8).line l
2278
- else
2279
- s(:str, "Unsupported!").line l
2280
- end
2281
- }
2282
-
2283
- var_ref: user_variable
2284
- {
2285
- raise "NO: #{val.inspect}" if Sexp === val.first
2286
- (var, line), = val
2287
- result = Sexp === var ? var : self.gettable(var)
2288
- result.line line
2289
- }
2290
- | keyword_variable
2291
- {
2292
- var = val[0]
2293
- result = Sexp === var ? var : self.gettable(var)
2294
- }
2295
-
2296
- var_lhs: user_variable
2297
- {
2298
- result = self.assignable val[0]
2299
- }
2300
- | keyword_variable
2301
- {
2302
- result = self.assignable val[0]
2303
- debug 40
2304
- }
2305
-
2306
- backref: tNTH_REF
2307
- {
2308
- (ref, line), = val
2309
- result = s(:nth_ref, ref).line line
2310
- }
2311
- | tBACK_REF
2312
- {
2313
- (ref, line), = val
2314
- result = s(:back_ref, ref).line line
2315
- }
2316
-
2317
- superclass: tLT
2318
- {
2319
- lexer.lex_state = EXPR_BEG
2320
- lexer.command_start = true
2321
- }
2322
- expr_value term
2323
- {
2324
- result = val[2]
2325
- }
2326
- | none
2327
- {
2328
- result = nil
2329
- }
2330
-
2331
- f_arglist: tLPAREN2 f_args rparen
2332
- {
2333
- result = end_args val
2334
- }
2335
- | {
2336
- result = self.in_kwarg
2337
- self.in_kwarg = true
2338
- self.lexer.lex_state |= EXPR_LABEL
2339
- }
2340
- f_args term
2341
- {
2342
- result = end_args val
2343
- }
2344
-
2345
- args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
2346
- {
2347
- result = args val
2348
- }
2349
- | f_kwarg opt_f_block_arg
2350
- {
2351
- result = args val
2352
- }
2353
- | f_kwrest opt_f_block_arg
2354
- {
2355
- result = args val
2356
- }
2357
- | f_block_arg
2358
-
2359
- opt_args_tail: tCOMMA args_tail
2360
- {
2361
- result = val[1]
2362
- }
2363
- |
2364
- {
2365
- result = nil
2366
- }
2367
-
2368
- f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_args_tail
2369
- {
2370
- result = args val
2371
- }
2372
- | f_arg tCOMMA f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2373
- {
2374
- result = args val
2375
- }
2376
- | f_arg tCOMMA f_optarg opt_args_tail
2377
- {
2378
- result = args val
2379
- }
2380
- | f_arg tCOMMA f_optarg tCOMMA f_arg opt_args_tail
2381
- {
2382
- result = args val
2383
- }
2384
- | f_arg tCOMMA f_rest_arg opt_args_tail
2385
- {
2386
- result = args val
2387
- }
2388
- | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2389
- {
2390
- result = args val
2391
- }
2392
- | f_arg opt_args_tail
2393
- {
2394
- result = args val
2395
- }
2396
- | f_optarg tCOMMA f_rest_arg opt_args_tail
2397
- {
2398
- result = args val
2399
- }
2400
- | f_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_args_tail
2401
- {
2402
- result = args val
2403
- }
2404
- | f_optarg opt_args_tail
2405
- {
2406
- result = args val
2407
- }
2408
- | f_optarg tCOMMA f_arg opt_args_tail
2409
- {
2410
- result = args val
2411
- }
2412
- | f_rest_arg opt_args_tail
2413
- {
2414
- result = args val
2415
- }
2416
- | f_rest_arg tCOMMA f_arg opt_args_tail
2417
- {
2418
- result = args val
2419
- }
2420
- | args_tail
2421
- {
2422
- result = args val
2423
- }
2424
- |
2425
- {
2426
- result = args val
2427
- # result.line lexer.lineno
2428
- }
2429
-
2430
-
2431
- f_bad_arg: tCONSTANT
2432
- {
2433
- yyerror "formal argument cannot be a constant"
2434
- }
2435
- | tIVAR
2436
- {
2437
- yyerror "formal argument cannot be an instance variable"
2438
- }
2439
- | tGVAR
2440
- {
2441
- yyerror "formal argument cannot be a global variable"
2442
- }
2443
- | tCVAR
2444
- {
2445
- yyerror "formal argument cannot be a class variable"
2446
- }
2447
-
2448
- f_norm_arg: f_bad_arg
2449
- | tIDENTIFIER
2450
- {
2451
- (id, line), = val
2452
- identifier = id.to_sym
2453
- self.env[identifier] = :lvar
2454
-
2455
- result = [identifier, line]
2456
- }
2457
-
2458
- f_arg_asgn: f_norm_arg
2459
-
2460
- f_arg_item: f_arg_asgn
2461
- | tLPAREN f_margs rparen
2462
- {
2463
- _, margs, _ = val
2464
-
2465
- result = margs
2466
- }
2467
-
2468
- f_arg: f_arg_item
2469
- {
2470
- result = new_arg val
2471
- }
2472
- | f_arg tCOMMA f_arg_item
2473
- {
2474
- list, _, item = val
2475
-
2476
- if list.sexp_type == :args then
2477
- result = list
2478
- else
2479
- result = s(:args, list).line list.line
2480
- end
2481
-
2482
- if Sexp === item then
2483
- line_max = item.line_max
2484
- else
2485
- item, line_max = item
2486
- end
2487
-
2488
- result << item
2489
- result.line_max = line_max
2490
- }
2491
-
2492
- f_label: tLABEL
2493
-
2494
- f_kw: f_label arg_value
2495
- {
2496
- # TODO: new_kw_arg
2497
- (label, line), arg = val
2498
-
2499
- identifier = label.to_sym
2500
- self.env[identifier] = :lvar
2501
-
2502
- kwarg = s(:kwarg, identifier, arg).line line
2503
- result = s(:array, kwarg).line line
2504
- }
2505
- | f_label
2506
- {
2507
- (label, line), = val
2508
-
2509
- id = label.to_sym
2510
- self.env[id] = :lvar
2511
-
2512
- result = s(:array, s(:kwarg, id).line(line)).line line
2513
- }
2514
-
2515
- f_block_kw: f_label primary_value
2516
- {
2517
- # TODO: new_kw_arg
2518
- (label, line), expr = val
2519
- id = label.to_sym
2520
- self.env[id] = :lvar
2521
-
2522
- result = s(:array, s(:kwarg, id, expr).line(line)).line line
2523
- }
2524
- | f_label
2525
- {
2526
- # TODO: new_kw_arg
2527
- (label, line), = val
2528
- id = label.to_sym
2529
- self.env[id] = :lvar
2530
-
2531
- result = s(:array, s(:kwarg, id).line(line)).line line
2532
- }
2533
-
2534
- f_block_kwarg: f_block_kw
2535
- | f_block_kwarg tCOMMA f_block_kw
2536
- {
2537
- list, _, item = val
2538
- result = list << item.last
2539
- }
2540
-
2541
- f_kwarg: f_kw
2542
- | f_kwarg tCOMMA f_kw
2543
- {
2544
- result = args val
2545
- }
2546
-
2547
- kwrest_mark: tPOW
2548
- | tDSTAR
2549
-
2550
-
2551
- f_kwrest: kwrest_mark tIDENTIFIER
2552
- {
2553
- _, (id, line) = val
2554
-
2555
- name = id.to_sym
2556
- self.assignable [name, line]
2557
- result = [:"**#{name}", line]
2558
- }
2559
- | kwrest_mark
2560
- {
2561
- id = :"**"
2562
- self.env[id] = :lvar # TODO: needed?!?
2563
- result = [id, lexer.lineno] # TODO: tPOW/tDSTAR include lineno
2564
- }
2565
-
2566
- f_opt: f_arg_asgn tEQL arg_value
2567
- {
2568
- lhs, _, rhs = val
2569
- result = self.assignable lhs, rhs
2570
- # TODO: detect duplicate names
2571
- }
2572
-
2573
- f_block_opt: f_arg_asgn tEQL primary_value
2574
- {
2575
- lhs, _, rhs = val
2576
- result = self.assignable lhs, rhs
2577
- }
2578
-
2579
- f_block_optarg: f_block_opt
2580
- {
2581
- optblk, = val
2582
- result = s(:block, optblk).line optblk.line
2583
- }
2584
- | f_block_optarg tCOMMA f_block_opt
2585
- {
2586
- optarg, _, optblk = val
2587
- result = optarg
2588
- result << optblk
2589
- }
2590
-
2591
- f_optarg: f_opt
2592
- {
2593
- opt, = val
2594
- result = s(:block, opt).line opt.line
2595
- }
2596
- | f_optarg tCOMMA f_opt
2597
- {
2598
- result = self.block_append val[0], val[2]
2599
- }
2600
-
2601
- restarg_mark: tSTAR2 | tSTAR
2602
-
2603
- f_rest_arg: restarg_mark tIDENTIFIER
2604
- {
2605
- # TODO: differs from parse.y - needs tests
2606
- _, (id, line) = val
2607
- name = id.to_sym
2608
- self.assignable [name, line]
2609
- result = [:"*#{name}", line]
2610
- }
2611
- | restarg_mark
2612
- {
2613
- name = :"*"
2614
- self.env[name] = :lvar
2615
- result = [name, lexer.lineno] # FIX: tSTAR to include lineno
2616
- }
2617
-
2618
- blkarg_mark: tAMPER2 | tAMPER
2619
-
2620
- f_block_arg: blkarg_mark tIDENTIFIER
2621
- {
2622
- _, (id, line) = val
2623
- identifier = id.to_sym
2624
-
2625
- self.env[identifier] = :lvar
2626
- result = ["&#{identifier}".to_sym, line]
2627
- }
2628
-
2629
- opt_f_block_arg: tCOMMA f_block_arg
2630
- {
2631
- _, arg = val
2632
- result = arg
2633
- }
2634
- |
2635
- {
2636
- result = nil
2637
- }
2638
-
2639
- singleton: var_ref
2640
- | tLPAREN2
2641
- {
2642
- lexer.lex_state = EXPR_BEG
2643
- }
2644
- expr rparen
2645
- {
2646
- result = val[2]
2647
- yyerror "Can't define single method for literals." if
2648
- result.sexp_type == :lit
2649
- }
2650
-
2651
- assoc_list: none
2652
- {
2653
- result = s(:array).line lexer.lineno
2654
- }
2655
- | assocs trailer
2656
-
2657
- assocs: assoc
2658
- | assocs tCOMMA assoc
2659
- {
2660
- list = val[0].dup
2661
- more = val[2].sexp_body
2662
- list.push(*more) unless more.empty?
2663
- result = list
2664
- result.sexp_type = :hash
2665
- }
2666
-
2667
- assoc: arg_value tASSOC arg_value
2668
- {
2669
- v1, _, v2 = val
2670
- result = s(:array, v1, v2).line v1.line
2671
- }
2672
- | tLABEL arg_value
2673
- {
2674
- label, arg = val
2675
-
2676
- lit = wrap :lit, label
2677
- result = s(:array, lit, arg).line lit.line
2678
- }
2679
- | tSTRING_BEG string_contents tLABEL_END arg_value
2680
- {
2681
- (_, line), sym, _, value = val
2682
-
2683
- sym.sexp_type = :dsym
2684
-
2685
- result = s(:array, sym, value).line line
2686
- }
2687
- | tDSTAR arg_value
2688
- {
2689
- _, arg = val
2690
- line = arg.line
2691
- result = s(:array, s(:kwsplat, arg).line(line)).line line
2692
- }
2693
-
2694
- operation: tIDENTIFIER | tCONSTANT | tFID
2695
- operation2: tIDENTIFIER | tCONSTANT | tFID | op
2696
- operation3: tIDENTIFIER | tFID | op
2697
- dot_or_colon: tDOT | tCOLON2
2698
- call_op: tDOT
2699
- | tLONELY # TODO: rename tANDDOT?
2700
-
2701
- call_op2: call_op
2702
- | tCOLON2
2703
-
2704
- opt_terms: | terms
2705
- opt_nl: | tNL
2706
- rparen: opt_nl tRPAREN
2707
- {
2708
- _, close = val
2709
- result = [close, lexer.lineno]
2710
- }
2711
- rbracket: opt_nl tRBRACK
2712
- {
2713
- _, close = val
2714
- result = [close, lexer.lineno]
2715
- }
2716
- trailer: | tNL | tCOMMA
2717
-
2718
- term: tSEMI { yyerrok }
2719
- | tNL
2720
-
2721
- terms: term
2722
- | terms tSEMI { yyerrok }
2723
-
2724
- none: { result = nil; }
2725
- end
2726
-
2727
- ---- inner
2728
-
2729
- require "ruby_lexer"
2730
- require "ruby_parser_extras"
2731
- include RubyLexer::State::Values
2732
-
2733
- # :stopdoc:
2734
-
2735
- # Local Variables: **
2736
- # racc-token-length-max:14 **
2737
- # End: **