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