ruby_parser 3.0.0.a2 → 3.0.0.a3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ruby_parser might be problematic. Click here for more details.

@@ -7,16 +7,18 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
7
7
  kREDO kRETRY kIN kDO kDO_COND kDO_BLOCK kDO_LAMBDA kRETURN kYIELD kSUPER
8
8
  kSELF kNIL kTRUE kFALSE kAND kOR kNOT kIF_MOD kUNLESS_MOD kWHILE_MOD
9
9
  kUNTIL_MOD kRESCUE_MOD kALIAS kDEFINED klBEGIN klEND k__LINE__
10
- k__FILE__ tIDENTIFIER tFID tGVAR tIVAR tCONSTANT tLABEL 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 tLAMBDA tLAMBEG
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 tLAST_TOKEN
21
+ tLAMBDA tLAMBEG
20
22
 
21
23
  prechigh
22
24
  right tBANG tTILDE tUPLUS
@@ -48,9 +50,36 @@ rule
48
50
  program: {
49
51
  self.lexer.lex_state = :expr_beg
50
52
  }
51
- compstmt
53
+ top_compstmt
52
54
  {
53
- result = val[1]
55
+ result = new_compstmt val
56
+ }
57
+
58
+ top_compstmt: top_stmts opt_terms
59
+ {
60
+ result = val[0]
61
+ }
62
+
63
+ top_stmts: none
64
+ | top_stmt
65
+ | top_stmts terms top_stmt
66
+ {
67
+ result = self.block_append val[0], val[2]
68
+ }
69
+ | error top_stmt
70
+
71
+ top_stmt: stmt
72
+ | klBEGIN
73
+ {
74
+ if (self.in_def || self.in_single > 0) then
75
+ yyerror "BEGIN in method"
76
+ end
77
+ self.env.extend
78
+ }
79
+ tLCURLY top_compstmt tRCURLY
80
+ {
81
+ result = new_iter s(:preexe), nil, val[3] # TODO: add test?
82
+ result = nil # TODO: since it isn't supposed to go in the AST
54
83
  }
55
84
 
56
85
  bodystmt: compstmt opt_rescue opt_else opt_ensure
@@ -119,18 +148,6 @@ rule
119
148
  {
120
149
  result = s(:rescue, val[0], new_resbody(s(:array), val[2]))
121
150
  }
122
- | klBEGIN
123
- {
124
- if (self.in_def || self.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] # TODO: add test?
132
- result = nil # TODO: since it isn't supposed to go in the AST
133
- }
134
151
  | klEND tLCURLY compstmt tRCURLY
135
152
  {
136
153
  if (self.in_def || self.in_single > 0) then
@@ -138,10 +155,7 @@ rule
138
155
  end
139
156
  result = new_iter s(:postexe), nil, val[2]
140
157
  }
141
- | lhs tEQL command_call
142
- {
143
- result = self.node_assign val[0], val[2]
144
- }
158
+ | command_asgn
145
159
  | mlhs tEQL command_call
