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.
@@ -87,14 +87,35 @@ rule
87
87
  end
88
88
  self.env.extend
89
89
  }
90
- tLCURLY top_compstmt tRCURLY
90
+ begin_block
91
91
  {
92
- result = new_iter s(:preexe), nil, val[3]
92
+ _, _, block = val
93
+ result = block
94
+ }
95
+
96
+ begin_block: tLCURLY top_compstmt tRCURLY
97
+ {
98
+ _, stmt, _ = val
99
+ result = new_iter s(:preexe), 0, stmt
93
100
  }
94
101
 
95
- bodystmt: compstmt opt_rescue opt_else opt_ensure
102
+ bodystmt: compstmt opt_rescue k_else
96
103
  {
97
- result = new_body val
104
+ res = _values[-2]
105
+ yyerror "else without rescue is useless" unless res
106
+ }
107
+ compstmt
108
+ opt_ensure
109
+ {
110
+ body, resc, _, _, els, ens = val
111
+
112
+ result = new_body [body, resc, els, ens]
113
+ }
114
+ | compstmt opt_rescue opt_ensure
115
+ {
116
+ body, resc, ens = val
117
+
118
+ result = new_body [body, resc, nil, ens]
98
119
  }
99
120
 
100
121
  compstmt: stmts opt_terms
@@ -103,8 +124,8 @@ rule
103
124
  }
104
125
 
105
126
  stmts: none
106
- | stmt
107
- | stmts terms stmt
127
+ | stmt_or_begin # TODO: newline_node ?
128
+ | stmts terms stmt_or_begin
108
129
  {
109
130
  result = self.block_append val[0], val[2]
110
131
  }
@@ -114,6 +135,21 @@ rule
114
135
  debug20 2, val, result
115
136
  }
116
137
 
138
+ stmt_or_begin: stmt
139
+ | klBEGIN
140
+ {
141
+ if (self.in_def || self.in_single > 0) then
142
+ debug20 1
143
+ yyerror "BEGIN in method"
144
+ end
145
+ self.env.extend
146
+ }
147
+ begin_block
148
+ {
149
+ _, _, stmt = val
150
+ result = stmt
151
+ }
152
+
117
153
  stmt: kALIAS fitem
118
154
  {
119
155
  lexer.lex_state = :expr_fname
@@ -157,7 +193,8 @@ rule
157
193
  }
158
194
  | stmt kRESCUE_MOD stmt
159
195
  {
160
- result = s(:rescue, val[0], new_resbody(s(:array), val[2]))
196
+ body, _, resbody = val
197
+ result = new_rescue body, new_resbody(s(:array), resbody)
161
198
  }
162
199
  | klEND tLCURLY compstmt tRCURLY
163
200
  {
@@ -172,15 +209,33 @@ rule
172
209
  {
173
210
  result = new_masgn val[0], val[2], :wrap
174
211
  }
175
- | var_lhs tOP_ASGN command_call
212
+ | lhs tEQL mrhs
213
+ {
214
+ result = new_assign val[0], s(:svalue, val[2])
215
+ }
216
+ | mlhs tEQL mrhs_arg
217
+ {
218
+ result = new_masgn val[0], val[2]
219
+ }
220
+ | expr
221
+
222
+ command_asgn: lhs tEQL command_rhs
223
+ {
224
+ result = new_assign val[0], val[2]
225
+ }
226
+ # | lhs tEQL command_asgn
227
+ # {
228
+ # result = new_assign val[0], val[2]
229
+ # }
230
+ | var_lhs tOP_ASGN command_rhs
176
231
  {
177
232
  result = new_op_asgn val
178
233
  }
179
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_call
234
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
180
235
  {
181
236
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
182
237
  }
183
- | primary_value call_op tIDENTIFIER tOP_ASGN command_call
238
+ | primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
184
239
  {
185
240
  result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
186
241
  if val[1] == '&.'
@@ -188,7 +243,7 @@ rule
188
243
  end
189
244
  result.line = val[0].line
190
245
  }
191
- | primary_value call_op tCONSTANT tOP_ASGN command_call
246
+ | primary_value call_op tCONSTANT tOP_ASGN command_rhs
192
247
  {
193
248
  result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
194
249
  if val[1] == '&.'
@@ -196,38 +251,33 @@ rule
196
251
  end
197
252
  result.line = val[0].line
198
253
  }
199
- | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
254
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
200
255
  {
201
256
  result = s(:op_asgn, val[0], val[4], val[2], val[3])
202
257
  debug20 4, val, result
203
258
  }
204
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
259
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
205
260
  {
206
261
  result = s(:op_asgn, val[0], val[4], val[2], val[3])
207
262
  debug20 5, val, result
208
263
  }
209
- | backref tOP_ASGN command_call
264
+ | backref tOP_ASGN command_rhs
210
265
  {
211
266
  self.backref_assign_error val[0]
212
267
  }
213
- | lhs tEQL mrhs
214
- {
215
- result = new_assign val[0], s(:svalue, val[2])
216
- }
217
- | mlhs tEQL mrhs_arg
218
- {
219
- result = new_masgn val[0], val[2]
220
- }
221
- | expr
222
268
 
223
- command_asgn: lhs tEQL command_call
269
+ command_rhs: command_call =tOP_ASGN
224
270
  {
225
- result = new_assign val[0], val[2]
271
+ expr, = val
272
+ result = value_expr expr
226
273
  }
227
- | lhs tEQL command_asgn
274
+ | command_call kRESCUE_MOD stmt
228
275
  {
229
- result = new_assign val[0], val[2]
276
+ expr, _, resbody = val
277
+ expr = value_expr expr
278
+ result = new_rescue(expr, new_resbody(s(:array), resbody))
230
279
  }
280
+ | command_asgn
231
281
 
232
282
  expr: command_call
233
283
  | expr kAND expr
@@ -253,30 +303,40 @@ rule
253
303
  result = value_expr(val[0])
254
304
  }
