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