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