255
305
 
306
+ expr_value_do: {
307
+ lexer.cond.push true
308
+ }
309
+ expr_value do
310
+ {
311
+ lexer.cond.pop
312
+ }
313
+ {
314
+ _, expr, _, _ = val
315
+ result = expr
316
+ }
317
+
256
318
  command_call: command
257
319
  | block_command
258
320
 
259
321
  block_command: block_call
260
- | block_call dot_or_colon operation2 command_args
322
+ | block_call call_op2 operation2 command_args
261
323
  {
262
324
  result = new_call val[0], val[2].to_sym, val[3]
263
325
  }
264
326
 
265
327
  cmd_brace_block: tLBRACE_ARG
266
328
  {
267
- self.env.extend(:dynamic)
329
+ # self.env.extend(:dynamic)
268
330
  result = self.lexer.lineno
269
331
  }
270
- opt_block_param
271
- {
272
- result = nil # self.env.dynamic.keys
273
- }
274
- compstmt tRCURLY
332
+ brace_body tRCURLY
275
333
  {
276
- result = new_iter nil, val[2], val[4]
277
- result.line = val[1]
334
+ _, line, body, _ = val
278
335
 
279
- self.env.unextend
336
+ result = body
337
+ result.line = line
338
+
339
+ # self.env.unextend
280
340
  }
281
341
 
282
342
  fcall: operation
@@ -334,7 +394,7 @@ rule
334
394
  {
335
395
  result = new_yield val[1]
336
396
  }