146
160
  {
147
161
  result = new_masgn val[0], val[2], :wrap
@@ -150,7 +164,7 @@ rule
150
164
  {
151
165
  result = new_op_asgn val
152
166
  }
153
- | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN command_call
167
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_call
154
168
  {
155
169
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
156
170
  }
@@ -162,6 +176,10 @@ rule
162
176
  {
163
177
  result = s(:op_asgn, val[0], val[4], val[2], val[3])
164
178
  }
179
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
180
+ {
181
+ result = s(:op_asgn, val[0], val[4], val[2], val[3])
182
+ }
165
183
  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
166
184
  {
167
185
  result = s(:op_asgn, val[0], val[4], val[2], val[3])
@@ -184,6 +202,15 @@ rule
184
202
  }
185
203
  | expr
186
204
 
205
+ command_asgn: lhs tEQL command_call
206
+ {
207
+ result = self.node_assign val[0], val[2]
208
+ }
209
+ | lhs tEQL command_asgn
210
+ {
211
+ result = self.node_assign val[0], val[2]
212
+ }
213
+
187
214
  expr: command_call
188
215
  | expr kAND expr
189
216
  {
@@ -193,13 +220,13 @@ rule
193
220
  {
194
221
  result = logop(:or, val[0], val[2])
195
222
  }
196
- | kNOT expr
223
+ | kNOT opt_nl expr
197
224
  {
198
- result = s(:not, val[1])
225
+ result = s(:call, val[2], :"!")
199
226
  }
200
227
  | tBANG command_call
201
228
  {
202
- result = s(:not, val[1])
229
+ result = s(:call, val[1], :"!")
203
230
  }
204
231
  | arg
205
232
 
@@ -210,21 +237,6 @@ rule
210
237
 
211
238
  command_call: command
212
239
  | block_command
213
- | kRETURN call_args
214
- {
215
- line = val[0].last
216
- result = s(:return, ret_args(val[1])).line(line)
217
- }
218
- | kBREAK call_args
219
- {
220
- line = val[0].last
221
- result = s(:break, ret_args(val[1])).line(line)
222
- }
223
- | kNEXT call_args
224
- {
225
- line = val[0].last
226
- result = s(:next, ret_args(val[1])).line(line)
227
- }
228
240
 
229
241
  block_command: block_call
230
242
  | block_call tDOT operation2 command_args
@@ -241,7 +253,7 @@ rule
241
253
  self.env.extend(:dynamic)
242
254
  result = self.lexer.lineno
243
255
  }
244
- opt_block_var
256
+ opt_block_param
245
257
  {
246
258
  result = self.env.dynamic.keys
247
259
  }
@@ -297,15 +309,30 @@ rule
297
309
  {
298
310
  result = new_yield val[1]
299
311
  }
312
+ | kRETURN call_args
313
+ {
314
+ line = val[0].last
315
+ result = s(:return, ret_args(val[1])).line(line)
316
+ }
317
+ | kBREAK call_args
318
+ {
319
+ line = val[0].last
320
+ result = s(:break, ret_args(val[1])).line(line)
321
+ }
322
+ | kNEXT call_args
323
+ {
324
+ line = val[0].last
325
+ result = s(:next, ret_args(val[1])).line(line)
326
+ }
300
327
 
301
328
  mlhs: mlhs_basic
302
- | tLPAREN mlhs_entry rparen
329
+ | tLPAREN mlhs_inner rparen
303
330
  {
304
331
  result = val[1]
305
332
  }
306
333
 
307
- mlhs_entry: mlhs_basic
308
- | tLPAREN mlhs_entry rparen
334
+ mlhs_inner: mlhs_basic
335
+ | tLPAREN mlhs_inner rparen
309
336
  {
310
337
  result = s(:masgn, s(:array, val[1]))
311
338
  }
@@ -322,21 +349,45 @@ rule
322
349
  {
323
350
  result = s(:masgn, val[0] << s(:splat, val[2]))
324
351
  }
352
+ | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
353
+ {
354
+ ary = list_append val[0], s(:splat, val[2])
355
+ ary.concat val[4][1..-1]
356
+ result = s(:masgn, ary)
357
+ }
325
358
  | mlhs_head tSTAR
326
359
  {
327
360
  result = s(:masgn, val[0] << s(:splat))
328
361
  }
362
+ | mlhs_head tSTAR tCOMMA mlhs_post
363
+ {
364
+ ary = list_append val[0], s(:splat)
365
+ ary.concat val[3][1..-1]
366
+ result = s(:masgn, ary)
367
+ }
329
368
  | tSTAR mlhs_node
330
369
  {
331
370
  result = s(:masgn, s(:array, s(:splat, val[1])))
332
371
  }
372
+ | tSTAR mlhs_node tCOMMA mlhs_post
373
+ {
374
+ ary = s(:array, s(:splat, val[1]))
375
+ ary.concat val[3][1..-1]
376
+ result = s(:masgn, ary)
377
+ }
333
378
  | tSTAR
334
379
  {
335
380
  result = s(:masgn, s(:array, s(:splat)))
336
381
  }
382
+ | tSTAR tCOMMA mlhs_post
383
+ {
384
+ ary = s(:array, s(:splat))
385
+ ary.concat val[2][1..-1]
386
+ result = s(:masgn, ary)
387
+ }
337
388
 
338
389
  mlhs_item: mlhs_node
339
- | tLPAREN mlhs_entry rparen
390
+ | tLPAREN mlhs_inner rparen
340
391
  {
341
392
  result = val[1]
342
393
  }
@@ -350,6 +401,15 @@ rule
350
401
  result = val[0] << val[1].compact
351
402
  }
352
403
 
