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/ruby20_parser.y
CHANGED
@@ -85,14 +85,35 @@ rule
|
|
85
85
|
end
|
86
86
|
self.env.extend
|
87
87
|
}
|
88
|
-
|
88
|
+
begin_block
|
89
89
|
{
|
90
|
-
|
90
|
+
_, _, block = val
|
91
|
+
result = block
|
92
|
+
}
|
93
|
+
|
94
|
+
begin_block: tLCURLY top_compstmt tRCURLY
|
95
|
+
{
|
96
|
+
_, stmt, _ = val
|
97
|
+
result = new_iter s(:preexe), 0, stmt
|
91
98
|
}
|
92
99
|
|
93
|
-
bodystmt: compstmt opt_rescue
|
100
|
+
bodystmt: compstmt opt_rescue k_else
|
94
101
|
{
|
95
|
-
|
102
|
+
res = _values[-2]
|
103
|
+
yyerror "else without rescue is useless" unless res
|
104
|
+
}
|
105
|
+
compstmt
|
106
|
+
opt_ensure
|
107
|
+
{
|
108
|
+
body, resc, _, _, els, ens = val
|
109
|
+
|
110
|
+
result = new_body [body, resc, els, ens]
|
111
|
+
}
|
112
|
+
| compstmt opt_rescue opt_ensure
|
113
|
+
{
|
114
|
+
body, resc, ens = val
|
115
|
+
|
116
|
+
result = new_body [body, resc, nil, ens]
|
96
117
|
}
|
97
118
|
|
98
119
|
compstmt: stmts opt_terms
|
@@ -101,8 +122,8 @@ rule
|
|
101
122
|
}
|
102
123
|
|
103
124
|
stmts: none
|
104
|
-
|
|
105
|
-
| stmts terms
|
125
|
+
| stmt_or_begin # TODO: newline_node ?
|
126
|
+
| stmts terms stmt_or_begin
|
106
127
|
{
|
107
128
|
result = self.block_append val[0], val[2]
|
108
129
|
}
|
@@ -112,6 +133,21 @@ rule
|
|
112
133
|
debug20 2, val, result
|
113
134
|
}
|
114
135
|
|
136
|
+
stmt_or_begin: stmt
|
137
|
+
| klBEGIN
|
138
|
+
{
|
139
|
+
if (self.in_def || self.in_single > 0) then
|
140
|
+
debug20 1
|
141
|
+
yyerror "BEGIN in method"
|
142
|
+
end
|
143
|
+
self.env.extend
|
144
|
+
}
|
145
|
+
begin_block
|
146
|
+
{
|
147
|
+
_, _, stmt = val
|
148
|
+
result = stmt
|
149
|
+
}
|
150
|
+
|
115
151
|
stmt: kALIAS fitem
|
116
152
|
{
|
117
153
|
lexer.lex_state = :expr_fname
|
@@ -155,7 +191,8 @@ rule
|
|
155
191
|
}
|
156
192
|
| stmt kRESCUE_MOD stmt
|
157
193
|
{
|
158
|
-
|
194
|
+
body, _, resbody = val
|
195
|
+
result = new_rescue body, new_resbody(s(:array), resbody)
|
159
196
|
}
|
160
197
|
| klEND tLCURLY compstmt tRCURLY
|
161
198
|
{
|
@@ -170,15 +207,37 @@ rule
|
|
170
207
|
{
|
171
208
|
result = new_masgn val[0], val[2], :wrap
|
172
209
|
}
|
173
|
-
|
|
210
|
+
| lhs tEQL mrhs
|
211
|
+
{
|
212
|
+
result = new_assign val[0], s(:svalue, val[2])
|
213
|
+
}
|
214
|
+
| mlhs tEQL arg_value
|
215
|
+
{
|
216
|
+
result = new_masgn val[0], val[2], :wrap
|
217
|
+
}
|
218
|
+
| mlhs tEQL mrhs
|
219
|
+
{
|
220
|
+
result = new_masgn val[0], val[2]
|
221
|
+
}
|
222
|
+
| expr
|
223
|
+
|
224
|
+
command_asgn: lhs tEQL command_rhs
|
225
|
+
{
|
226
|
+
result = new_assign val[0], val[2]
|
227
|
+
}
|
228
|
+
# | lhs tEQL command_asgn
|
229
|
+
# {
|
230
|
+
# result = new_assign val[0], val[2]
|
231
|
+
# }
|
232
|
+
| var_lhs tOP_ASGN command_rhs
|
174
233
|
{
|
175
234
|
result = new_op_asgn val
|
176
235
|
}
|
177
|
-
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN
|
236
|
+
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN command_rhs
|
178
237
|
{
|
179
238
|
result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
|
180
239
|
}
|
181
|
-
| primary_value call_op tIDENTIFIER tOP_ASGN
|
240
|
+
| primary_value call_op tIDENTIFIER tOP_ASGN command_rhs
|
182
241
|
{
|
183
242
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
184
243
|
if val[1] == '&.'
|
@@ -186,7 +245,7 @@ rule
|
|
186
245
|
end
|
187
246
|
result.line = val[0].line
|
188
247
|
}
|
189
|
-
| primary_value call_op tCONSTANT tOP_ASGN
|
248
|
+
| primary_value call_op tCONSTANT tOP_ASGN command_rhs
|
190
249
|
{
|
191
250
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
192
251
|
if val[1] == '&.'
|
@@ -194,42 +253,33 @@ rule
|
|
194
253
|
end
|
195
254
|
result.line = val[0].line
|
196
255
|
}
|
197
|
-
| primary_value tCOLON2 tCONSTANT tOP_ASGN
|
256
|
+
| primary_value tCOLON2 tCONSTANT tOP_ASGN command_rhs
|
198
257
|
{
|
199
258
|
result = s(:op_asgn, val[0], val[4], val[2], val[3])
|
200
259
|
debug20 4, val, result
|
201
260
|
}
|
202
|
-
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN
|
261
|
+
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_rhs
|
203
262
|
{
|
204
263
|
result = s(:op_asgn, val[0], val[4], val[2], val[3])
|
205
264
|
debug20 5, val, result
|
206
265
|
}
|
207
|
-
| backref tOP_ASGN
|
266
|
+
| backref tOP_ASGN command_rhs
|
208
267
|
{
|
209
268
|
self.backref_assign_error val[0]
|
210
269
|
}
|
211
|
-
| lhs tEQL mrhs
|
212
|
-
{
|
213
|
-
result = new_assign val[0], s(:svalue, val[2])
|
214
|
-
}
|
215
|
-
| mlhs tEQL arg_value
|
216
|
-
{
|
217
|
-
result = new_masgn val[0], val[2], :wrap
|
218
|
-
}
|
219
|
-
| mlhs tEQL mrhs
|
220
|
-
{
|
221
|
-
result = new_masgn val[0], val[2]
|
222
|
-
}
|
223
|
-
| expr
|
224
270
|
|
225
|
-
|
271
|
+
command_rhs: command_call =tOP_ASGN
|
226
272
|
{
|
227
|
-
|
273
|
+
expr, = val
|
274
|
+
result = value_expr expr
|
228
275
|
}
|
229
|
-
|
|
276
|
+
| command_call kRESCUE_MOD stmt
|
230
277
|
{
|
231
|
-
|
278
|
+
expr, _, resbody = val
|
279
|
+
expr = value_expr expr
|
280
|
+
result = new_rescue(expr, new_resbody(s(:array), resbody))
|
232
281
|
}
|
282
|
+
| command_asgn
|
233
283
|
|
234
284
|
expr: command_call
|
235
285
|
| expr kAND expr
|
@@ -255,30 +305,40 @@ rule
|
|
255
305
|
result = value_expr(val[0])
|
256
306
|
}
|
257
307
|
|
308
|
+
expr_value_do: {
|
309
|
+
lexer.cond.push true
|
310
|
+
}
|
311
|
+
expr_value do
|
312
|
+
{
|
313
|
+
lexer.cond.pop
|
314
|
+
}
|
315
|
+
{
|
316
|
+
_, expr, _, _ = val
|
317
|
+
result = expr
|
318
|
+
}
|
319
|
+
|
258
320
|
command_call: command
|
259
321
|
| block_command
|
260
322
|
|
261
323
|
block_command: block_call
|
262
|
-
| block_call
|
324
|
+
| block_call call_op2 operation2 command_args
|
263
325
|
{
|
264
326
|
result = new_call val[0], val[2].to_sym, val[3]
|
265
327
|
}
|
266
328
|
|
267
329
|
cmd_brace_block: tLBRACE_ARG
|
268
330
|
{
|
269
|
-
self.env.extend(:dynamic)
|
331
|
+
# self.env.extend(:dynamic)
|
270
332
|
result = self.lexer.lineno
|
271
333
|
}
|
272
|
-
|
273
|
-
{
|
274
|
-
result = nil # self.env.dynamic.keys
|
275
|
-
}
|
276
|
-
compstmt tRCURLY
|
334
|
+
brace_body tRCURLY
|
277
335
|
{
|
278
|
-
|
279
|
-
result.line = val[1]
|
336
|
+
_, line, body, _ = val
|
280
337
|
|
281
|
-
|
338
|
+
result = body
|
339
|
+
result.line = line
|
340
|
+
|
341
|
+
# self.env.unextend
|
282
342
|
}
|
283
343
|
|
284
344
|
fcall: operation
|
@@ -336,7 +396,7 @@ rule
|
|
336
396
|
{
|
337
397
|
result = new_yield val[1]
|
338
398
|
}
|
339
|
-
|
|
399
|
+
| k_return call_args
|
340
400
|
{
|
341
401
|
line = val[0].last
|
342
402
|
result = s(:return, ret_args(val[1])).line(line)
|
@@ -560,8 +620,9 @@ rule
|
|
560
620
|
|
561
621
|
| reswords
|
562
622
|
{
|
623
|
+
(sym, _line), = val
|
563
624
|
lexer.lex_state = :expr_end
|
564
|
-
result =
|
625
|
+
result = sym
|
565
626
|
}
|
566
627
|
|
567
628
|
fsym: fname | symbol
|
@@ -603,51 +664,46 @@ rule
|
|
603
664
|
| kWHEN | kYIELD | kIF | kUNLESS | kWHILE
|
604
665
|
| kUNTIL
|
605
666
|
|
606
|
-
arg: lhs tEQL
|
667
|
+
arg: lhs tEQL arg_rhs
|
607
668
|
{
|
608
669
|
result = new_assign val[0], val[2]
|
609
670
|
}
|
610
|
-
|
|
611
|
-
{
|
612
|
-
result = new_assign val[0], s(:rescue, val[2], new_resbody(s(:array), val[4]))
|
613
|
-
}
|
614
|
-
| var_lhs tOP_ASGN arg
|
671
|
+
| var_lhs tOP_ASGN arg_rhs
|
615
672
|
{
|
616
673
|
result = new_op_asgn val
|
617
674
|
}
|
618
|
-
|
|
619
|
-
{
|
620
|
-
result = new_op_asgn val
|
621
|
-
result = s(:rescue, result, new_resbody(s(:array), val[4]))
|
622
|
-
}
|
623
|
-
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
|
675
|
+
| primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg_rhs
|
624
676
|
{
|
625
677
|
val[2].sexp_type = :arglist if val[2]
|
626
678
|
result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
|
627
679
|
}
|
628
|
-
| primary_value call_op tIDENTIFIER tOP_ASGN
|
680
|
+
| primary_value call_op tIDENTIFIER tOP_ASGN arg_rhs
|
629
681
|
{
|
630
682
|
result = new_op_asgn2 val
|
631
683
|
}
|
632
|
-
| primary_value call_op tCONSTANT tOP_ASGN
|
684
|
+
| primary_value call_op tCONSTANT tOP_ASGN arg_rhs
|
633
685
|
{
|
634
686
|
result = new_op_asgn2 val
|
635
687
|
}
|
636
|
-
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN
|
688
|
+
| primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg_rhs
|
637
689
|
{
|
638
690
|
result = s(:op_asgn, val[0], val[4], val[2].to_sym, val[3].to_sym)
|
639
691
|
}
|
640
|
-
| primary_value tCOLON2 tCONSTANT tOP_ASGN
|
692
|
+
| primary_value tCOLON2 tCONSTANT tOP_ASGN arg_rhs
|
641
693
|
{
|
642
|
-
|
694
|
+
# TODO: assignment
|
695
|
+
raise "not yet: %p" % [val]
|
643
696
|
}
|
644
|
-
| tCOLON3 tCONSTANT tOP_ASGN
|
697
|
+
| tCOLON3 tCONSTANT tOP_ASGN arg_rhs
|
645
698
|
{
|
646
|
-
|
699
|
+
# TODO: assignment
|
700
|
+
raise "not yet: %p" % [val]
|
647
701
|
}
|
648
|
-
| backref tOP_ASGN
|
702
|
+
| backref tOP_ASGN arg_rhs
|
649
703
|
{
|
650
|
-
|
704
|
+
# TODO: lhs = var_field val[0]
|
705
|
+
asgn = new_op_asgn val
|
706
|
+
result = self.backref_assign_error asgn
|
651
707
|
}
|
652
708
|
| arg tDOT2 arg
|
653
709
|
{
|
@@ -725,22 +781,7 @@ rule
|
|
725
781
|
{
|
726
782
|
result = new_call val[0], :"<=>", argl(val[2])
|
727
783
|
}
|
728
|
-
|
|
729
|
-
{
|
730
|
-
result = new_call val[0], :">", argl(val[2])
|
731
|
-
}
|
732
|
-
| arg tGEQ arg
|
733
|
-
{
|
734
|
-
result = new_call val[0], :">=", argl(val[2])
|
735
|
-
}
|
736
|
-
| arg tLT arg
|
737
|
-
{
|
738
|
-
result = new_call val[0], :"<", argl(val[2])
|
739
|
-
}
|
740
|
-
| arg tLEQ arg
|
741
|
-
{
|
742
|
-
result = new_call val[0], :"<=", argl(val[2])
|
743
|
-
}
|
784
|
+
| rel_expr =tCMP
|
744
785
|
| arg tEQ arg
|
745
786
|
{
|
746
787
|
result = new_call val[0], :"==", argl(val[2])
|
@@ -799,6 +840,23 @@ rule
|
|
799
840
|
}
|
800
841
|
| primary
|
801
842
|
|
843
|
+
relop: tGT
|
844
|
+
| tLT
|
845
|
+
| tGEQ
|
846
|
+
| tLEQ
|
847
|
+
|
848
|
+
rel_expr: arg relop arg =tGT
|
849
|
+
{
|
850
|
+
lhs, op, rhs = val
|
851
|
+
result = new_call lhs, op.to_sym, argl(rhs)
|
852
|
+
}
|
853
|
+
| rel_expr relop arg =tGT
|
854
|
+
{
|
855
|
+
lhs, op, rhs = val
|
856
|
+
warn "comparison '%s' after comparison", op
|
857
|
+
result = new_call lhs, op.to_sym, argl(rhs)
|
858
|
+
}
|
859
|
+
|
802
860
|
arg_value: arg
|
803
861
|
{
|
804
862
|
result = value_expr(val[0])
|
@@ -818,6 +876,15 @@ rule
|
|
818
876
|
result = args [array_to_hash(val[0])]
|
819
877
|
}
|
820
878
|
|
879
|
+
arg_rhs: arg =tOP_ASGN
|
880
|
+
| arg kRESCUE_MOD arg
|
881
|
+
{
|
882
|
+
body, _, resbody = val
|
883
|
+
body = value_expr body
|
884
|
+
resbody = remove_begin resbody
|
885
|
+
result = new_rescue(body, new_resbody(s(:array), resbody))
|
886
|
+
}
|
887
|
+
|
821
888
|
paren_args: tLPAREN2 opt_call_args rparen
|
822
889
|
{
|
823
890
|
result = val[1]
|
@@ -873,12 +940,11 @@ rule
|
|
873
940
|
}
|
874
941
|
|
875
942
|
command_args: {
|
876
|
-
result = lexer.cmdarg.
|
877
|
-
lexer.cmdarg.push true
|
943
|
+
result = lexer.cmdarg.store true
|
878
944
|
}
|
879
945
|
call_args
|
880
946
|
{
|
881
|
-
lexer.cmdarg.
|
947
|
+
lexer.cmdarg.restore val[0]
|
882
948
|
result = val[1]
|
883
949
|
}
|
884
950
|
|
@@ -937,12 +1003,16 @@ rule
|
|
937
1003
|
{
|
938
1004
|
result = new_call nil, val[0].to_sym
|
939
1005
|
}
|
940
|
-
|
|
1006
|
+
| k_begin
|
941
1007
|
{
|
942
1008
|
result = self.lexer.lineno
|
1009
|
+
# TODO:
|
1010
|
+
# $<val>1 = cmdarg_stack;
|
1011
|
+
# CMDARG_SET(0);
|
943
1012
|
}
|
944
|
-
bodystmt
|
1013
|
+
bodystmt k_end
|
945
1014
|
{
|
1015
|
+
# TODO: CMDARG_SET($<val>1);
|
946
1016
|
unless val[2] then
|
947
1017
|
result = s(:nil)
|
948
1018
|
else
|
@@ -953,22 +1023,25 @@ rule
|
|
953
1023
|
}
|
954
1024
|
| tLPAREN_ARG rparen
|
955
1025
|
{
|
1026
|
+
# TODO: lex_state = :expr_endarg in between
|
956
1027
|
debug20 13, val, result
|
957
1028
|
}
|
958
1029
|
| tLPAREN_ARG
|
959
1030
|
{
|
960
|
-
result =
|
961
|
-
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
|
962
1034
|
}
|
963
|
-
|
1035
|
+
stmt
|
964
1036
|
{
|
965
1037
|
lexer.lex_state = :expr_endarg
|
966
1038
|
}
|
967
1039
|
rparen
|
968
1040
|
{
|
1041
|
+
_, cmdarg, stmt, _, _, = val
|
969
1042
|
warning "(...) interpreted as grouped expression"
|
970
|
-
lexer.cmdarg.
|
971
|
-
result =
|
1043
|
+
lexer.cmdarg.restore cmdarg
|
1044
|
+
result = stmt
|
972
1045
|
}
|
973
1046
|
| tLPAREN compstmt tRPAREN
|
974
1047
|
{
|
@@ -996,7 +1069,7 @@ rule
|
|
996
1069
|
{
|
997
1070
|
result = new_hash val
|
998
1071
|
}
|
999
|
-
|
|
1072
|
+
| k_return
|
1000
1073
|
{
|
1001
1074
|
result = s(:return)
|
1002
1075
|
}
|
@@ -1044,61 +1117,42 @@ rule
|
|
1044
1117
|
{
|
1045
1118
|
result = val[1] # TODO: fix lineno
|
1046
1119
|
}
|
1047
|
-
|
|
1048
|
-
{
|
1049
|
-
result = new_if val[1], val[3], val[4]
|
1050
|
-
}
|
1051
|
-
| kUNLESS expr_value then compstmt opt_else kEND
|
1052
|
-
{
|
1053
|
-
result = new_if val[1], val[4], val[3]
|
1054
|
-
}
|
1055
|
-
| kWHILE
|
1056
|
-
{
|
1057
|
-
lexer.cond.push true
|
1058
|
-
}
|
1059
|
-
expr_value do
|
1060
|
-
{
|
1061
|
-
lexer.cond.pop
|
1062
|
-
}
|
1063
|
-
compstmt kEND
|
1120
|
+
| k_if expr_value then compstmt if_tail k_end
|
1064
1121
|
{
|
1065
|
-
|
1122
|
+
_, c, _, t, f, _ = val
|
1123
|
+
result = new_if c, t, f
|
1066
1124
|
}
|
1067
|
-
|
|
1125
|
+
| k_unless expr_value then compstmt opt_else k_end
|
1068
1126
|
{
|
1069
|
-
|
1127
|
+
_, c, _, t, f, _ = val
|
1128
|
+
result = new_if c, f, t
|
1070
1129
|
}
|
1071
|
-
|
1130
|
+
| k_while expr_value_do compstmt k_end
|
1072
1131
|
{
|
1073
|
-
|
1132
|
+
_, cond, body, _ = val
|
1133
|
+
result = new_while body, cond, true
|
1074
1134
|
}
|
1075
|
-
|
1135
|
+
| k_until expr_value_do compstmt k_end
|
1076
1136
|
{
|
1077
|
-
|
1137
|
+
_, cond, body, _ = val
|
1138
|
+
result = new_until body, cond, true
|
1078
1139
|
}
|
1079
|
-
|
|
1140
|
+
| k_case expr_value opt_terms case_body k_end
|
1080
1141
|
{
|
1081
1142
|
(_, line), expr, _, body, _ = val
|
1082
1143
|
result = new_case expr, body, line
|
1083
1144
|
}
|
1084
|
-
|
|
1145
|
+
| k_case opt_terms case_body k_end
|
1085
1146
|
{
|
1086
1147
|
(_, line), _, body, _ = val
|
1087
1148
|
result = new_case nil, body, line
|
1088
1149
|
}
|
1089
|
-
|
|
1150
|
+
| k_for for_var kIN expr_value_do compstmt k_end
|
1090
1151
|
{
|
1091
|
-
|
1152
|
+
_, var, _, iter, body, _ = val
|
1153
|
+
result = new_for iter, var, body
|
1092
1154
|
}
|
1093
|
-
|
1094
|
-
{
|
1095
|
-
lexer.cond.pop
|
1096
|
-
}
|
1097
|
-
compstmt kEND
|
1098
|
-
{
|
1099
|
-
result = new_for val[4], val[1], val[7]
|
1100
|
-
}
|
1101
|
-
| kCLASS
|
1155
|
+
| k_class
|
1102
1156
|
{
|
1103
1157
|
result = self.lexer.lineno
|
1104
1158
|
}
|
@@ -1110,13 +1164,13 @@ rule
|
|
1110
1164
|
end
|
1111
1165
|
self.env.extend
|
1112
1166
|
}
|
1113
|
-
bodystmt
|
1167
|
+
bodystmt k_end
|
1114
1168
|
{
|
1115
1169
|
result = new_class val
|
1116
1170
|
self.env.unextend
|
1117
1171
|
self.lexer.comments # we don't care about comments in the body
|
1118
1172
|
}
|
1119
|
-
|
|
1173
|
+
| k_class tLSHFT
|
1120
1174
|
{
|
1121
1175
|
result = self.lexer.lineno
|
1122
1176
|
}
|
@@ -1131,13 +1185,13 @@ rule
|
|
1131
1185
|
self.in_single = 0
|
1132
1186
|
self.env.extend
|
1133
1187
|
}
|
1134
|
-
bodystmt
|
1188
|
+
bodystmt k_end
|
1135
1189
|
{
|
1136
1190
|
result = new_sclass val
|
1137
1191
|
self.env.unextend
|
1138
1192
|
self.lexer.comments # we don't care about comments in the body
|
1139
1193
|
}
|
1140
|
-
|
|
1194
|
+
| k_module
|
1141
1195
|
{
|
1142
1196
|
result = self.lexer.lineno
|
1143
1197
|
}
|
@@ -1149,13 +1203,13 @@ rule
|
|
1149
1203
|
|
1150
1204
|
self.env.extend
|
1151
1205
|
}
|
1152
|
-
bodystmt
|
1206
|
+
bodystmt k_end
|
1153
1207
|
{
|
1154
1208
|
result = new_module val
|
1155
1209
|
self.env.unextend
|
1156
1210
|
self.lexer.comments # we don't care about comments in the body
|
1157
1211
|
}
|
1158
|
-
|
|
1212
|
+
| k_def fname
|
1159
1213
|
{
|
1160
1214
|
result = [self.in_def, self.lexer.cmdarg.stack.dup]
|
1161
1215
|
|
@@ -1166,7 +1220,7 @@ rule
|
|
1166
1220
|
# TODO: port local_push_gen and local_pop_gen
|
1167
1221
|
lexer.cmdarg.stack.replace [false]
|
1168
1222
|
}
|
1169
|
-
f_arglist bodystmt
|
1223
|
+
f_arglist bodystmt k_end
|
1170
1224
|
{
|
1171
1225
|
in_def, cmdarg = val[2]
|
1172
1226
|
|
@@ -1177,7 +1231,7 @@ rule
|
|
1177
1231
|
self.in_def = in_def
|
1178
1232
|
self.lexer.comments # we don't care about comments in the body
|
1179
1233
|
}
|
1180
|
-
|
|
1234
|
+
| k_def singleton dot_or_colon
|
1181
1235
|
{
|
1182
1236
|
self.comments.push self.lexer.comments
|
1183
1237
|
lexer.lex_state = :expr_fname
|
@@ -1190,7 +1244,7 @@ rule
|
|
1190
1244
|
result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
|
1191
1245
|
lexer.cmdarg.stack.replace [false]
|
1192
1246
|
}
|
1193
|
-
f_arglist bodystmt
|
1247
|
+
f_arglist bodystmt k_end
|
1194
1248
|
{
|
1195
1249
|
line, cmdarg = val[5]
|
1196
1250
|
result = new_defs val
|
@@ -1235,7 +1289,15 @@ rule
|
|
1235
1289
|
k_class: kCLASS
|
1236
1290
|
k_module: kMODULE
|
1237
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
|
1238
1299
|
k_end: kEND
|
1300
|
+
k_return: kRETURN
|
1239
1301
|
|
1240
1302
|
then: term
|
1241
1303
|
| kTHEN
|
@@ -1245,7 +1307,7 @@ rule
|
|
1245
1307
|
| kDO_COND
|
1246
1308
|
|
1247
1309
|
if_tail: opt_else
|
1248
|
-
|
|
1310
|
+
| k_elsif expr_value then compstmt if_tail
|
1249
1311
|
{
|
1250
1312
|
result = s(:if, val[1], val[3], val[4])
|
1251
1313
|
}
|
@@ -1416,18 +1478,22 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1416
1478
|
|
1417
1479
|
opt_block_param: none { result = 0 }
|
1418
1480
|
| block_param_def
|
1481
|
+
{
|
1482
|
+
self.lexer.command_start = true
|
1483
|
+
}
|
1419
1484
|
|
1420
1485
|
block_param_def: tPIPE opt_bv_decl tPIPE
|
1421
1486
|
{
|
1487
|
+
# TODO: current_arg = 0
|
1422
1488
|
result = args val
|
1423
1489
|
}
|
1424
1490
|
| tOROP
|
1425
1491
|
{
|
1426
|
-
self.lexer.command_start = true
|
1427
1492
|
result = s(:args)
|
1428
1493
|
}
|
1429
1494
|
| tPIPE block_param opt_bv_decl tPIPE
|
1430
1495
|
{
|
1496
|
+
# TODO: current_arg = 0
|
1431
1497
|
result = args val
|
1432
1498
|
}
|
1433
1499
|
|
@@ -1460,13 +1526,21 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1460
1526
|
lexer.paren_nest += 1
|
1461
1527
|
lexer.lpar_beg = lexer.paren_nest
|
1462
1528
|
}
|
1463
|
-
f_larglist
|
1529
|
+
f_larglist
|
1464
1530
|
{
|
1465
|
-
|
1531
|
+
result = [lexer.cmdarg.store(false), self.lexer.lineno]
|
1532
|
+
}
|
1533
|
+
lambda_body
|
1534
|
+
{
|
1535
|
+
lpar, args, (cmdarg, lineno), body = val
|
1466
1536
|
lexer.lpar_beg = lpar
|
1467
1537
|
|
1538
|
+
lexer.cmdarg.restore cmdarg
|
1539
|
+
lexer.cmdarg.lexpop
|
1540
|
+
|
1468
1541
|
call = new_call nil, :lambda
|
1469
1542
|
result = new_iter call, args, body
|
1543
|
+
result.line = lineno
|
1470
1544
|
self.env.unextend
|
1471
1545
|
}
|
1472
1546
|
|
@@ -1484,28 +1558,15 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1484
1558
|
{
|
1485
1559
|
result = val[1]
|
1486
1560
|
}
|
1487
|
-
| kDO_LAMBDA
|
1561
|
+
| kDO_LAMBDA bodystmt kEND
|
1488
1562
|
{
|
1489
1563
|
result = val[1]
|
1490
1564
|
}
|
1491
1565
|
|
1492
|
-
do_block:
|
1566
|
+
do_block: k_do_block do_body kEND
|
1493
1567
|
{
|
1494
|
-
|
1495
|
-
result =
|
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
|
1568
|
+
# TODO: maybe fix lineno to kDO's lineno?
|
1569
|
+
result = val[1]
|
1509
1570
|
}
|
1510
1571
|
|
1511
1572
|
block_call: command do_block
|
@@ -1522,11 +1583,11 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1522
1583
|
result = val[1]
|
1523
1584
|
result.insert 1, val[0]
|
1524
1585
|
}
|
1525
|
-
| block_call
|
1586
|
+
| block_call call_op2 operation2 opt_paren_args
|
1526
1587
|
{
|
1527
1588
|
result = new_call val[0], val[2].to_sym, val[3]
|
1528
1589
|
}
|
1529
|
-
| block_call
|
1590
|
+
| block_call call_op2 operation2 opt_paren_args brace_block
|
1530
1591
|
{
|
1531
1592
|
iter1, _, name, args, iter2 = val
|
1532
1593
|
|
@@ -1535,7 +1596,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1535
1596
|
|
1536
1597
|
result = iter2
|
1537
1598
|
}
|
1538
|
-
| block_call
|
1599
|
+
| block_call call_op2 operation2 command_args do_block
|
1539
1600
|
{
|
1540
1601
|
iter1, _, name, args, iter2 = val
|
1541
1602
|
|
@@ -1592,39 +1653,55 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1592
1653
|
self.env.extend :dynamic
|
1593
1654
|
result = self.lexer.lineno
|
1594
1655
|
}
|
1595
|
-
|
1596
|
-
{
|
1597
|
-
result = nil # self.env.dynamic.keys
|
1598
|
-
}
|
1599
|
-
compstmt tRCURLY
|
1656
|
+
brace_body tRCURLY
|
1600
1657
|
{
|
1601
|
-
_, line,
|
1658
|
+
_, line, body, _ = val
|
1602
1659
|
|
1603
|
-
result =
|
1660
|
+
result = body
|
1604
1661
|
result.line = line
|
1605
1662
|
|
1606
1663
|
self.env.unextend
|
1607
1664
|
}
|
1608
|
-
|
|
1665
|
+
| k_do
|
1609
1666
|
{
|
1610
1667
|
self.env.extend :dynamic
|
1611
1668
|
result = self.lexer.lineno
|
1612
1669
|
}
|
1613
|
-
|
1670
|
+
do_body kEND
|
1614
1671
|
{
|
1615
|
-
|
1672
|
+
_, line, body, _ = val
|
1673
|
+
|
1674
|
+
result = body
|
1675
|
+
result.line = line
|
1676
|
+
|
1677
|
+
self.env.unextend
|
1616
1678
|
}
|
1617
|
-
|
1679
|
+
|
1680
|
+
brace_body: { self.env.extend :dynamic; result = self.lexer.lineno }
|
1681
|
+
{ result = lexer.cmdarg.store(false) }
|
1682
|
+
opt_block_param compstmt
|
1618
1683
|
{
|
1619
|
-
|
1684
|
+
line, cmdarg, param, cmpstmt = val
|
1620
1685
|
|
1621
|
-
result =
|
1622
|
-
|
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
|
+
}
|
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
|
1623
1698
|
|
1699
|
+
result = new_do_body param, cmpstmt, line
|
1624
1700
|
self.env.unextend
|
1701
|
+
lexer.cmdarg.restore cmdarg
|
1625
1702
|
}
|
1626
1703
|
|
1627
|
-
case_body:
|
1704
|
+
case_body: k_when
|
1628
1705
|
{
|
1629
1706
|
result = self.lexer.lineno
|
1630
1707
|
}
|
@@ -1637,7 +1714,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1637
1714
|
|
1638
1715
|
cases: opt_else | case_body
|
1639
1716
|
|
1640
|
-
opt_rescue:
|
1717
|
+
opt_rescue: k_rescue exc_list exc_var then compstmt opt_rescue
|
1641
1718
|
{
|
1642
1719
|
(_, line), klasses, var, _, body, rest = val
|
1643
1720
|
|
@@ -1666,7 +1743,7 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1666
1743
|
}
|
1667
1744
|
| none
|
1668
1745
|
|
1669
|
-
opt_ensure:
|
1746
|
+
opt_ensure: k_ensure compstmt
|
1670
1747
|
{
|
1671
1748
|
_, body = val
|
1672
1749
|
|
@@ -1833,7 +1910,7 @@ regexp_contents: none
|
|
1833
1910
|
result = lexer.lex_strterm
|
1834
1911
|
|
1835
1912
|
lexer.lex_strterm = nil
|
1836
|
-
lexer.lex_state = :expr_beg
|
1913
|
+
lexer.lex_state = :expr_beg
|
1837
1914
|
}
|
1838
1915
|
string_dvar
|
1839
1916
|
{
|
@@ -1854,11 +1931,11 @@ regexp_contents: none
|
|
1854
1931
|
lexer.brace_nest = 0
|
1855
1932
|
lexer.string_nest = 0
|
1856
1933
|
|
1857
|
-
lexer.lex_state = :
|
1934
|
+
lexer.lex_state = :expr_beg
|
1858
1935
|
}
|
1859
|
-
compstmt
|
1936
|
+
compstmt
|
1937
|
+
tSTRING_DEND
|
1860
1938
|
{
|
1861
|
-
# TODO: tRCURLY -> tSTRING_DEND
|
1862
1939
|
_, memo, stmt, _ = val
|
1863
1940
|
|
1864
1941
|
lex_strterm, brace_nest, string_nest, oldcond, oldcmdarg, oldlex_state = memo
|
@@ -1981,23 +2058,18 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
1981
2058
|
backref: tNTH_REF { result = s(:nth_ref, val[0]) }
|
1982
2059
|
| tBACK_REF { result = s(:back_ref, val[0]) }
|
1983
2060
|
|
1984
|
-
superclass:
|
1985
|
-
{
|
1986
|
-
result = nil
|
1987
|
-
}
|
1988
|
-
| tLT
|
2061
|
+
superclass: tLT
|
1989
2062
|
{
|
1990
2063
|
lexer.lex_state = :expr_beg
|
2064
|
+
lexer.command_start = true
|
1991
2065
|
}
|
1992
2066
|
expr_value term
|
1993
2067
|
{
|
1994
2068
|
result = val[2]
|
1995
2069
|
}
|
1996
|
-
|
|
2070
|
+
| none
|
1997
2071
|
{
|
1998
|
-
yyerrok
|
1999
2072
|
result = nil
|
2000
|
-
debug20 30, val, result
|
2001
2073
|
}
|
2002
2074
|
|
2003
2075
|
f_arglist: tLPAREN2 f_args rparen
|
@@ -2005,16 +2077,20 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2005
2077
|
result = val[1]
|
2006
2078
|
self.lexer.lex_state = :expr_beg
|
2007
2079
|
self.lexer.command_start = true
|
2008
|
-
# TODO:
|
2009
|
-
# $<num>$ = parser->parser_in_kwarg;
|
2010
|
-
# parser->parser_in_kwarg = 1;
|
2011
2080
|
}
|
2012
|
-
|
|
2081
|
+
| {
|
2082
|
+
result = self.in_kwarg
|
2083
|
+
self.in_kwarg = true
|
2084
|
+
# TODO: self.lexer.lex_state |= :expr_label
|
2085
|
+
}
|
2086
|
+
f_args term
|
2013
2087
|
{
|
2014
|
-
|
2015
|
-
|
2016
|
-
self.
|
2017
|
-
|
2088
|
+
kwarg, args, _ = val
|
2089
|
+
|
2090
|
+
self.in_kwarg = kwarg
|
2091
|
+
result = args
|
2092
|
+
lexer.lex_state = :expr_beg
|
2093
|
+
lexer.command_start = true
|
2018
2094
|
}
|
2019
2095
|
|
2020
2096
|
args_tail: f_kwarg tCOMMA f_kwrest opt_f_block_arg
|
@@ -2197,7 +2273,9 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2197
2273
|
|
2198
2274
|
f_kwrest: kwrest_mark tIDENTIFIER
|
2199
2275
|
{
|
2200
|
-
|
2276
|
+
name = val[1].to_sym
|
2277
|
+
self.assignable name
|
2278
|
+
result = :"**#{name}"
|
2201
2279
|
}
|
2202
2280
|
| kwrest_mark
|
2203
2281
|
{
|
@@ -2304,9 +2382,10 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2304
2382
|
{
|
2305
2383
|
result = s(:array, val[0], val[2])
|
2306
2384
|
}
|
2307
|
-
| tLABEL
|
2385
|
+
| tLABEL arg_value
|
2308
2386
|
{
|
2309
|
-
|
2387
|
+
(label, _), arg = val
|
2388
|
+
result = s(:array, s(:lit, label.to_sym), arg)
|
2310
2389
|
}
|
2311
2390
|
| tDSTAR arg_value
|
2312
2391
|
{
|
@@ -2318,6 +2397,10 @@ keyword_variable: kNIL { result = s(:nil) }
|
|
2318
2397
|
operation3: tIDENTIFIER | tFID | op
|
2319
2398
|
dot_or_colon: tDOT | tCOLON2
|
2320
2399
|
call_op: tDOT
|
2400
|
+
|
2401
|
+
call_op2: call_op
|
2402
|
+
| tCOLON2
|
2403
|
+
|
2321
2404
|
opt_terms: | terms
|
2322
2405
|
opt_nl: | tNL
|
2323
2406
|
rparen: opt_nl tRPAREN
|