337
- | kRETURN call_args
397
+ | k_return call_args
338
398
  {
339
399
  line = val[0].last
340
400
  result = s(:return, ret_args(val[1])).line(line)
@@ -558,8 +618,9 @@ rule
558
618
 
559
619
  | reswords
560
620
  {
621
+ (sym, _line), = val
561
622
  lexer.lex_state = :expr_end
562
- result = val[0]
623
+ result = sym
563
624
  }
564
625
 
565
626
  fsym: fname | symbol
@@ -589,6 +650,7 @@ rule
589
650
  | tNEQ | tLSHFT | tRSHFT | tPLUS | tMINUS | tSTAR2
590
651
  | tSTAR | tDIVIDE | tPERCENT | tPOW | tDSTAR | tBANG | tTILDE
591
652
  | tUPLUS | tUMINUS | tAREF | tASET | tBACK_REF2
653
+ | tUBANG
592
654
 
593
655
  reswords: k__LINE__ | k__FILE__ | k__ENCODING__ | klBEGIN | klEND
594
656
  | kALIAS | kAND | kBEGIN | kBREAK | kCASE
@@ -600,51 +662,46 @@ rule
600
662
  | kWHEN | kYIELD | kIF | kUNLESS | kWHILE
601
663
  | kUNTIL
602
664
 
603
- arg: lhs tEQL arg
665
+ arg: lhs tEQL arg_rhs
604
666
  {
605
667
  result = new_assign val[0], val[2]
606
668
  }
607
- | lhs tEQL arg kRESCUE_MOD arg
608
- {
609
- result = new_assign val[0], s(:rescue, val[2], new_resbody(s(:array), val[4]))
610
- }
611
- | var_lhs tOP_ASGN arg
612
- {
613
- result = new_op_asgn val
614
- }
615
- | var_lhs tOP_ASGN arg kRESCUE_MOD arg
669
+ | var_lhs tOP_ASGN arg_rhs
616
670
  {
617
671
  result = new_op_asgn val
618
- result = s(:rescue, result, new_resbody(s(:array), val[4]))
619
672
  }
620
- | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
673
+ | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
621
674
  {
622
675
  val[2].sexp_type = :arglist if val[2]
623
676
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
624
677
  }
625
- | primary_value call_op tIDENTIFIER tOP_ASGN arg
678
+ | primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
626
679
  {
627
680
  result = new_op_asgn2 val
628
681
  }
629
- | primary_value call_op tCONSTANT tOP_ASGN arg
682
+ | primary_value call_op tCONSTANT tOP_ASGN arg_rhs
630
683
  {
631
684
  result = new_op_asgn2 val
632
685
  }
633
- | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
686
+ | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
634
687
  {
635
688
  result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
636
689
  }
637
- | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
690
+ | primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
638
691
  {
639
- yyerror "constant re-assignment"
692
+ # TODO: assignment
693
+ raise "not yet: %p" % [val]
640
694
  }
641
- | tCOLON3 tCONSTANT tOP_ASGN arg
695
+ | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
642
696
  {
643
- yyerror "constant re-assignment"
697
+ # TODO: assignment
698
+ raise "not yet: %p" % [val]
644
699
  }
645
- | backref tOP_ASGN arg
700
+ | backref tOP_ASGN arg_rhs
646
701
  {
647
- self.backref_assign_error val[0]
702
+ # TODO: lhs = var_field val[0]
703
+ asgn = new_op_asgn val
704
+ result = self.backref_assign_error asgn
648
705
  }
649
706
  | arg tDOT2 arg
650
707
  {
@@ -716,22 +773,7 @@ rule
716
773
  {
717
774
  result = new_call val[0], :"<=>", argl(val[2])
718
775
  }
719
- | arg tGT arg
720
- {
721
- result = new_call val[0], :">", argl(val[2])
722
- }
723
- | arg tGEQ arg
724
- {
725
- result = new_call val[0], :">=", argl(val[2])
726
- }
727
- | arg tLT arg
728
- {
729
- result = new_call val[0], :"<", argl(val[2])
730
- }
731
- | arg tLEQ arg
732
- {
733
- result = new_call val[0], :"<=", argl(val[2])
734
- }
776
+ | rel_expr =tCMP
735
777
  | arg tEQ arg
736
778
  {
737
779
  result = new_call val[0], :"==", argl(val[2])
@@ -790,6 +832,23 @@ rule
790
832
  }
791
833
  | primary
792
834
 
835
+ relop: tGT
836
+ | tLT
837
+ | tGEQ
838
+ | tLEQ
839
+
840
+ rel_expr: arg relop arg =tGT
841
+ {
842
+ lhs, op, rhs = val
843
+ result = new_call lhs, op.to_sym, argl(rhs)
844
+ }
845
+ | rel_expr relop arg =tGT
846
+ {
847
+ lhs, op, rhs = val
848
+ warn "comparison '%s' after comparison", op
849
+ result = new_call lhs, op.to_sym, argl(rhs)
850
+ }
851
+
793
852
  arg_value: arg
794
853
  {
795
854
  result = value_expr(val[0])
@@ -809,6 +868,15 @@ rule
809
868
  result = args [array_to_hash(val[0])]
810
869
  }
811
870
 
871
+ arg_rhs: arg =tOP_ASGN
872
+ | arg kRESCUE_MOD arg
873
+ {
874
+ body, _, resbody = val
875
+ body = value_expr body
876
+ resbody = remove_begin resbody
877
+ result = new_rescue(body, new_resbody(s(:array), resbody))
878
+ }
879
+
812
880
  paren_args: tLPAREN2 opt_call_args rparen
813
881
  {
814
882
  result = val[1]
@@ -864,12 +932,11 @@ rule
864
932
  }
865
933
 
866
934
  command_args: {
867
- result = lexer.cmdarg.stack.dup # TODO: smell?
868
- lexer.cmdarg.push true
935
+ result = lexer.cmdarg.store true
869
936
  }
870
937
  call_args
871
938
  {
872
- lexer.cmdarg.stack.replace val[0]
939
+ lexer.cmdarg.restore val[0]
873
940
  result = val[1]
874
941
  }
875
942
 
@@ -937,12 +1004,16 @@ rule
937
1004
  {
938
1005
  result = new_call nil, val[0].to_sym
939
1006
  }
940
- | kBEGIN
1007
+ | k_begin
941
1008
  {
942
1009
  result = self.lexer.lineno
1010
+ # TODO:
1011
+ # $<val>1 = cmdarg_stack;
1012
+ # CMDARG_SET(0);
943
1013
  }
944
- bodystmt kEND
1014
+ bodystmt k_end
945
1015
  {
1016
+ # TODO: CMDARG_SET($<val>1);
946
1017
  unless val[2] then
947
1018
  result = s(:nil)
948
1019
  else
@@ -953,22 +1024,25 @@ rule
953
1024
  }
954
1025
  | tLPAREN_ARG rparen
955
1026
  {
1027
+ # TODO: lex_state = :expr_endarg in between
956
1028
  debug20 13, val, result
957
1029
  }
958
1030
  | tLPAREN_ARG
959
1031
  {
960
- result = self.lexer.cmdarg.stack.dup
961
- lexer.cmdarg.stack.replace [false] # TODO add api for these
1032
+ result = lexer.cmdarg.store false
1033
+ # result = self.lexer.cmdarg.stack.dup
1034
+ # lexer.cmdarg.stack.replace [false] # TODO add api for these
962
1035
  }
963
- expr
1036
+ stmt
964
1037
  {
965
1038
  lexer.lex_state = :expr_endarg
966
1039
  }
967
1040
  rparen
968
1041
  {
1042
+ _, cmdarg, stmt, _, _, = val
969
1043
  warning "(...) interpreted as grouped expression"
970
- lexer.cmdarg.stack.replace val[1]
971
- result = val[2]
1044
+ lexer.cmdarg.restore cmdarg
1045
+ result = stmt
972
1046
  }
973
1047
  | tLPAREN compstmt tRPAREN
974
1048
  {
@@ -996,7 +1070,7 @@ rule
996
1070
  {
997
1071
  result = new_hash val
998
1072
  }
999
- | kRETURN
1073
+ | k_return
1000
1074
  {
1001
1075
  result = s(:return)
1002
1076
  }
@@ -1044,61 +1118,42 @@ rule
1044
1118
  {
1045
1119
  result = val[1] # TODO: fix lineno
1046
1120
  }
1047
- | kIF expr_value then compstmt if_tail kEND
1121
+ | k_if expr_value then compstmt if_tail k_end
1048
1122
  {
1049
- result = new_if val[1], val[3], val[4]
1123
+ _, c, _, t, f, _ = val
1124
+ result = new_if c, t, f
1050
1125
  }
1051
- | kUNLESS expr_value then compstmt opt_else kEND
1126
+ | k_unless expr_value then compstmt opt_else k_end
1052
1127
  {
1053
- result = new_if val[1], val[4], val[3]
1128
+ _, c, _, t, f, _ = val
1129
+ result = new_if c, f, t
1054
1130
  }
1055
- | kWHILE
1131
+ | k_while expr_value_do compstmt k_end
1056
1132
  {
1057
- lexer.cond.push true
1133
+ _, cond, body, _ = val
1134
+ result = new_while body, cond, true
1058
1135
  }
1059
- expr_value do
1136
+ | k_until expr_value_do compstmt k_end
1060
1137
  {
1061
- lexer.cond.pop
1062
- }
1063
- compstmt kEND
1064
- {
1065
- result = new_while val[5], val[2], true
1066
- }
1067
- | kUNTIL
1068
- {
1069
- lexer.cond.push true
1070
- }
1071
- expr_value do
1072
- {
1073
- lexer.cond.pop
1138
+ _, cond, body, _ = val
1139
+ result = new_until body, cond, true
1074
1140
  }
1075
- compstmt kEND
1076
- {
1077
- result = new_until val[5], val[2], true
1078
- }
1079
- | kCASE expr_value opt_terms case_body kEND
1141
+ | k_case expr_value opt_terms case_body k_end
1080
1142
  {
1081
1143
  (_, line), expr, _, body, _ = val
1082
1144
  result = new_case expr, body, line
1083
1145
  }
1084
- | kCASE opt_terms case_body kEND
1146
+ | k_case opt_terms case_body k_end
1085
1147
  {
1086
1148
  (_, line), _, body, _ = val
1087
1149
  result = new_case nil, body, line
1088
1150
  }
1089
- | kFOR for_var kIN
1090
- {
1091
- lexer.cond.push true
1092
- }
1093
- expr_value do
1151
+ | k_for for_var kIN expr_value_do compstmt k_end
1094
1152
  {
1095
- lexer.cond.pop
1153
+ _, var, _, iter, body, _ = val
1154
+ result = new_for iter, var, body
1096
1155
  }
1097
- compstmt kEND
1098
- {
1099
- result = new_for val[4], val[1], val[7]
1100
- }
1101
- | kCLASS
1156
+ | k_class
1102
1157
  {
1103
1158
  result = self.lexer.lineno
1104
1159
  }
@@ -1110,13 +1165,13 @@ rule
1110
1165
  end
1111
1166
  self.env.extend
1112
1167
  }
1113
- bodystmt kEND
1168
+ bodystmt k_end
1114
1169
  {
1115
1170
  result = new_class val
1116
1171
  self.env.unextend
1117
1172
  self.lexer.comments # we don't care about comments in the body
1118
1173
  }
1119
- | kCLASS tLSHFT
1174
+ | k_class tLSHFT
1120
1175
  {
1121
1176
  result = self.lexer.lineno
1122
1177
  }
@@ -1131,13 +1186,13 @@ rule
1131
1186
  self.in_single = 0
1132
1187
  self.env.extend
1133
1188
  }
1134
- bodystmt kEND
1189
+ bodystmt k_end
1135
1190
  {
1136
1191
  result = new_sclass val
1137
1192
  self.env.unextend
1138
1193
  self.lexer.comments # we don't care about comments in the body
1139
1194
  }
1140
- | kMODULE
1195
+ | k_module
1141
1196
  {
1142
1197
  result = self.lexer.lineno
1143
1198
  }
@@ -1149,13 +1204,13 @@ rule
1149
1204
 
1150
1205
  self.env.extend
1151
1206
  }
