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