404
+ mlhs_post: mlhs_item
405
+ {
406
+ result = s(:array, val[0])
407
+ }
408
+ | mlhs_post tCOMMA mlhs_item
409
+ {
410
+ result = list_append val[0], val[2]
411
+ }
412
+
353
413
  mlhs_node: user_variable
354
414
  {
355
415
  result = self.assignable val[0]
@@ -358,7 +418,7 @@ rule
358
418
  {
359
419
  result = self.assignable val[0]
360
420
  }
361
- | primary_value tLBRACK2 aref_args tRBRACK
421
+ | primary_value tLBRACK2 opt_call_args rbracket
362
422
  {
363
423
  result = self.aryset val[0], val[2]
364
424
  }
@@ -403,7 +463,7 @@ rule
403
463
  {
404
464
  result = self.assignable val[0]
405
465
  }
406
- | primary_value tLBRACK2 aref_args tRBRACK
466
+ | primary_value tLBRACK2 opt_call_args rbracket
407
467
  {
408
468
  result = self.aryset val[0], val[2]
409
469
  }
@@ -491,19 +551,21 @@ rule
491
551
  result = new_undef val[0], val[3]
492
552
  }
493
553
 
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
554
+ op: tPIPE | tCARET | tAMPER2 | tCMP | tEQ | tEQQ
555
+ | tMATCH | tNMATCH | tGT | tGEQ | tLT | tLEQ
556
+ | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
557
+ | tSTAR | tDIVIDE | tPERCENT | tPOW | tBANG | tTILDE
558
+ | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
559
+
560
+ reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
561
+ | kALIAS | kAND | kBEGIN | kBREAK | kCASE
562
+ | kCLASS | kDEF | kDEFINED | kDO | kELSE
563
+ | kELSIF | kEND | kENSURE | kFALSE | kFOR
564
+ | kIN | kMODULE | kNEXT | kNIL | kNOT
565
+ | kOR | kREDO | kRESCUE | kRETRY | kRETURN
566
+ | kSELF | kSUPER | kTHEN | kTRUE | kUNDEF
567
+ | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
568
+ | kUNTIL
507
569
 
508
570
  arg: lhs tEQL arg
509
571
  {
@@ -512,13 +574,17 @@ rule
512
574
  | lhs tEQL arg kRESCUE_MOD arg
513
575
  {
514
576
  result = self.node_assign val[0], s(:rescue, val[2], new_resbody(s(:array), val[4]))
515
- # result.line = val[0].line
516
577
  }
517
578
  | var_lhs tOP_ASGN arg
518
579
  {
519
580
  result = new_op_asgn val
520
581
  }
521
- | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN arg
582
+ | var_lhs tOP_ASGN arg kRESCUE_MOD arg
583
+ {
584
+ result = new_op_asgn val
585
+ result = self.node_assign s(:rescue, result, new_resbody(s(:array), val[4]))
586
+ }
587
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
522
588
  {
523
589
  val[2][0] = :arglist
524
590
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
@@ -664,7 +730,7 @@ rule
664
730
  }
665
731
  | tBANG arg
666
732
  {
667
- result = new_call val[1], :"!@"
733
+ result = new_call val[1], :"!"
668
734
  }
669
735
  | tTILDE arg
670
736
  {
@@ -695,10 +761,10 @@ rule
695
761
  {
696
762
  result = s(:defined, val[2])
697
763
  }
698
- | arg tEH arg tCOLON arg
764
+ | arg tEH arg opt_nl tCOLON arg
699
765
  {
700
766
  lexer.tern.pop
701
- result = s(:if, val[0], val[2], val[4])
767
+ result = s(:if, val[0], val[2], val[5])
702
768
  }
703
769
  | primary
704
770
 
@@ -708,30 +774,17 @@ rule
708
774
  }
709
775
 
710
776
  aref_args: none
711
- | command opt_nl
712
- {
713
- warning 'parenthesize argument(s) for future version'
714
- result = s(:array, val[0])
715
- }
716
777
  | args trailer
717
778
  {
718
779
  result = val[0]
719
780
  }
720
- | args tCOMMA tSTAR arg opt_nl
721
- {
722
- result = self.arg_concat val[0], val[3]
723
- }
724
- | assocs trailer
725
- {
726
- result = s(:array, s(:hash, *val[0].values))
727
- }
728
781
  | args tCOMMA assocs trailer
729
782
  {
730
783
  result = val[0] << s(:hash, *val[2].values)
731
784
  }
732
- | tSTAR arg opt_nl
785
+ | assocs trailer
733
786
  {
734
- result = s(:array, s(:splat, val[1]))
787
+ result = s(:array, s(:hash, *val[0].values))
735
788
  }
736
789
 
737
790
  paren_args: tLPAREN2 opt_call_args rparen
@@ -739,6 +792,9 @@ rule
739
792
  result = val[1]
740
793
  }