1152
- bodystmt kEND
1207
+ bodystmt k_end
1153
1208
  {
1154
1209
  result = new_module val
1155
1210
  self.env.unextend
1156
1211
  self.lexer.comments # we don't care about comments in the body
1157
1212
  }
1158
- | kDEF fname
1213
+ | k_def fname
1159
1214
  {
1160
1215
  result = [self.in_def, self.lexer.cmdarg.stack.dup]
1161
1216
 
@@ -1166,7 +1221,7 @@ rule
1166
1221
  # TODO: port local_push_gen and local_pop_gen
1167
1222
  lexer.cmdarg.stack.replace [false]
1168
1223
  }
1169
- f_arglist bodystmt kEND
1224
+ f_arglist bodystmt k_end
1170
1225
  {
1171
1226
  in_def, cmdarg = val[2]
1172
1227
 
@@ -1177,7 +1232,7 @@ rule
1177
1232
  self.in_def = in_def
1178
1233
  self.lexer.comments # we don't care about comments in the body
1179
1234
  }
1180
- | kDEF singleton dot_or_colon
1235
+ | k_def singleton dot_or_colon
1181
1236
  {
1182
1237
  self.comments.push self.lexer.comments
1183
1238
  lexer.lex_state = :expr_fname
@@ -1190,7 +1245,7 @@ rule
1190
1245
  result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
1191
1246
  lexer.cmdarg.stack.replace [false]
1192
1247
  }
