ruby_parser 3.20.3 → 3.21.0

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