741
794
 
795
+ opt_paren_args: none
796
+ | paren_args
797
+
742
798
  opt_call_args: none
743
799
  {
744
800
  result = val[0]
@@ -751,20 +807,16 @@ rule
751
807
  {
752
808
  result = val[0]
753
809
  }
754
- | block_call
810
+ | args tCOMMA assocs tCOMMA
755
811
  {
756
812
  warning "parenthesize argument(s) for future version"
757
- result = s(:array, val[0])
813
+ result = val[0].add val[2]
758
814
  }
759
- | args tCOMMA block_call
815
+ | assocs tCOMMA
760
816
  {
761
- warning "parenthesize argument(s) for future version"
762
- result = val[0].add val[2]
817
+ result = val[0]
763
818
  }
764
819
 
765
- opt_paren_args: none
766
- | paren_args
767
-
768
820
  call_args: command
769
821
  {
770
822
  warning "parenthesize argument(s) for future version"
@@ -774,129 +826,28 @@ rule
774
826
  {
775
827
  result = self.arg_blk_pass val[0], val[1]
776
828
  }
777
- | args tCOMMA tSTAR arg_value opt_block_arg
778
- {
779
- result = self.arg_concat val[0], val[3]
780
- result = self.arg_blk_pass result, val[4]
781
- }
782
- | args tCOMMA tSTAR arg_value tCOMMA args opt_block_arg
783
- {
784
- result = self.arg_concat val[0], val[3]
785
- val[5][1..-1].each {|a| result << a }
786
- result = self.arg_blk_pass result, val[6]
787
- }
788
829
  | assocs opt_block_arg
789
830
  {
790
831
  result = s(:array, s(:hash, *val[0].values))
791
832
  result = self.arg_blk_pass result, val[1]
792
833
  }
793
- | assocs tCOMMA tSTAR arg_value opt_block_arg
794
- {
795
- result = self.arg_concat s(:array, s(:hash, *val[0].values)), val[3]
796
- result = self.arg_blk_pass result, val[4]
797
- }
798
834
  | args tCOMMA assocs opt_block_arg
799
835
  {
800
836
  result = val[0] << s(:hash, *val[2].values)
801
837
  result = self.arg_blk_pass result, val[3]
802
838
  }
803
- | args tCOMMA assocs tCOMMA tSTAR arg opt_block_arg
804
- {
805
- val[0] << s(:hash, *val[2].values)
806
- result = self.arg_concat val[0], val[5]
807
- result = self.arg_blk_pass result, val[6]
808
- }
809
- | tSTAR arg_value opt_block_arg
810
- {
811
- result = self.arg_blk_pass s(:splat, val[1]), val[2]
812
- }
813
- | block_arg
814
-
815
- call_args2: arg_value tCOMMA args opt_block_arg
816
- {
817
- args = self.list_prepend val[0], val[2]
818
- result = self.arg_blk_pass args, val[3]
819
- }
820
- | arg_value tCOMMA block_arg
821
- {
822
- result = self.arg_blk_pass val[0], val[2]
823
- }
824
- | arg_value tCOMMA tSTAR arg_value opt_block_arg
825
- {
826
- result = self.arg_concat s(:array, val[0]), val[3]
827
- result = self.arg_blk_pass result, val[4]
828
- }
829
- | arg_value tCOMMA args tCOMMA tSTAR arg_value opt_block_arg
830
- {
831
- result = self.arg_concat s(:array, val[0], s(:hash, *val[2].values)), val[5]
832
- result = self.arg_blk_pass result, val[6]
833
- }
834
- | assocs opt_block_arg
835
- {
836
- result = s(:array, s(:hash, *val[0].values))
837
- result = self.arg_blk_pass result, val[1]
838
- }
839
- | assocs tCOMMA tSTAR arg_value opt_block_arg
840
- {
841
- result = s(:array, s(:hash, *val[0].values), val[3])
842
- result = self.arg_blk_pass result, val[4]
843
- }
844
- | arg_value tCOMMA assocs opt_block_arg
845
- {
846
- result = s(:array, val[0], s(:hash, *val[2].values))
847
- result = self.arg_blk_pass result, val[3]
848
- }
849
- | arg_value tCOMMA args tCOMMA assocs opt_block_arg
850
- {
851
- result = s(:array, val[0]).add_all(val[2]).add(s(:hash, *val[4].values))
852
- result = self.arg_blk_pass result, val[5]
853
- }
854
- | arg_value tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
855
- {
856
- result = self.arg_concat s(:array, val[0]).add(s(:hash, *val[2].values)), val[5]
857
- result = self.arg_blk_pass result, val[6]
858
- }
859
- | arg_value tCOMMA args tCOMMA assocs tCOMMA tSTAR arg_value opt_block_arg
860
- {
861
- result = self.arg_concat s(:array, val[0]).add_all(val[2]).add(s(:hash, *val[4].values)), val[7]
862
- result = self.arg_blk_pass result, val[8]
863
- }
864
- | tSTAR arg_value opt_block_arg
865
- {
866
- result = self.arg_blk_pass s(:splat, val[1]), val[2]
867
- }
868
839
  | block_arg
869
840
 
870
841
  command_args: {
871
842
  result = lexer.cmdarg.stack.dup
872
843
  lexer.cmdarg.push true
873
844
  }
874
- open_args
845
+ call_args
875
846
  {
876
847
  lexer.cmdarg.stack.replace val[0]
877
848
  result = val[1]
878
849
  }
879
850
 
880
- open_args: call_args
881
- | tLPAREN_ARG
882
- {
883
- lexer.lex_state = :expr_endarg
884
- }
885
- tRPAREN
886
- {
887
- warning "don't put space before argument parentheses"
888
- result = nil
889
- }
890
- | tLPAREN_ARG call_args2
891
- {
892
- lexer.lex_state = :expr_endarg
893
- }
894
- tRPAREN
895
- {
896
- warning "don't put space before argument parentheses"
897
- result = val[1]
898
- }
899
-
900
851
  block_arg: tAMPER arg_value
901
852
  {
902
853
  result = s(:block_pass, val[1])
@@ -912,10 +863,18 @@ rule
912
863
  {
913
864
  result = s(:array, val[0])
914
865
  }
866
+ | tSTAR arg_value
867
+ {
868
+ result = s(:array, s(:splat, val[1]))
869
+ }
915
870
  | args tCOMMA arg_value
916
871
  {
917
872
  result = self.list_append val[0], val[2]
918
873
  }
874
+ | args tCOMMA tSTAR arg_value
875
+ {
876
+ result = self.list_append val[0], s(:splat, val[3])
877
+ }
919
878
 
920
879
  mrhs: args tCOMMA arg_value
921
880
  {
@@ -978,10 +937,6 @@ rule
978
937
  {
979
938
  result = s(:colon3, val[1].to_sym)
980
939
  }
981
- | primary_value tLBRACK2 aref_args tRBRACK
982
- {
983
- result = new_aref val
984
- }
985
940
  | tLBRACK aref_args tRBRACK
986
941
  {
987
942
  result = val[1] || s(:array)
@@ -1010,6 +965,14 @@ rule
1010
965
  {
1011
966
  result = s(:defined, val[3])
1012
967
  }
968
+ | kNOT tLPAREN2 expr rparen
969
+ {
970
+ raise "no2: #{val.inspect}"
971
+ }
972
+ | kNOT tLPAREN2 rparen
973
+ {
974
+ raise "no3: #{val.inspect}"
975
+ }
1013
976
  | operation brace_block
1014
977
  {
1015
978
  oper, iter = val[0], val[1]
@@ -1069,10 +1032,6 @@ rule
1069
1032
  {
1070
1033
  result = new_case nil, val[2]
1071
1034
  }
1072
- | kCASE opt_terms kELSE compstmt kEND # TODO: need a test
1073
- {
1074
- result = new_case nil, val[3]
1075
- }
1076
1035
  | kFOR for_var kIN
1077
1036
  {
1078
1037
  lexer.cond.push true
@@ -1206,12 +1165,10 @@ rule
1206
1165
  k_end: kEND
1207
1166
 
1208
1167
  then: term
1209
- | tCOLON
1210
1168
  | kTHEN
1211
1169
  | term kTHEN
1212
1170
 
1213
1171
  do: term
1214
- | tCOLON
1215
1172
  | kDO_COND
1216
1173
 
1217
1174
  if_tail: opt_else
@@ -1232,85 +1189,138 @@ rule
1232
1189
  val[0].delete_at 1 if val[0][1].nil? # HACK
1233
1190
  }
1234
1191
 
1235
- block_par: mlhs_item
1192
+ f_marg: f_norm_arg
1236
1193
  {
1237
- result = s(:array, val[0])
1194
+ raise "no4: #{val.inspect}"
1238
1195
  }
1239
- | block_par tCOMMA mlhs_item
1196
+ | tLPAREN f_margs rparen
1240
1197
  {
1241
- result = self.list_append val[0], val[2]
1198
+ raise "no5: #{val.inspect}"
1242
1199
  }
1243
1200
 
1244
- block_var: block_par
1201
+ f_marg_list: f_marg
1245
1202
  {
1246
- result = block_var val[0], nil, nil
1203
+ raise "no6: #{val.inspect}"
1247
1204
  }
1248
- | block_par tCOMMA
1205
+ | f_marg_list tCOMMA f_marg
1249
1206
  {
1250
- result = block_var val[0], nil, nil
1207
+ raise "no7: #{val.inspect}"
1251
1208
  }
1252
- | block_par tCOMMA tAMPER lhs
1209
+
1210
+ f_margs: f_marg_list
1253
1211
  {
1254
- result = block_var val[0], nil, val[3]
1212
+ raise "no8: #{val.inspect}"
1255
1213
  }
1256
- | block_par tCOMMA tSTAR lhs tCOMMA tAMPER lhs
1214
+ | f_marg_list tCOMMA tSTAR f_norm_arg
1257
1215
  {
1258
- result = block_var val[0], val[3], val[6]
1216
+ raise "no9: #{val.inspect}"
1259
1217
  }
1260
- | block_par tCOMMA tSTAR tCOMMA tAMPER lhs
1218
+ | f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
1261
1219
  {
1262
- result = block_var val[0], s(:splat), val[5]
1220
+ raise "no10: #{val.inspect}"
1263
1221
  }
1264
- | block_par tCOMMA tSTAR lhs
1222
+ | f_marg_list tCOMMA tSTAR
1265
1223
  {
1266
- result = block_var val[0], val[3], nil
1224
+ raise "no11: #{val.inspect}"
1267
1225
  }
1268
- | block_par tCOMMA tSTAR
1226
+ | f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
1269
1227
  {
1270
- result = block_var val[0], s(:splat), nil
1228
+ raise "no12: #{val.inspect}"
1271
1229
  }
1272
- | tSTAR lhs tCOMMA tAMPER lhs
1230
+ | tSTAR f_norm_arg
1273
1231
  {
1274
- result = block_var nil, val[1], val[4]
1232
+ raise "no13: #{val.inspect}"
1275
1233
  }
1276
- | tSTAR tCOMMA tAMPER lhs
1234
+ | tSTAR f_norm_arg tCOMMA f_marg_list
1277
1235
  {
1278
- result = block_var nil, s(:splat), val[3]
1236
+ raise "no14: #{val.inspect}"
1279
1237
  }
1280
- | tSTAR lhs
1238
+ | tSTAR
1281
1239
  {
1282
- result = block_var nil, val[1], nil
1240
+ raise "no15: #{val.inspect}"
1283
1241
  }
1284
- | tSTAR
1242
+ | tSTAR tCOMMA f_marg_list
1243
+ {
1244
+ raise "no16: #{val.inspect}"
1245
+ }
1246
+
1247
+ block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
1248
+ {
1249
+ result = block_args19 val, "1"
1250
+ }
1251
+ | f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
1285
1252
  {
1286
- result = block_var nil, s(:splat), nil
1253
+ result = block_args19 val, "2"
1287
1254
  }
1288
- | tAMPER lhs
1255
+ | f_arg tCOMMA f_block_optarg opt_f_block_arg
1289
1256
  {
1290
- result = block_var nil, nil, val[1]
1257
+ result = block_args19 val, "3"
1258
+ }
1259
+ | f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_f_block_arg
1260
+ {
1261
+ result = block_args19 val, "4"
1262
+ }
1263
+ | f_arg tCOMMA f_rest_arg opt_f_block_arg
1264
+ {
1265
+ result = block_args19 val, "5"
1266
+ }
1267
+ | f_arg tCOMMA
1268
+ {
1269
+ result = block_args19 val, "6"
1270
+ }
1271
+ | f_arg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
1272
+ {
1273
+ result = block_args19 val, "7"
1274
+ }
1275
+ | f_arg opt_f_block_arg
1276
+ {
1277
+ result = block_args19 val, "8"
1278
+ }
1279
+ | f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
1280
+ {
1281
+ result = block_args19 val, "9"
1282
+ }
1283
+ | f_block_optarg tCOMMA f_rest_arg tCOMMA f_arg opt_f_block_arg
1284
+ {
1285
+ result = block_args19 val, "10"
1286
+ }
1287
+ | f_block_optarg opt_f_block_arg
1288
+ {
1289
+ result = block_args19 val, "11"
1290
+ }
1291
+ | f_block_optarg tCOMMA f_arg opt_f_block_arg
1292
+ {
1293
+ result = block_args19 val, "12"
1294
+ }
1295
+ | f_rest_arg opt_f_block_arg
1296
+ {
1297
+ result = block_args19 val, "13"
1298
+ }
1299
+ | f_rest_arg tCOMMA f_arg opt_f_block_arg
1300
+ {
1301
+ result = block_args19 val, "14"
1302
+ }
1303
+ | f_block_arg
1304
+ {
1305
+ result = block_args19 val, "15"
1291
1306
  }
1292
- ;
1293
1307
 
1294
- opt_block_var: none
1295
- | tPIPE tPIPE
1308
+ opt_block_param: none
1309
+ | block_param_def
1310
+
1311
+ block_param_def: tPIPE opt_bv_decl tPIPE
1296
1312
  {
1297
- result = 0
1298
- self.lexer.command_start = true
1313
+ raise "no17: #{val.inspect}"
1299
1314
  }
1300
1315
  | tOROP
1301
1316
  {
1302
1317
  result = 0
1303
1318
  self.lexer.command_start = true
1304
1319
  }
1305
- | tPIPE block_var tPIPE
1320
+ | tPIPE block_param opt_bv_decl tPIPE
1306
1321
  {
1307
1322
  result = val[1]
1308
- self.lexer.command_start = true
1309
- }
1310
- | tPIPE tAMPER block_var tPIPE
1311
- {
1312
- result = s(:lasgn, :"&block")
1313
- self.lexer.command_start = true
1323
+ result.concat val[2] if val[2]
1314
1324
  }
1315
1325
 
1316
1326
  opt_bv_decl: none
@@ -1323,17 +1333,13 @@ rule
1323
1333
  | bv_decls tCOMMA bvar
1324
1334
  {
1325
1335
  result = val[0] << val[2]
1336
+ raise "no18: #{val.inspect}"
1326
1337
  }
1327
1338
 
1328
1339
  bvar: tIDENTIFIER
1329
1340
  | f_bad_arg
1330
1341
 
1331
- lambda: lambda_body
1332
- {
1333
- call = new_call nil, :lambda
1334
- result = s(:iter, call, 0, val[0])
1335
- }
1336
- | f_larglist lambda_body
1342
+ lambda: f_larglist lambda_body
1337
1343
  {
1338
1344
  case val[0].size
1339
1345
  when 1
@@ -1372,7 +1378,7 @@ rule
1372
1378
  self.env.extend :dynamic
1373
1379
  result = self.lexer.lineno
1374
1380
  }
1375
- opt_block_var
1381
+ opt_block_param
1376
1382
  {
1377
1383
  result = self.env.dynamic.keys
1378
1384
  }
@@ -1423,6 +1429,14 @@ rule
1423
1429
  {
1424
1430
  result = new_call val[0], val[2].to_sym
1425
1431
  }
1432
+ | primary_value tDOT paren_args
1433
+ {
1434
+ result = new_call val[0], :call
1435
+ }
1436
+ | primary_value tCOLON2 paren_args
1437
+ {
1438
+ result = new_call val[0], :call
1439
+ }
1426
1440
  | kSUPER paren_args
1427
1441
  {
1428
1442
  result = new_super val[1]
@@ -1431,13 +1445,17 @@ rule
1431
1445
  {
1432
1446
  result = s(:zsuper)
1433
1447
  }
1448
+ | primary_value tLBRACK2 opt_call_args rbracket
1449
+ {
1450
+ result = new_aref val
1451
+ }
1434
1452
 
1435
1453
  brace_block: tLCURLY
1436
1454
  {
1437
1455
  self.env.extend :dynamic
1438
1456
  result = self.lexer.lineno
1439
1457
  }
1440
- opt_block_var
1458
+ opt_block_param
1441
1459
  {
1442
1460
  result = self.env.dynamic.keys
1443
1461
  }
@@ -1455,7 +1473,7 @@ rule
1455
1473
  self.env.extend :dynamic
1456
1474
  result = self.lexer.lineno
1457
1475
  }
1458
- opt_block_var
1476
+ opt_block_param
1459
1477
  {
1460
1478
  result = self.env.dynamic.keys
1461
1479
  }
@@ -1472,23 +1490,13 @@ rule
1472
1490
  {
1473
1491
  result = self.lexer.lineno
1474
1492
  }
1475
- when_args then compstmt cases
1493
+ args then compstmt cases
1476
1494
  {
1477
1495
  result = new_when(val[2], val[4])
1478
1496
  result.line = val[1]
1479
1497
  result << val[5] if val[5]
1480
1498
  }
1481
1499
 
1482
- when_args: args
1483
- | args tCOMMA tSTAR arg_value
1484
- {
1485
- result = self.list_append val[0], new_when(val[3], nil)
1486
- }
1487
- | tSTAR arg_value
1488
- {
1489
- result = s(:array, new_when(val[1], nil))
1490
- }
1491
-
1492
1500
  cases: opt_else | case_body
1493
1501
 
1494
1502
  opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
@@ -1737,6 +1745,7 @@ keyword_variable: kNIL { result = s(:nil) }
1737
1745
  | kFALSE { result = s(:false) }
1738
1746
  | k__FILE__ { result = s(:str, self.file) }
1739
1747
  | k__LINE__ { result = s(:lit, lexer.src.current_line) }
1748
+ | k__ENCODING__ { result = s(:str, "Unsupported!") }
1740
1749
 
1741
1750
  var_ref: user_variable
1742
1751
  {
@@ -1877,12 +1886,18 @@ keyword_variable: kNIL { result = s(:nil) }
1877
1886
  result = val[0]
1878
1887
  }
1879
1888
 
1880
- f_arg: f_norm_arg
1889
+ f_arg_item: f_norm_arg
1890
+ | tLPAREN f_margs rparen
1891
+ {
1892
+ raise "no19: #{val.inspect}"
1893
+ }
1894
+
1895
+ f_arg: f_arg_item
1881
1896
  {
1882
1897
  result = s(:args)
1883
1898
  result << val[0].to_sym
1884
1899
  }
1885
- | f_arg tCOMMA f_norm_arg
1900
+ | f_arg tCOMMA f_arg_item
1886
1901
  {
1887
1902
  val[0] << val[2].to_sym
1888
1903
  result = val[0]
@@ -1894,6 +1909,20 @@ keyword_variable: kNIL { result = s(:nil) }
1894
1909
  # TODO: detect duplicate names
1895
1910
  }
1896
1911
 
1912
+ f_block_opt: tIDENTIFIER tEQL primary_value
1913
+ {
1914
+ raise "no20: #{val.inspect}"
1915
+ }
1916
+
1917
+ f_block_optarg: f_block_opt
1918
+ {
1919
+ raise "no21: #{val.inspect}"
1920
+ }
1921
+ | f_block_optarg tCOMMA f_block_opt
1922
+ {
1923
+ raise "no22: #{val.inspect}"
1924
+ }
1925
+
1897
1926
  f_optarg: f_opt
1898
1927
  {
1899
1928
  result = s(:block, val[0])
@@ -1958,14 +1987,6 @@ keyword_variable: kNIL { result = s(:nil) }
1958
1987
  {
1959
1988
  result = val[0]
1960
1989
  }
1961
- | args trailer
1962
- {
1963
- size = val[0].size
1964
- if (size % 2 != 1) then # != 1 because of leading :array
1965
- yyerror "Odd number (#{size}) list for Hash. #{val[0].inspect}"
1966
- end
1967
- result = val[0]
1968
- }
1969
1990
 
1970
1991
  assocs: assoc
1971
1992
  | assocs tCOMMA assoc