1193
- f_arglist bodystmt kEND
1248
+ f_arglist bodystmt k_end
1194
1249
  {
1195
1250
  line, cmdarg = val[5]
1196
1251
  result = new_defs val
@@ -1235,7 +1290,15 @@ rule
1235
1290
  k_class: kCLASS
1236
1291
  k_module: kMODULE
1237
1292
  k_def: kDEF
1293
+ k_do: kDO
1294
+ k_do_block: kDO_BLOCK
1295
+ k_rescue: kRESCUE
1296
+ k_ensure: kENSURE
1297
+ k_when: kWHEN
1298
+ k_else: kELSE
1299
+ k_elsif: kELSIF
1238
1300
  k_end: kEND
1301
+ k_return: kRETURN
1239
1302
 
1240
1303
  then: term
1241
1304
  | kTHEN
@@ -1245,7 +1308,7 @@ rule
1245
1308
  | kDO_COND
1246
1309
 
1247
1310
  if_tail: opt_else
1248
- | kELSIF expr_value then compstmt if_tail
1311
+ | k_elsif expr_value then compstmt if_tail
1249
1312
  {
1250
1313
  result = s(:if, val[1], val[3], val[4])
1251
1314
  }
@@ -1416,18 +1479,22 @@ opt_block_args_tail: tCOMMA block_args_tail
1416
1479
 
1417
1480
  opt_block_param: none { result = 0 }
1418
1481
  | block_param_def
1482
+ {
1483
+ self.lexer.command_start = true
1484
+ }
1419
1485
 
1420
1486
  block_param_def: tPIPE opt_bv_decl tPIPE
1421
1487
  {
1488
+ # TODO: current_arg = 0
1422
1489
  result = args val
1423
1490
  }
1424
1491
  | tOROP
1425
1492
  {
1426
- self.lexer.command_start = true
1427
1493
  result = s(:args)
1428
1494
  }
1429
1495
  | tPIPE block_param opt_bv_decl tPIPE
1430
1496
  {
1497
+ # TODO: current_arg = 0
1431
1498
  result = args val
1432
1499
  }
1433
1500
 
@@ -1460,13 +1527,21 @@ opt_block_args_tail: tCOMMA block_args_tail
1460
1527
  lexer.paren_nest += 1
1461
1528
  lexer.lpar_beg = lexer.paren_nest
1462
1529
  }
