ruby_parser 3.12.0 → 3.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,1908 +0,0 @@
1
- # -*- racc -*-
2
-
3
- class Ruby18Parser
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 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__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tCVAR tNTH_REF
11
- tBACK_REF tSTRING_CONTENT tINTEGER tFLOAT tREGEXP_END tUPLUS
12
- tUMINUS tUMINUS_NUM tPOW tCMP tEQ tEQQ tNEQ tGEQ tLEQ tANDOP
13
- tOROP tMATCH tNMATCH tDOT tDOT2 tDOT3 tAREF tASET tLSHFT tRSHFT
14
- tCOLON2 tCOLON3 tOP_ASGN tASSOC tLPAREN tLPAREN2 tRPAREN tLPAREN_ARG
15
- tLBRACK tLBRACK2 tRBRACK tLBRACE tLBRACE_ARG tSTAR tSTAR2 tAMPER tAMPER2
16
- tTILDE tPERCENT tDIVIDE tPLUS tMINUS tLT tGT tPIPE tBANG tCARET
17
- tLCURLY tRCURLY tBACK_REF2 tSYMBEG tSTRING_BEG tXSTRING_BEG tREGEXP_BEG
18
- tWORDS_BEG tQWORDS_BEG tSTRING_DBEG tSTRING_DVAR tSTRING_END tSTRING
19
- tSYMBOL tNL tEH tCOLON tCOMMA tSPACE tSEMI tLAST_TOKEN
20
-
21
- prechigh
22
- right tBANG tTILDE tUPLUS
23
- right tPOW
24
- right tUMINUS_NUM tUMINUS
25
- left tSTAR2 tDIVIDE tPERCENT
26
- left tPLUS tMINUS
27
- left tLSHFT tRSHFT
28
- left tAMPER2
29
- left tPIPE tCARET
30
- left tGT tGEQ tLT tLEQ
31
- nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
32
- left tANDOP
33
- left tOROP
34
- nonassoc tDOT2 tDOT3
35
- right tEH tCOLON
36
- left kRESCUE_MOD
37
- right tEQL tOP_ASGN
38
- nonassoc kDEFINED
39
- right kNOT
40
- left kOR kAND
41
- nonassoc kIF_MOD kUNLESS_MOD kWHILE_MOD kUNTIL_MOD
42
- nonassoc tLBRACE_ARG
43
- nonassoc tLOWEST
44
- preclow
45
-
46
- rule
47
-
48
- program: {
49
- self.lexer.lex_state = :expr_beg
50
- }
51
- compstmt
52
- {
53
- result = val[1]
54
- }
55
-
56
- bodystmt: compstmt opt_rescue opt_else opt_ensure
57
- {
58
- result = new_body val
59
- }
60
-
61
- compstmt: stmts opt_terms
62
- {
63
- result = new_compstmt val
64
- }
65
-
66
- stmts: none
67
- | stmt
68
- | stmts terms stmt
69
- {
70
- result = block_append val[0], val[2]
71
- }
72
- | error stmt
73
- {
74
- result = val[1]
75
- }
76
-
77
- stmt: kALIAS fitem
78
- {
79
- lexer.lex_state = :expr_fname
80
- result = self.lexer.lineno
81
- }
82
- fitem
83
- {
84
- result = s(:alias, val[1], val[3]).line(val[2])
85
- }
86
- | kALIAS tGVAR tGVAR
87
- {
88
- result = s(:valias, val[1].to_sym, val[2].to_sym)
89
- }
90
- | kALIAS tGVAR tBACK_REF
91
- {
92
- result = s(:valias, val[1].to_sym, :"$#{val[2]}")
93
- }
94
- | kALIAS tGVAR tNTH_REF
95
- {
96
- yyerror "can't make alias for the number variables"
97
- }
98
- | kUNDEF undef_list
99
- {
100
- result = val[1]
101
- }
102
- | stmt kIF_MOD expr_value
103
- {
104
- result = new_if val[2], val[0], nil
105
- }
106
- | stmt kUNLESS_MOD expr_value
107
- {
108
- result = new_if val[2], nil, val[0]
109
- }
110
- | stmt kWHILE_MOD expr_value
111
- {
112
- result = new_while val[0], val[2], true
113
- }
114
- | stmt kUNTIL_MOD expr_value
115
- {
116
- result = new_until val[0], val[2], true
117
- }
118
- | stmt kRESCUE_MOD stmt
119
- {
120
- result = s(:rescue, val[0], new_resbody(s(:array), val[2]))
121
- }
122
- | klBEGIN
123
- {
124
- if (in_def || in_single > 0) then
125
- yyerror "BEGIN in method"
126
- end
127
- self.env.extend
128
- }
129
- tLCURLY compstmt tRCURLY
130
- {
131
- result = new_iter s(:preexe), nil, val[3]
132
- }
133
- | klEND tLCURLY compstmt tRCURLY
134
- {
135
- if (in_def || in_single > 0) then
136
- yyerror "END in method; use at_exit"
137
- end
138
- result = new_iter s(:postexe), 0, val[2]
139
- }
140
- | lhs tEQL command_call
141
- {
142
- result = new_assign val[0], val[2]
143
- }
144
- | mlhs tEQL command_call
145
- {
146
- result = new_masgn val[0], val[2], :wrap
147
- }
148
- | var_lhs tOP_ASGN command_call
149
- {
150
- result = new_op_asgn val
151
- }
152
- | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN command_call
153
- {
154
- result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
155
- }
156
- | primary_value tDOT tIDENTIFIER tOP_ASGN command_call
157
- {
158
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
159
- }
160
- | primary_value tDOT tCONSTANT tOP_ASGN command_call
161
- {
162
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
163
- }
164
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
165
- {
166
- result = s(:op_asgn, val[0], val[4], val[2], val[3])
167
- }
168
- | backref tOP_ASGN command_call
169
- {
170
- backref_assign_error val[0]
171
- }
172
- | lhs tEQL mrhs
173
- {
174
- result = new_assign val[0], s(:svalue, val[2])
175
- }
176
- | mlhs tEQL arg_value
177
- {
178
- result = new_masgn val[0], val[2], :wrap
179
- }
180
- | mlhs tEQL mrhs
181
- {
182
- result = new_masgn val[0], val[2]
183
- }
184
- | expr
185
-
186
- expr: command_call
187
- | expr kAND expr
188
- {
189
- result = logical_op :and, val[0], val[2]
190
- }
191
- | expr kOR expr
192
- {
193
- result = logical_op :or, val[0], val[2]
194
- }
195
- | kNOT expr
196
- {
197
- result = s(:not, val[1])
198
- }
199
- | tBANG command_call
200
- {
201
- result = s(:not, val[1])
202
- }
203
- | arg
204
-
205
- expr_value: expr
206
- {
207
- result = value_expr(val[0])
208
- }
209
-
210
- command_call: command
211
- | block_command
212
- | kRETURN call_args
213
- {
214
- line = val[0].last
215
- result = s(:return, ret_args(val[1])).line(line)
216
- }
217
- | kBREAK call_args
218
- {
219
- line = val[0].last
220
- result = s(:break, ret_args(val[1])).line(line)
221
- }
222
- | kNEXT call_args
223
- {
224
- line = val[0].last
225
- result = s(:next, ret_args(val[1])).line(line)
226
- }
227
-
228
- block_command: block_call
229
- | block_call tDOT operation2 command_args
230
- {
231
- result = new_call val[0], val[2], val[3]
232
- }
233
- | block_call tCOLON2 operation2 command_args
234
- {
235
- result = new_call val[0], val[2], val[3]
236
- }
237
-
238
- cmd_brace_block: tLBRACE_ARG
239
- {
240
- self.env.extend(:dynamic)
241
- result = self.lexer.lineno
242
- }
243
- opt_block_var
244
- {
245
- result = nil # self.env.dynamic.keys
246
- }
247
- compstmt tRCURLY
248
- {
249
- result = new_iter nil, val[2], val[4]
250
- self.env.unextend
251
- }
252
-
253
- command: operation command_args =tLOWEST
254
- {
255
- result = new_call nil, val[0].to_sym, val[1]
256
- }
257
- | operation command_args cmd_brace_block
258
- {
259
- result = new_call nil, val[0].to_sym, val[1]
260
-
261
- if val[2] then
262
- block_dup_check result, val[2]
263
-
264
- result, operation = val[2], result
265
- result.insert 1, operation
266
- end
267
- }
268
- | primary_value tDOT operation2 command_args =tLOWEST
269
- {
270
- result = new_call val[0], val[2].to_sym, val[3]
271
- }
272
- | primary_value tDOT operation2 command_args cmd_brace_block
273
- {
274
- result = new_call val[0], val[2].to_sym, val[3]
275
- raise "no2"
276
-
277
- if val[4] then
278
- block_dup_check result, val[4]
279
-
280
- val[2] << result
281
- result = val[2]
282
- end
283
- }
284
- | primary_value tCOLON2 operation2 command_args =tLOWEST
285
- {
286
- result = new_call val[0], val[2].to_sym, val[3]
287
- }
288
- | primary_value tCOLON2 operation2 command_args cmd_brace_block
289
- {
290
- result = new_call val[0], val[2].to_sym, val[3]
291
- raise "no3"
292
-
293
- if val[4] then
294
- block_dup_check result, val[4]
295
-
296
- val[2] << result
297
- result = val[2]
298
- end
299
- }
300
- | kSUPER command_args
301
- {
302
- result = new_super val[1]
303
- }
304
- | kYIELD command_args
305
- {
306
- result = new_yield val[1]
307
- }
308
-
309
- mlhs: mlhs_basic
310
- | tLPAREN mlhs_entry tRPAREN
311
- {
312
- result = val[1]
313
- }
314
-
315
- mlhs_entry: mlhs_basic
316
- | tLPAREN mlhs_entry tRPAREN
317
- {
318
- result = s(:masgn, s(:array, val[1]))
319
- }
320
-
321
- mlhs_basic: mlhs_head
322
- {
323
- result = s(:masgn, val[0])
324
- }
325
- | mlhs_head mlhs_item
326
- {
327
- result = s(:masgn, val[0] << val[1].compact)
328
- }
329
- | mlhs_head tSTAR mlhs_node
330
- {
331
- result = s(:masgn, val[0] << s(:splat, val[2]))
332
- }
333
- | mlhs_head tSTAR
334
- {
335
- result = s(:masgn, val[0] << s(:splat))
336
- }
337
- | tSTAR mlhs_node
338
- {
339
- result = s(:masgn, s(:array, s(:splat, val[1])))
340
- }
341
- | tSTAR
342
- {
343
- result = s(:masgn, s(:array, s(:splat)))
344
- }
345
-
346
- mlhs_item: mlhs_node
347
- | tLPAREN mlhs_entry tRPAREN
348
- {
349
- result = val[1]
350
- }
351
-
352
- mlhs_head: mlhs_item tCOMMA
353
- {
354
- result = s(:array, val[0])
355
- }
356
- | mlhs_head mlhs_item tCOMMA
357
- {
358
- result = val[0] << val[1].compact
359
- }
360
-
361
- mlhs_node: variable
362
- {
363
- result = assignable val[0]
364
- }
365
- | primary_value tLBRACK2 aref_args tRBRACK
366
- {
367
- result = aryset val[0], val[2]
368
- }
369
- | primary_value tDOT tIDENTIFIER
370
- {
371
- result = s(:attrasgn, val[0], :"#{val[2]}=")
372
- }
373
- | primary_value tCOLON2 tIDENTIFIER
374
- {
375
- result = s(:attrasgn, val[0], :"#{val[2]}=")
376
- }
377
- | primary_value tDOT tCONSTANT
378
- {
379
- result = s(:attrasgn, val[0], :"#{val[2]}=")
380
- }
381
- | primary_value tCOLON2 tCONSTANT
382
- {
383
- if (in_def || in_single > 0) then
384
- yyerror "dynamic constant assignment"
385
- end
386
-
387
- result = s(:const, s(:colon2, val[0], val[2].to_sym), nil)
388
- }
389
- | tCOLON3 tCONSTANT
390
- {
391
- if (in_def || in_single > 0) then
392
- yyerror "dynamic constant assignment"
393
- end
394
-
395
- result = s(:const, nil, s(:colon3, val[1].to_sym))
396
- }
397
- | backref
398
- {
399
- backref_assign_error val[0]
400
- }
401
-
402
- lhs: variable
403
- {
404
- result = assignable val[0]
405
- }
406
- | primary_value tLBRACK2 aref_args tRBRACK
407
- {
408
- result = aryset val[0], val[2]
409
- }
410
- | primary_value tDOT tIDENTIFIER
411
- {
412
- result = s(:attrasgn, val[0], :"#{val[2]}=")
413
- }
414
- | primary_value tCOLON2 tIDENTIFIER
415
- {
416
- result = s(:attrasgn, val[0], :"#{val[2]}=")
417
- }
418
- | primary_value tDOT tCONSTANT
419
- {
420
- result = s(:attrasgn, val[0], :"#{val[2]}=")
421
- }
422
- | primary_value tCOLON2 tCONSTANT
423
- {
424
- if (in_def || in_single > 0) then
425
- yyerror "dynamic constant assignment"
426
- end
427
-
428
- result = s(:const, s(:colon2, val[0], val[2].to_sym))
429
- }
430
- | tCOLON3 tCONSTANT
431
- {
432
- if (in_def || in_single > 0) then
433
- yyerror "dynamic constant assignment"
434
- end
435
-
436
- result = s(:const, s(:colon3, val[1].to_sym))
437
- }
438
- | backref
439
- {
440
- backref_assign_error val[0]
441
- }
442
-
443
- cname: tIDENTIFIER
444
- {
445
- yyerror "class/module name must be CONSTANT"
446
- }
447
- | tCONSTANT
448
-
449
- cpath: tCOLON3 cname
450
- {
451
- result = s(:colon3, val[1].to_sym)
452
- }
453
- | cname
454
- {
455
- result = val[0].to_sym
456
- }
457
- | primary_value tCOLON2 cname
458
- {
459
- result = s(:colon2, val[0], val[2].to_sym)
460
- }
461
-
462
- fname: tIDENTIFIER | tCONSTANT | tFID
463
- | op
464
- {
465
- lexer.lex_state = :expr_end
466
- result = val[0]
467
- }
468
-
469
- | reswords
470
- {
471
- lexer.lex_state = :expr_end
472
- result = val[0]
473
- }
474
-
475
- fsym: fname | symbol
476
-
477
- fitem: fsym { result = s(:lit, val[0].to_sym) }
478
- | dsym
479
-
480
- undef_list: fitem
481
- {
482
- result = new_undef val[0]
483
- }
484
- |
485
- undef_list tCOMMA
486
- {
487
- lexer.lex_state = :expr_fname
488
- }
489
- fitem
490
- {
491
- result = new_undef val[0], val[3]
492
- }
493
-
494
- op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
495
- | tMATCH | tGT | tGEQ | tLT | tLEQ | tLSHFT
496
- | tRSHFT | tPLUS | tMINUS | tSTAR2 | tSTAR | tDIVIDE
497
- | tPERCENT | tPOW | tTILDE | tUPLUS | tUMINUS | tAREF
498
- | tASET | tBACK_REF2
499
-
500
- reswords: k__LINE__ | k__FILE__ | klBEGIN | klEND | kALIAS | kAND
501
- | kBEGIN | kBREAK | kCASE | kCLASS | kDEF | kDEFINED
502
- | kDO | kELSE | kELSIF | kEND | kENSURE | kFALSE
503
- | kFOR | kIN | kMODULE | kNEXT | kNIL | kNOT
504
- | kOR | kREDO | kRESCUE | kRETRY | kRETURN | kSELF
505
- | kSUPER | kTHEN | kTRUE | kUNDEF | kWHEN | kYIELD
506
- | kIF | kUNLESS | kWHILE | kUNTIL
507
-
508
- arg: lhs tEQL arg
509
- {
510
- result = new_assign val[0], val[2]
511
- }
512
- | lhs tEQL arg kRESCUE_MOD arg
513
- {
514
- result = new_assign val[0], s(:rescue, val[2], new_resbody(s(:array), val[4]))
515
- # result.line = val[0].line
516
- }
517
- | var_lhs tOP_ASGN arg
518
- {
519
- result = new_op_asgn val
520
- }
521
- | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN arg
522
- {
523
- result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
524
- val[2].sexp_type = :arglist if val[2]
525
- }
526
- | primary_value tDOT tIDENTIFIER tOP_ASGN arg
527
- {
528
- result = s(:op_asgn2, val[0], :"#{val[2]}=", val[3].to_sym, val[4])
529
- }
530
- | primary_value tDOT tCONSTANT tOP_ASGN arg
531
- {
532
- result = s(:op_asgn2, val[0], :"#{val[2]}=", val[3].to_sym, val[4])
533
- }
534
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
535
- {
536
- result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
537
- }
538
- | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
539
- {
540
- yyerror "constant re-assignment"
541
- }
542
- | tCOLON3 tCONSTANT tOP_ASGN arg
543
- {
544
- yyerror "constant re-assignment"
545
- }
546
- | backref tOP_ASGN arg
547
- {
548
- backref_assign_error val[0]
549
- }
550
- | arg tDOT2 arg
551
- {
552
- v1, v2 = val[0], val[2]
553
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
554
- result = s(:lit, (v1.last)..(v2.last))
555
- else
556
- result = s(:dot2, v1, v2)
557
- end
558
- }
559
- | arg tDOT3 arg
560
- {
561
- v1, v2 = val[0], val[2]
562
- if v1.node_type == :lit and v2.node_type == :lit and Integer === v1.last and Integer === v2.last then
563
- result = s(:lit, (v1.last)...(v2.last))
564
- else
565
- result = s(:dot3, v1, v2)
566
- end
567
- }
568
- | arg tPLUS arg
569
- {
570
- result = new_call val[0], :+, argl(val[2])
571
- }
572
- | arg tMINUS arg
573
- {
574
- result = new_call val[0], :-, argl(val[2])
575
- }
576
- | arg tSTAR2 arg
577
- {
578
- result = new_call val[0], :*, argl(val[2])
579
- }
580
- | arg tDIVIDE arg
581
- {
582
- result = new_call val[0], :"/", argl(val[2])
583
- }
584
- | arg tPERCENT arg
585
- {
586
- result = new_call val[0], :"%", argl(val[2])
587
- }
588
- | arg tPOW arg
589
- {
590
- result = new_call val[0], :**, argl(val[2])
591
- }
592
- | tUMINUS_NUM tINTEGER tPOW arg
593
- {
594
- result = new_call(new_call(s(:lit, val[1]), :"**", argl(val[3])), :"-@")
595
- }
596
- | tUMINUS_NUM tFLOAT tPOW arg
597
- {
598
- result = new_call(new_call(s(:lit, val[1]), :"**", argl(val[3])), :"-@")
599
- }
600
- | tUPLUS arg
601
- {
602
- if val[1].sexp_type == :lit then
603
- result = val[1]
604
- else
605
- result = new_call val[1], :"+@"
606
- end
607
- }
608
- | tUMINUS arg
609
- {
610
- result = new_call val[1], :"-@"
611
- }
612
- | arg tPIPE arg
613
- {
614
- result = new_call val[0], :"|", argl(val[2])
615
- }
616
- | arg tCARET arg
617
- {
618
- result = new_call val[0], :"^", argl(val[2])
619
- }
620
- | arg tAMPER2 arg
621
- {
622
- result = new_call val[0], :"&", argl(val[2])
623
- }
624
- | arg tCMP arg
625
- {
626
- result = new_call val[0], :"<=>", argl(val[2])
627
- }
628
- | arg tGT arg
629
- {
630
- result = new_call val[0], :">", argl(val[2])
631
- }
632
- | arg tGEQ arg
633
- {
634
- result = new_call val[0], :">=", argl(val[2])
635
- }
636
- | arg tLT arg
637
- {
638
- result = new_call val[0], :"<", argl(val[2])
639
- }
640
- | arg tLEQ arg
641
- {
642
- result = new_call val[0], :"<=", argl(val[2])
643
- }
644
- | arg tEQ arg
645
- {
646
- result = new_call val[0], :"==", argl(val[2])
647
- }
648
- | arg tEQQ arg
649
- {
650
- result = new_call val[0], :"===", argl(val[2])
651
- }
652
- | arg tNEQ arg
653
- {
654
- val[0] = value_expr val[0] # TODO: port call_op and clean these
655
- val[2] = value_expr val[2]
656
- result = s(:not, new_call(val[0], :"==", argl(val[2])))
657
- }
658
- | arg tMATCH arg
659
- {
660
- result = new_match val[0], val[2]
661
- }
662
- | arg tNMATCH arg
663
- {
664
- result = s(:not, new_match(val[0], val[2]))
665
- }
666
- | tBANG arg
667
- {
668
- result = s(:not, val[1])
669
- }
670
- | tTILDE arg
671
- {
672
- val[2] = value_expr val[2]
673
- result = new_call val[1], :"~"
674
- }
675
- | arg tLSHFT arg
676
- {
677
- val[0] = value_expr val[0]
678
- val[2] = value_expr val[2]
679
- result = new_call val[0], :"\<\<", argl(val[2])
680
- }
681
- | arg tRSHFT arg
682
- {
683
- val[0] = value_expr val[0]
684
- val[2] = value_expr val[2]
685
- result = new_call val[0], :">>", argl(val[2])
686
- }
687
- | arg tANDOP arg
688
- {
689
- result = logical_op :and, val[0], val[2]
690
- }
691
- | arg tOROP arg
692
- {
693
- result = logical_op :or, val[0], val[2]
694
- }
695
- | kDEFINED opt_nl arg
696
- {
697
- result = s(:defined, val[2])
698
- }
699
- | arg tEH arg tCOLON arg
700
- {
701
- result = s(:if, val[0], val[2], val[4])
702
- }
703
- | primary
704
-
705
- arg_value: arg
706
- {
707
- result = value_expr(val[0])
708
- }
709
-
710
- aref_args: none
711
- | command opt_nl
712
- {
713
- warning 'parenthesize argument(s) for future version'
714
- result = s(:array, val[0])
715
- }
716
- | args trailer
717
- {
718
- result = val[0]
719
- }
720
- | args tCOMMA tSTAR arg opt_nl
721
- {
722
- result = arg_concat val[0], val[3]
723
- }
724
- | assocs trailer
725
- {
726
- result = s(:array, s(:hash, *val[0].values))
727
- }
728
- | tSTAR arg opt_nl
729
- {
730
- result = s(:array, s(:splat, val[1]))
731
- }
732
-
733
- paren_args: tLPAREN2 none tRPAREN
734
- {
735
- result = val[1]
736
- }
737
- | tLPAREN2 call_args opt_nl tRPAREN
738
- {
739
- result = val[1]
740
- }
741
- | tLPAREN2 block_call opt_nl tRPAREN
742
- {
743
- warning "parenthesize argument(s) for future version"
744
- result = s(:array, val[1])
745
- }
746
- | tLPAREN2 args tCOMMA block_call opt_nl tRPAREN
747
- {
748
- warning "parenthesize argument(s) for future version"
749
- result = val[1].add val[3]
750
- }
751
-
752
- opt_paren_args: none
753
- | paren_args
754
-
755
- call_args: command
756
- {
757
- warning "parenthesize argument(s) for future version"
758
- result = s(:array, val[0])
759
- }
760
- | args opt_block_arg
761
- {
762
- result = arg_blk_pass val[0], val[1]
763
- }
764
- | args tCOMMA tSTAR arg_value opt_block_arg
765
- {
766
- result = arg_concat val[0], val[3]
767
- result = arg_blk_pass result, val[4]
768
- }
769
- | assocs opt_block_arg
770
- {
771
- result = s(:array, s(:hash, *val[0].values))
772
- result = arg_blk_pass result, val[1]
773
- }
774
- | assocs tCOMMA tSTAR arg_value opt_block_arg
775
- {
776
- result = arg_concat s(:array, s(:hash, *val[0].values)), val[3]
777
- result = arg_blk_pass result, val[4]
778
- }
779
- | args tCOMMA assocs opt_block_arg
780
- {
781
- result = val[0] << s(:hash, *val[2].values)
782
- result = arg_blk_pass result, val[3]
783
- }
784
- | args tCOMMA assocs tCOMMA tSTAR arg opt_block_arg
785
- {
786
- val[0] << s(:hash, *val[2].values)
787
- result = arg_concat val[0], val[5]
788
- result = arg_blk_pass result, val[6]
789
- }
790
- | tSTAR arg_value opt_block_arg
791
- {
792
- result = arg_blk_pass s(:splat, val[1]), val[2]
793
- }
794
- | block_arg
795
-
796
- call_args2: arg_value tCOMMA args opt_block_arg
797
- {
798
- args = list_prepend val[0], val[2]
799
- result = arg_blk_pass args, val[3]
800
- }
801
- | arg_value tCOMMA block_arg
802
- {
803
- result = arg_blk_pass val[0], val[2]
804
- }
805
- | arg_value tCOMMA tSTAR arg_value opt_block_arg
806
- {
807
- result = arg_concat s(:array, val[0]), val[3]
808
- result = arg_blk_pass result, val[4]
809
- }
810
- | arg_value tCOMMA args tCOMMA tSTAR arg_value opt_block_arg
811
- {
812
- result = arg_concat s(:array, val[0], s(:hash, *val[2].values)), val[5]
813
- result = arg_blk_pass result, val[6]
814
- }
815
- | assocs opt_block_arg
816
- {
817
- result = s(:array, s(:hash, *val[0].values))
818
- result = arg_blk_pass result, val[1]
819
- }
820
- | assocs tCOMMA tSTAR arg_value opt_block_arg
821
- {
822
- result = s(:array, s(:hash, *val[0].values), val[3])
823
- result = arg_blk_pass result, val[4]
824
- }
825
- | arg_value tCOMMA assocs opt_block_arg
826
- {
827
- result = s(:array, val[0], s(:hash, *val[2].values))
828
- result = arg_blk_pass result, val[3]
829
- }
830
- | arg_value tCOMMA args tCOMMA assocs opt_block_arg
831
- {
832
- arg_value, _, args, _, assocs, opt_block = val
833
- result = s(:array, arg_value).add_all(args)
834
- result.add(s(:hash, *assocs.sexp_body))
835
- result = arg_blk_pass result, opt_block
836
- }
837
- | arg_value tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
838
- {
839
- result = arg_concat s(:array, val[0]).add(s(:hash, *val[2].sexp_body)), val[5]
840
- result = arg_blk_pass result, val[6]
841
- }
842
- | arg_value tCOMMA args tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
843
- {
844
- result = arg_concat s(:array, val[0]).add_all(val[2]).add(s(:hash, *val[4].values)), val[7]
845
- result = arg_blk_pass result, val[8]
846
- }
847
- | tSTAR arg_value opt_block_arg
848
- {
849
- result = arg_blk_pass s(:splat, val[1]), val[2]
850
- }
851
- | block_arg
852
-
853
- command_args: {
854
- result = lexer.cmdarg.stack.dup
855
- lexer.cmdarg.push true
856
- }
857
- open_args
858
- {
859
- lexer.cmdarg.stack.replace val[0]
860
- result = val[1]
861
- }
862
-
863
- open_args: call_args
864
- | tLPAREN_ARG
865
- {
866
- lexer.lex_state = :expr_endarg
867
- }
868
- tRPAREN
869
- {
870
- warning "don't put space before argument parentheses"
871
- result = nil
872
- }
873
- | tLPAREN_ARG call_args2
874
- {
875
- lexer.lex_state = :expr_endarg
876
- }
877
- tRPAREN
878
- {
879
- warning "don't put space before argument parentheses"
880
- result = val[1]
881
- }
882
-
883
- block_arg: tAMPER arg_value
884
- {
885
- result = s(:block_pass, val[1])
886
- }
887
-
888
- opt_block_arg: tCOMMA block_arg
889
- {
890
- result = val[1]
891
- }
892
- | none
893
-
894
- args: arg_value
895
- {
896
- result = s(:array, val[0])
897
- }
898
- | args tCOMMA arg_value
899
- {
900
- result = list_append val[0], val[2]
901
- }
902
-
903
- mrhs: args tCOMMA arg_value
904
- {
905
- result = val[0] << val[2]
906
- }
907
- | args tCOMMA tSTAR arg_value
908
- {
909
- result = arg_concat val[0], val[3]
910
- }
911
- | tSTAR arg_value
912
- {
913
- result = s(:splat, val[1])
914
- }
915
-
916
- primary: literal
917
- | strings
918
- | xstring
919
- | regexp
920
- | words
921
- | qwords
922
- | var_ref
923
- | backref
924
- | tFID
925
- {
926
- result = new_call nil, val[0].to_sym
927
- }
928
- | kBEGIN
929
- {
930
- result = self.lexer.lineno
931
- }
932
- bodystmt kEND
933
- {
934
- unless val[2] then
935
- result = s(:nil)
936
- else
937
- result = s(:begin, val[2])
938
- end
939
-
940
- result.line = val[1]
941
- }
942
- | tLPAREN_ARG expr
943
- {
944
- lexer.lex_state = :expr_endarg
945
- }
946
- opt_nl tRPAREN
947
- {
948
- warning "(...) interpreted as grouped expression"
949
- result = val[1]
950
- }
951
- | tLPAREN compstmt tRPAREN
952
- {
953
- result = val[1] || s(:nil)
954
- result.paren = true
955
- }
956
- | primary_value tCOLON2 tCONSTANT
957
- {
958
- result = s(:colon2, val[0], val[2].to_sym)
959
- }
960
- | tCOLON3 tCONSTANT
961
- {
962
- result = s(:colon3, val[1].to_sym)
963
- }
964
- | primary_value tLBRACK2 aref_args tRBRACK
965
- {
966
- result = new_aref val
967
- }
968
- | tLBRACK aref_args tRBRACK
969
- {
970
- result = val[1] || s(:array)
971
- }
972
- | tLBRACE
973
- {
974
- result = self.lexer.lineno
975
- }
976
- assoc_list tRCURLY
977
- {
978
- result = new_hash val
979
- }
980
- | kRETURN
981
- {
982
- result = s(:return)
983
- }
984
- | kYIELD tLPAREN2 call_args tRPAREN
985
- {
986
- result = new_yield val[2]
987
- }
988
- | kYIELD tLPAREN2 tRPAREN
989
- {
990
- result = new_yield
991
- }
992
- | kYIELD
993
- {
994
- result = new_yield
995
- }
996
- | kDEFINED opt_nl tLPAREN2 expr tRPAREN
997
- {
998
- result = s(:defined, val[3])
999
- }
1000
- | operation brace_block
1001
- {
1002
- oper, iter = val[0], val[1]
1003
- call = new_call(nil, oper.to_sym)
1004
- iter.insert 1, call
1005
- result = iter
1006
- call.line = iter.line
1007
- }
1008
- | method_call
1009
- | method_call brace_block
1010
- {
1011
- call, iter = val[0], val[1]
1012
- block_dup_check call, iter
1013
-
1014
- iter.insert 1, call
1015
- result = iter
1016
- }
1017
- | kIF expr_value then compstmt if_tail kEND
1018
- {
1019
- result = new_if val[1], val[3], val[4]
1020
- }
1021
- | kUNLESS expr_value then compstmt opt_else kEND
1022
- {
1023
- result = new_if val[1], val[4], val[3]
1024
- }
1025
- | kWHILE
1026
- {
1027
- lexer.cond.push true
1028
- }
1029
- expr_value do
1030
- {
1031
- lexer.cond.pop
1032
- }
1033
- compstmt kEND
1034
- {
1035
- result = new_while val[5], val[2], true
1036
- }
1037
- | kUNTIL
1038
- {
1039
- lexer.cond.push true
1040
- }
1041
- expr_value do
1042
- {
1043
- lexer.cond.pop
1044
- }
1045
- compstmt kEND
1046
- {
1047
- result = new_until val[5], val[2], true
1048
- }
1049
- | kCASE expr_value opt_terms case_body kEND
1050
- {
1051
- (_, line), expr, _, body, _ = val
1052
- result = new_case expr, body, line
1053
- }
1054
- | kCASE opt_terms case_body kEND
1055
- {
1056
- (_, line), _, body, _ = val
1057
- result = new_case nil, body, line
1058
- }
1059
- | kCASE opt_terms kELSE compstmt kEND # TODO: need a test
1060
- {
1061
- (_, line), _, _, elsebody, _ = val
1062
- result = new_case nil, elsebody, line
1063
- }
1064
- | kFOR for_var kIN
1065
- {
1066
- lexer.cond.push true
1067
- }
1068
- expr_value do
1069
- {
1070
- lexer.cond.pop
1071
- }
1072
- compstmt kEND
1073
- {
1074
- result = new_for val[4], val[1], val[7]
1075
- }
1076
- | kCLASS
1077
- {
1078
- result = self.lexer.lineno
1079
- }
1080
- cpath superclass
1081
- {
1082
- self.comments.push self.lexer.comments
1083
- if (in_def || in_single > 0) then
1084
- yyerror "class definition in method body"
1085
- end
1086
- self.env.extend
1087
- }
1088
- bodystmt kEND
1089
- {
1090
- result = new_class val
1091
- self.env.unextend
1092
- self.lexer.comments # we don't care about comments in the body
1093
- }
1094
- | kCLASS tLSHFT
1095
- {
1096
- result = self.lexer.lineno
1097
- }
1098
- expr
1099
- {
1100
- result = in_def
1101
- self.in_def = false
1102
- }
1103
- term
1104
- {
1105
- result = in_single
1106
- self.in_single = 0
1107
- self.env.extend
1108
- }
1109
- bodystmt kEND
1110
- {
1111
- result = new_sclass val
1112
- self.env.unextend
1113
- self.lexer.comments # we don't care about comments in the body
1114
- }
1115
- | kMODULE
1116
- {
1117
- result = self.lexer.lineno
1118
- }
1119
- cpath
1120
- {
1121
- self.comments.push self.lexer.comments
1122
- yyerror "module definition in method body" if
1123
- in_def or in_single > 0
1124
-
1125
- self.env.extend
1126
- }
1127
- bodystmt kEND
1128
- {
1129
- result = new_module val
1130
- self.env.unextend
1131
- self.lexer.comments # we don't care about comments in the body
1132
- }
1133
- | kDEF fname
1134
- {
1135
- result = self.in_def
1136
-
1137
- self.comments.push self.lexer.comments
1138
- self.in_def = true
1139
- self.env.extend
1140
- }
1141
- f_arglist bodystmt kEND
1142
- {
1143
- in_def = val[2]
1144
-
1145
- result = new_defn val
1146
-
1147
- self.env.unextend
1148
- self.in_def = in_def
1149
- self.lexer.comments # we don't care about comments in the body
1150
- }
1151
- | kDEF singleton dot_or_colon
1152
- {
1153
- self.comments.push self.lexer.comments
1154
- lexer.lex_state = :expr_fname
1155
- }
1156
- fname
1157
- {
1158
- self.in_single += 1
1159
- self.env.extend
1160
- lexer.lex_state = :expr_end # force for args
1161
- result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
1162
- lexer.cmdarg.stack.replace [false]
1163
- }
1164
- f_arglist bodystmt kEND
1165
- {
1166
- line, cmdarg = val[5]
1167
- result = new_defs val
1168
- result[3].line line
1169
-
1170
- lexer.cmdarg.stack.replace cmdarg
1171
- self.env.unextend
1172
- self.in_single -= 1
1173
- self.lexer.comments # we don't care about comments in the body
1174
- }
1175
- | kBREAK
1176
- {
1177
- result = s(:break)
1178
- }
1179
- | kNEXT
1180
- {
1181
- result = s(:next)
1182
- }
1183
- | kREDO
1184
- {
1185
- result = s(:redo)
1186
- }
1187
- | kRETRY
1188
- {
1189
- result = s(:retry)
1190
- }
1191
-
1192
- primary_value: primary
1193
- {
1194
- result = value_expr(val[0])
1195
- }
1196
-
1197
- then: term
1198
- | tCOLON
1199
- | kTHEN
1200
- | term kTHEN
1201
-
1202
- do: term
1203
- | tCOLON
1204
- | kDO_COND
1205
-
1206
- if_tail: opt_else
1207
- | kELSIF expr_value then compstmt if_tail
1208
- {
1209
- result = s(:if, val[1], val[3], val[4])
1210
- }
1211
-
1212
- opt_else: none
1213
- | kELSE compstmt
1214
- {
1215
- result = val[1]
1216
- }
1217
-
1218
- for_var: lhs
1219
- | mlhs
1220
- {
1221
- val[0].delete_at 1 if val[0][1].nil? # HACK
1222
- }
1223
-
1224
- block_par: mlhs_item
1225
- {
1226
- result = s(:array, clean_mlhs(val[0]))
1227
- }
1228
- | block_par tCOMMA mlhs_item
1229
- {
1230
- result = list_append val[0], clean_mlhs(val[2])
1231
- }
1232
-
1233
- block_var: block_par
1234
- {
1235
- result = block_var18 val[0], nil, nil
1236
- }
1237
- | block_par tCOMMA
1238
- {
1239
- result = block_var18 val[0], nil, nil
1240
- }
1241
- | block_par tCOMMA tAMPER lhs
1242
- {
1243
- result = block_var18 val[0], nil, val[3]
1244
- }
1245
- | block_par tCOMMA tSTAR lhs tCOMMA tAMPER lhs
1246
- {
1247
- result = block_var18 val[0], val[3], val[6]
1248
- }
1249
- | block_par tCOMMA tSTAR tCOMMA tAMPER lhs
1250
- {
1251
- result = block_var18 val[0], s(:splat), val[5]
1252
- }
1253
- | block_par tCOMMA tSTAR lhs
1254
- {
1255
- result = block_var18 val[0], val[3], nil
1256
- }
1257
- | block_par tCOMMA tSTAR
1258
- {
1259
- result = block_var18 val[0], s(:splat), nil
1260
- }
1261
- | tSTAR lhs tCOMMA tAMPER lhs
1262
- {
1263
- result = block_var18 nil, val[1], val[4]
1264
- }
1265
- | tSTAR tCOMMA tAMPER lhs
1266
- {
1267
- result = block_var18 nil, s(:splat), val[3]
1268
- }
1269
- | tSTAR lhs
1270
- {
1271
- result = block_var18 nil, val[1], nil
1272
- }
1273
- | tSTAR
1274
- {
1275
- result = block_var18 nil, s(:splat), nil
1276
- }
1277
- | tAMPER lhs
1278
- {
1279
- result = block_var18 nil, nil, val[1]
1280
- }
1281
- ;
1282
-
1283
- opt_block_var: none { result = 0 }
1284
- | tPIPE tPIPE
1285
- {
1286
- result = s(:args)
1287
- self.lexer.command_start = true
1288
- }
1289
- | tOROP
1290
- {
1291
- result = s(:args)
1292
- self.lexer.command_start = true
1293
- }
1294
- | tPIPE block_var tPIPE
1295
- {
1296
- result = val[1]
1297
- self.lexer.command_start = true
1298
- }
1299
-
1300
- do_block: kDO_BLOCK
1301
- {
1302
- self.env.extend :dynamic
1303
- result = self.lexer.lineno
1304
- }
1305
- opt_block_var
1306
- {
1307
- result = nil # self.env.dynamic.keys
1308
- }
1309
- compstmt kEND
1310
- {
1311
- vars = val[2]
1312
- body = val[4]
1313
- result = new_iter nil, vars, body
1314
- result.line = val[1]
1315
-
1316
- self.env.unextend
1317
- }
1318
-
1319
- block_call: command do_block
1320
- {
1321
- block_dup_check val[0], val[1]
1322
-
1323
- result = val[1]
1324
- result.insert 1, val[0]
1325
- }
1326
- | block_call tDOT operation2 opt_paren_args
1327
- {
1328
- result = new_call val[0], val[2], val[3]
1329
- }
1330
- | block_call tCOLON2 operation2 opt_paren_args
1331
- {
1332
- result = new_call val[0], val[2], val[3]
1333
- }
1334
-
1335
- method_call: operation
1336
- {
1337
- result = self.lexer.lineno
1338
- }
1339
- paren_args
1340
- {
1341
- result = new_call nil, val[0].to_sym, val[2]
1342
- }
1343
- | primary_value tDOT operation2 opt_paren_args
1344
- {
1345
- result = new_call val[0], val[2].to_sym, val[3]
1346
- }
1347
- | primary_value tCOLON2 operation2 paren_args
1348
- {
1349
- result = new_call val[0], val[2].to_sym, val[3]
1350
- }
1351
- | primary_value tCOLON2 operation3
1352
- {
1353
- result = new_call val[0], val[2].to_sym
1354
- }
1355
- | kSUPER paren_args
1356
- {
1357
- result = new_super val[1]
1358
- }
1359
- | kSUPER
1360
- {
1361
- result = s(:zsuper)
1362
- }
1363
-
1364
- brace_block: tLCURLY
1365
- {
1366
- self.env.extend :dynamic
1367
- result = self.lexer.lineno
1368
- }
1369
- opt_block_var
1370
- {
1371
- result = nil # self.env.dynamic.keys
1372
- }
1373
- compstmt tRCURLY
1374
- {
1375
- # REFACTOR
1376
- args = val[2]
1377
- body = val[4]
1378
- result = new_iter nil, args, body
1379
- self.env.unextend
1380
- result.line = val[1]
1381
- }
1382
- | kDO
1383
- {
1384
- self.env.extend :dynamic
1385
- result = self.lexer.lineno
1386
- }
1387
- opt_block_var
1388
- {
1389
- result = nil # self.env.dynamic.keys
1390
- }
1391
- compstmt kEND
1392
- {
1393
- args = val[2]
1394
- body = val[4]
1395
- result = new_iter nil, args, body
1396
- self.env.unextend
1397
- result.line = val[1]
1398
- }
1399
-
1400
- case_body: kWHEN
1401
- {
1402
- result = self.lexer.lineno
1403
- }
1404
- when_args then compstmt cases
1405
- {
1406
- result = new_when(val[2], val[4])
1407
- result.line = val[1]
1408
- result << val[5] if val[5]
1409
- }
1410
-
1411
- when_args: args
1412
- | args tCOMMA tSTAR arg_value
1413
- {
1414
- result = list_append val[0], s(:splat, val[3])
1415
- }
1416
- | tSTAR arg_value
1417
- {
1418
- result = s(:array, s(:splat, val[1]))
1419
- }
1420
-
1421
- cases: opt_else | case_body
1422
-
1423
- opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1424
- {
1425
- (_, line), klasses, var, _, body, rest = val
1426
-
1427
- klasses ||= s(:array)
1428
- klasses << new_assign(var, s(:gvar, :"$!")) if var
1429
- klasses.line line
1430
-
1431
- result = new_resbody(klasses, body)
1432
- result << rest if rest # UGH, rewritten above
1433
- }
1434
- |
1435
- {
1436
- result = nil
1437
- }
1438
-
1439
- exc_list: arg_value
1440
- {
1441
- result = s(:array, val[0])
1442
- }
1443
- | mrhs
1444
- | none
1445
-
1446
- exc_var: tASSOC lhs
1447
- {
1448
- result = val[1]
1449
- }
1450
- | none
1451
-
1452
- opt_ensure: kENSURE compstmt
1453
- {
1454
- if (val[1] != nil) then
1455
- result = val[1]
1456
- else
1457
- result = s(:nil)
1458
- end
1459
- }
1460
- | none
1461
-
1462
- literal: numeric { result = s(:lit, val[0]) }
1463
- | symbol { result = s(:lit, val[0]) }
1464
- | dsym
1465
-
1466
- strings: string
1467
- {
1468
- val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
1469
- result = val[0]
1470
- }
1471
-
1472
- string: string1
1473
- | string string1
1474
- {
1475
- result = literal_concat val[0], val[1]
1476
- }
1477
-
1478
- string1: tSTRING_BEG string_contents tSTRING_END
1479
- {
1480
- result = val[1]
1481
- }
1482
- | tSTRING
1483
- {
1484
- result = new_string val
1485
- }
1486
-
1487
- xstring: tXSTRING_BEG xstring_contents tSTRING_END
1488
- {
1489
- result = new_xstring val[1]
1490
- }
1491
-
1492
- regexp: tREGEXP_BEG xstring_contents tREGEXP_END
1493
- {
1494
- result = new_regexp val
1495
- }
1496
-
1497
- words: tWORDS_BEG tSPACE tSTRING_END
1498
- {
1499
- result = s(:array)
1500
- }
1501
- | tWORDS_BEG word_list tSTRING_END
1502
- {
1503
- result = val[1]
1504
- }
1505
-
1506
- word_list: none
1507
- {
1508
- result = new_word_list
1509
- }
1510
- | word_list word tSPACE
1511
- {
1512
- result = val[0] << new_word_list_entry(val)
1513
- }
1514
-
1515
- word: string_content
1516
- | word string_content
1517
- {
1518
- result = literal_concat val[0], val[1]
1519
- }
1520
-
1521
- qwords: tQWORDS_BEG tSPACE tSTRING_END
1522
- {
1523
- result = s(:array)
1524
- }
1525
- | tQWORDS_BEG qword_list tSTRING_END
1526
- {
1527
- result = val[1]
1528
- }
1529
-
1530
- qword_list: none
1531
- {
1532
- result = new_qword_list
1533
- }
1534
- | qword_list tSTRING_CONTENT tSPACE
1535
- {
1536
- result = val[0] << new_qword_list_entry(val)
1537
- }
1538
-
1539
- string_contents: none
1540
- {
1541
- result = s(:str, "")
1542
- }
1543
- | string_contents string_content
1544
- {
1545
- result = literal_concat(val[0], val[1])
1546
- }
1547
-
1548
- xstring_contents: none
1549
- {
1550
- result = nil
1551
- }
1552
- | xstring_contents string_content
1553
- {
1554
- result = literal_concat(val[0], val[1])
1555
- }
1556
-
1557
- string_content: tSTRING_CONTENT
1558
- {
1559
- result = new_string val
1560
- }
1561
- | tSTRING_DVAR
1562
- {
1563
- result = lexer.lex_strterm
1564
-
1565
- lexer.lex_strterm = nil
1566
- lexer.lex_state = :expr_beg
1567
- }
1568
- string_dvar
1569
- {
1570
- lexer.lex_strterm = val[1]
1571
- result = s(:evstr, val[2])
1572
- }
1573
- | tSTRING_DBEG
1574
- {
1575
- result = [lexer.lex_strterm,
1576
- lexer.brace_nest,
1577
- lexer.string_nest, # TODO: remove
1578
- lexer.cond.store,
1579
- lexer.cmdarg.store]
1580
-
1581
- lexer.lex_strterm = nil
1582
- lexer.brace_nest = 0
1583
- lexer.string_nest = 0
1584
-
1585
- lexer.lex_state = :expr_beg
1586
- }
1587
- compstmt tRCURLY
1588
- {
1589
- _, memo, stmt, _ = val
1590
-
1591
- lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg = memo
1592
-
1593
- lexer.lex_strterm = lex_strterm
1594
- lexer.brace_nest = brace_nest
1595
- lexer.string_nest = string_nest
1596
-
1597
- lexer.cond.restore oldcond
1598
- lexer.cmdarg.restore oldcmdarg
1599
-
1600
- case stmt
1601
- when Sexp then
1602
- case stmt.sexp_type
1603
- when :str, :dstr, :evstr then
1604
- result = stmt
1605
- else
1606
- result = s(:evstr, stmt)
1607
- end
1608
- when nil then
1609
- result = s(:evstr)
1610
- else
1611
- raise "unknown string body: #{stmt.inspect}"
1612
- end
1613
- }
1614
-
1615
- string_dvar: tGVAR { result = s(:gvar, val[0].to_sym) }
1616
- | tIVAR { result = s(:ivar, val[0].to_sym) }
1617
- | tCVAR { result = s(:cvar, val[0].to_sym) }
1618
- | backref
1619
-
1620
- symbol: tSYMBEG sym
1621
- {
1622
- lexer.lex_state = :expr_end
1623
- result = val[1].to_sym
1624
- }
1625
- | tSYMBOL
1626
- {
1627
- result = val[0].to_sym
1628
- }
1629
-
1630
- sym: fname | tIVAR | tGVAR | tCVAR
1631
-
1632
- dsym: tSYMBEG xstring_contents tSTRING_END
1633
- {
1634
- lexer.lex_state = :expr_end
1635
- result = val[1]
1636
-
1637
- yyerror "empty symbol literal" if
1638
- result.nil? or result.empty?
1639
-
1640
- case result.sexp_type
1641
- when :dstr then
1642
- result.sexp_type = :dsym
1643
- when :str then
1644
- result = s(:lit, result.last.to_sym)
1645
- else
1646
- result = s(:dsym, "", result)
1647
- end
1648
- }
1649
-
1650
- numeric: tINTEGER
1651
- | tFLOAT
1652
- | tUMINUS_NUM tINTEGER =tLOWEST
1653
- {
1654
- result = -val[1] # TODO: pt_testcase
1655
- }
1656
- | tUMINUS_NUM tFLOAT =tLOWEST
1657
- {
1658
- result = -val[1] # TODO: pt_testcase
1659
- }
1660
-
1661
- variable: tIDENTIFIER
1662
- | tIVAR
1663
- | tGVAR
1664
- | tCONSTANT
1665
- | tCVAR
1666
- | kNIL { result = s(:nil) }
1667
- | kSELF { result = s(:self) }
1668
- | kTRUE { result = s(:true) }
1669
- | kFALSE { result = s(:false) }
1670
- | k__FILE__ { result = s(:str, self.file) }
1671
- | k__LINE__ { result = s(:lit, lexer.lineno) }
1672
-
1673
- var_ref: variable
1674
- {
1675
- var = val[0]
1676
- result = Sexp === var ? var : self.gettable(var)
1677
- }
1678
-
1679
- var_lhs: variable
1680
- {
1681
- result = assignable val[0]
1682
- }
1683
-
1684
- backref: tNTH_REF { result = s(:nth_ref, val[0]) }
1685
- | tBACK_REF { result = s(:back_ref, val[0]) }
1686
-
1687
- superclass: term
1688
- {
1689
- result = nil
1690
- }
1691
- | tLT
1692
- {
1693
- lexer.lex_state = :expr_beg
1694
- }
1695
- expr_value term
1696
- {
1697
- result = val[2]
1698
- }
1699
- | error term
1700
- {
1701
- yyerrok
1702
- result = nil
1703
- }
1704
-
1705
- f_arglist: tLPAREN2 f_args opt_nl tRPAREN
1706
- {
1707
- result = val[1]
1708
- lexer.lex_state = :expr_beg
1709
- self.lexer.command_start = true
1710
- }
1711
- | f_args term
1712
- {
1713
- result = val[0]
1714
- }
1715
-
1716
- f_args: f_arg tCOMMA f_optarg tCOMMA f_rest_arg opt_f_block_arg
1717
- {
1718
- result = args val
1719
- }
1720
- | f_arg tCOMMA f_optarg opt_f_block_arg
1721
- {
1722
- result = args val
1723
- }
1724
- | f_arg tCOMMA f_rest_arg opt_f_block_arg
1725
- {
1726
- result = args val
1727
- }
1728
- | f_arg opt_f_block_arg
1729
- {
1730
- result = args val
1731
- }
1732
- | f_optarg tCOMMA f_rest_arg opt_f_block_arg
1733
- {
1734
- result = args val
1735
- }
1736
- | f_optarg opt_f_block_arg
1737
- {
1738
- result = args val
1739
- }
1740
- | f_rest_arg opt_f_block_arg
1741
- {
1742
- result = args val
1743
- }
1744
- | f_block_arg
1745
- {
1746
- result = args val
1747
- }
1748
- |
1749
- {
1750
- result = args val
1751
- }
1752
-
1753
- f_norm_arg: tCONSTANT
1754
- {
1755
- yyerror "formal argument cannot be a constant"
1756
- }
1757
- | tIVAR
1758
- {
1759
- yyerror "formal argument cannot be an instance variable"
1760
- }
1761
- | tGVAR
1762
- {
1763
- yyerror "formal argument cannot be a global variable"
1764
- }
1765
- | tCVAR
1766
- {
1767
- yyerror "formal argument cannot be a class variable"
1768
- }
1769
- | tIDENTIFIER
1770
- {
1771
- identifier = val[0].to_sym
1772
- self.env[identifier] = :lvar
1773
-
1774
- result = val[0]
1775
- }
1776
-
1777
- f_arg: f_norm_arg
1778
- {
1779
- result = s(:args)
1780
- result << val[0].to_sym
1781
- }
1782
- | f_arg tCOMMA f_norm_arg
1783
- {
1784
- val[0] << val[2].to_sym
1785
- result = val[0]
1786
- }
1787
-
1788
- f_opt: tIDENTIFIER tEQL arg_value
1789
- {
1790
- result = assignable val[0], val[2]
1791
- # TODO: detect duplicate names
1792
- }
1793
-
1794
- f_optarg: f_opt
1795
- {
1796
- result = s(:block, val[0])
1797
- }
1798
- | f_optarg tCOMMA f_opt
1799
- {
1800
- result = block_append val[0], val[2]
1801
- }
1802
-
1803
- restarg_mark: tSTAR2 | tSTAR
1804
-
1805
- f_rest_arg: restarg_mark tIDENTIFIER
1806
- {
1807
- # TODO: differs from parse.y - needs tests
1808
- name = val[1].to_sym
1809
- assignable name
1810
- result = :"*#{name}"
1811
- }
1812
- | restarg_mark
1813
- {
1814
- name = :"*"
1815
- self.env[name] = :lvar
1816
- result = name
1817
- }
1818
-
1819
- blkarg_mark: tAMPER2 | tAMPER
1820
-
1821
- f_block_arg: blkarg_mark tIDENTIFIER
1822
- {
1823
- identifier = val[1].to_sym
1824
-
1825
- self.env[identifier] = :lvar
1826
- result = s(:block_arg, identifier.to_sym)
1827
- }
1828
-
1829
- opt_f_block_arg: tCOMMA f_block_arg
1830
- {
1831
- result = val[1]
1832
- }
1833
- |
1834
- {
1835
- result = nil
1836
- }
1837
-
1838
- singleton: var_ref
1839
- | tLPAREN2
1840
- {
1841
- lexer.lex_state = :expr_beg
1842
- }
1843
- expr opt_nl tRPAREN
1844
- {
1845
- result = val[2]
1846
- yyerror "Can't define single method for literals." if
1847
- result.sexp_type == :lit
1848
- }
1849
-
1850
- assoc_list: none # [!nil]
1851
- {
1852
- result = s(:array)
1853
- }
1854
- | assocs trailer # [!nil]
1855
- {
1856
- result = val[0]
1857
- }
1858
- | args trailer
1859
- {
1860
- size = val[0].size
1861
- if (size % 2 != 1) then # != 1 because of leading :array
1862
- yyerror "Odd number (#{size}) list for Hash. #{val[0].inspect}"
1863
- end
1864
- result = val[0]
1865
- }
1866
-
1867
- assocs: assoc
1868
- | assocs tCOMMA assoc
1869
- {
1870
- list = val[0].dup
1871
- more = val[2].sexp_body
1872
- list.push(*more) unless more.empty?
1873
- result = list
1874
- }
1875
-
1876
- assoc: arg_value tASSOC arg_value
1877
- {
1878
- result = s(:array, val[0], val[2])
1879
- }
1880
-
1881
- operation: tIDENTIFIER | tCONSTANT | tFID
1882
- operation2: tIDENTIFIER | tCONSTANT | tFID | op
1883
- operation3: tIDENTIFIER | tFID | op
1884
- dot_or_colon: tDOT | tCOLON2
1885
- opt_terms: | terms
1886
- opt_nl: | tNL
1887
- trailer: | tNL | tCOMMA
1888
-
1889
- term: tSEMI { yyerrok }
1890
- | tNL
1891
-
1892
- terms: term
1893
- | terms tSEMI { yyerrok }
1894
-
1895
- none: { result = nil }
1896
-
1897
- end
1898
-
1899
- ---- inner
1900
-
1901
- require "ruby_lexer"
1902
- require "ruby_parser_extras"
1903
-
1904
- # :stopdoc:
1905
-
1906
- # Local Variables: **
1907
- # racc-token-length-max:14 **
1908
- # End: **