1463
- f_larglist lambda_body
1530
+ f_larglist
1531
+ {
1532
+ result = [lexer.cmdarg.store(false), self.lexer.lineno]
1533
+ }
1534
+ lambda_body
1464
1535
  {
1465
- lpar, args, body = val
1536
+ lpar, args, (cmdarg, lineno), body = val
1466
1537
  lexer.lpar_beg = lpar
1467
1538
 
1539
+ lexer.cmdarg.restore cmdarg
1540
+ lexer.cmdarg.lexpop
1541
+
1468
1542
  call = new_call nil, :lambda
1469
1543
  result = new_iter call, args, body
1544
+ result.line = lineno
1470
1545
  self.env.unextend
1471
1546
  }
1472
1547
 
@@ -1484,28 +1559,15 @@ opt_block_args_tail: tCOMMA block_args_tail
1484
1559
  {
1485
1560
  result = val[1]
1486
1561
  }
1487
- | kDO_LAMBDA compstmt kEND
1562
+ | kDO_LAMBDA bodystmt kEND
1488
1563
  {
1489
1564
  result = val[1]
1490
1565
  }
1491
1566
 
1492
- do_block: kDO_BLOCK
1567
+ do_block: k_do_block do_body kEND
1493
1568
  {
1494
- self.env.extend :dynamic
1495
- result = self.lexer.lineno
1496
- }
1497
- opt_block_param
1498
- {
1499
- result = nil # self.env.dynamic.keys
1500
- }
1501
- compstmt kEND
1502
- {
1503
- args = val[2]
1504
- body = val[4]
1505
- result = new_iter nil, args, body
1506
- result.line = val[1]
1507
-
1508
- self.env.unextend
1569
+ # TODO: maybe fix lineno to kDO's lineno?
1570
+ result = val[1]
1509
1571
  }
1510
1572
 
1511
1573
  block_call: command do_block
@@ -1522,11 +1584,11 @@ opt_block_args_tail: tCOMMA block_args_tail
1522
1584
  result = val[1]
1523
1585
  result.insert 1, val[0]
1524
1586
  }
1525
- | block_call dot_or_colon operation2 opt_paren_args
1587
+ | block_call call_op2 operation2 opt_paren_args
1526
1588
  {
1527
1589
  result = new_call val[0], val[2].to_sym, val[3]
1528
1590
  }
1529
- | block_call dot_or_colon operation2 opt_paren_args brace_block
1591
+ | block_call call_op2 operation2 opt_paren_args brace_block
1530
1592
  {
1531
1593
  iter1, _, name, args, iter2 = val
1532
1594
 
@@ -1535,7 +1597,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1535
1597
 
1536
1598
  result = iter2
1537
1599
  }
1538
- | block_call dot_or_colon operation2 command_args do_block
1600
+ | block_call call_op2 operation2 command_args do_block
1539
1601
  {
1540
1602
  iter1, _, name, args, iter2 = val
1541
1603
 
@@ -1592,39 +1654,55 @@ opt_block_args_tail: tCOMMA block_args_tail
1592
1654
  self.env.extend :dynamic
1593
1655
  result = self.lexer.lineno
1594
1656
  }
1595
- opt_block_param
1596
- {
1597
- result = nil # self.env.dynamic.keys
1598
- }
1599
- compstmt tRCURLY
1657
+ brace_body tRCURLY
1600
1658
  {
1601
- _, line, args, _, body, _ = val
1659
+ _, line, body, _ = val
1602
1660
 
1603
- result = new_iter nil, args, body
1661
+ result = body
1604
1662
  result.line = line
1605
1663
 
1606
1664
  self.env.unextend
1607
1665
  }
1608
- | kDO
1666
+ | k_do
1609
1667
  {
1610
1668
  self.env.extend :dynamic
1611
1669
  result = self.lexer.lineno
1612
1670
  }
1613
- opt_block_param
1671
+ do_body kEND
1614
1672
  {
1615
- result = nil # self.env.dynamic.keys
1673
+ _, line, body, _ = val
1674
+
1675
+ result = body
1676
+ result.line = line
1677
+
1678
+ self.env.unextend
1616
1679
  }
1617
- compstmt kEND
1680
+
1681
+ brace_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1682
+ { result = lexer.cmdarg.store(false) }
1683
+ opt_block_param compstmt
1618
1684
  {
1619
- _, line, args, _, body, _ = val
1685
+ line, cmdarg, param, cmpstmt = val
1620
1686
 
1621
- result = new_iter nil, args, body
1622
- result.line = line
1687
+ result = new_brace_body param, cmpstmt, line
1688
+ self.env.unextend
1689
+ lexer.cmdarg.restore cmdarg
1690
+ lexer.cmdarg.pop # because of: cmdarg_stack >> 1 ?
1691
+ }
1692
+
1693
+ do_body: { self.env.extend :dynamic; result = self.lexer.lineno }
1694
+ { result = lexer.cmdarg.store(false) }
1695
+ opt_block_param
1696
+ compstmt
1697
+ {
1698
+ line, cmdarg, param, cmpstmt = val
1623
1699
 
1700
+ result = new_do_body param, cmpstmt, line
1624
1701
  self.env.unextend
1702
+ lexer.cmdarg.restore cmdarg
1625
1703
  }
1626
1704
 
1627
- case_body: kWHEN
1705
+ case_body: k_when
1628
1706
  {
1629
1707
  result = self.lexer.lineno
1630
1708
  }
@@ -1637,7 +1715,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1637
1715
 
1638
1716
  cases: opt_else | case_body
1639
1717
 
1640
- opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1718
+ opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
1641
1719
  {
1642
1720
  (_, line), klasses, var, _, body, rest = val
1643
1721
 
@@ -1666,7 +1744,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1666
1744
  }
1667
1745
  | none
1668
1746
 
1669
- opt_ensure: kENSURE compstmt
1747
+ opt_ensure: k_ensure compstmt
1670
1748
  {
1671
1749
  _, body = val
1672
1750
 
@@ -1833,7 +1911,7 @@ regexp_contents: none
1833
1911
  result = lexer.lex_strterm
1834
1912
 
1835
1913
  lexer.lex_strterm = nil
1836
- lexer.lex_state = :expr_beg # TODO: expr_value ?
1914
+ lexer.lex_state = :expr_beg
1837
1915
  }
1838
1916
  string_dvar
1839
1917
  {
@@ -1854,11 +1932,11 @@ regexp_contents: none
1854
1932
  lexer.brace_nest = 0
1855
1933
  lexer.string_nest = 0
1856
1934
 
1857
- lexer.lex_state = :expr_value
1935
+ lexer.lex_state = :expr_beg
1858
1936
  }
1859
- compstmt tRCURLY
1937
+ compstmt
1938
+ tSTRING_DEND
1860
1939
  {
1861
- # TODO: tRCURLY -> tSTRING_END
1862
1940
  _, memo, stmt, _ = val
1863
1941
 
1864
1942
  lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg, oldlex_state = memo
@@ -1981,23 +2059,18 @@ keyword_variable: kNIL { result = s(:nil) }
1981
2059
  backref: tNTH_REF { result = s(:nth_ref, val[0]) }
1982
2060
  | tBACK_REF { result = s(:back_ref, val[0]) }
1983
2061
 
1984
- superclass: term
1985
- {
1986
- result = nil
1987
- }
1988
- | tLT
2062
+ superclass: tLT
1989
2063
  {
1990
2064
  lexer.lex_state = :expr_beg
2065
+ lexer.command_start = true
1991
2066
  }
1992
2067
  expr_value term
1993
2068
  {
1994
2069
  result = val[2]
1995
2070
  }
1996
- | error term
2071
+ | none
1997
2072
  {
1998
- yyerrok
1999
2073
  result = nil
2000
- debug20 30, val, result
2001
2074
  }
2002
2075
 
2003
2076
  f_arglist: tLPAREN2 f_args rparen
@@ -2005,16 +2078,20 @@ keyword_variable: kNIL { result = s(:nil) }
2005
2078
  result = val[1]
2006
2079
  self.lexer.lex_state = :expr_beg
2007
2080
  self.lexer.command_start = true
2008
- # TODO:
2009
- # $<num>$ = parser->parser_in_kwarg;
2010
- # parser->parser_in_kwarg = 1;
2011
2081
  }
2012
- | f_args term
2082
+ | {
2083
+ result = self.in_kwarg
2084
+ self.in_kwarg = true
2085
+ # TODO: self.lexer.lex_state |= :expr_label
2086
+ }
2087
+ f_args term
2013
2088
  {
2014
- # TODO: parser->parser_in_kwarg = $<num>1;
2015
- result = val[0]
2016
- self.lexer.lex_state = :expr_beg
2017
- self.lexer.command_start = true
2089
+ kwarg, args, _ = val
2090
+
2091
+ self.in_kwarg = kwarg
2092
+ result = args
2093
+ lexer.lex_state = :expr_beg
2094
+ lexer.command_start = true
2018
2095
  }
2019
2096
 
2020
2097
  args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
@@ -2217,7 +2294,9 @@ keyword_variable: kNIL { result = s(:nil) }
2217
2294
 
2218
2295
  f_kwrest: kwrest_mark tIDENTIFIER
2219
2296
  {
2220
- result = :"**#{val[1]}"
2297
+ name = val[1].to_sym
2298
+ self.assignable name
2299
+ result = :"**#{name}"
2221
2300
  }
2222
2301
  | kwrest_mark
2223
2302
  {
@@ -2324,9 +2403,10 @@ keyword_variable: kNIL { result = s(:nil) }
2324
2403
  {
2325
2404
  result = s(:array, val[0], val[2])
2326
2405
  }
2327
- | tLABEL opt_nl arg_value
2406
+ | tLABEL arg_value
2328
2407
  {
2329
- result = s(:array, s(:lit, val[0][0].to_sym), val.last)
2408
+ (label, _), arg = val
2409
+ result = s(:array, s(:lit, label.to_sym), arg)
2330
2410
  }
2331
2411
  | tSTRING_BEG string_contents tLABEL_END arg_value
2332
2412
  {
@@ -2334,11 +2414,6 @@ keyword_variable: kNIL { result = s(:nil) }
2334
2414
  sym.sexp_type = :dsym
2335
2415
  result = s(:array, sym, value)
2336
2416
  }
2337
- | tSYMBOL arg_value
2338
- {
2339
- raise "not yet: #{val.inspect}"
2340
- # result = s(:array, s(:lit, val[1].to_sym), val[1])
2341
- }
2342
2417
  | tDSTAR arg_value
2343
2418
  {
2344
2419
  result = s(:array, s(:kwsplat, val[1]))
@@ -2349,6 +2424,10 @@ keyword_variable: kNIL { result = s(:nil) }
2349
2424
  operation3: tIDENTIFIER | tFID | op
2350
2425
  dot_or_colon: tDOT | tCOLON2
2351
2426
  call_op: tDOT
2427
+
2428
+ call_op2: call_op
2429
+ | tCOLON2
2430
+
2352
2431
  opt_terms: | terms
2353
2432
  opt_nl: | tNL
2354
2433
  rparen: opt_nl tRPAREN