ruby_parser 3.19.2 → 3.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +20 -0
- data/Manifest.txt +2 -0
- data/README.rdoc +2 -1
- data/Rakefile +13 -8
- data/lib/ruby20_parser.rb +171 -135
- data/lib/ruby20_parser.y +50 -16
- data/lib/ruby21_parser.rb +111 -75
- data/lib/ruby21_parser.y +50 -16
- data/lib/ruby22_parser.rb +239 -203
- data/lib/ruby22_parser.y +50 -16
- data/lib/ruby23_parser.rb +384 -348
- data/lib/ruby23_parser.y +50 -16
- data/lib/ruby24_parser.rb +97 -61
- data/lib/ruby24_parser.y +50 -16
- data/lib/ruby25_parser.rb +93 -57
- data/lib/ruby25_parser.y +50 -16
- data/lib/ruby26_parser.rb +93 -57
- data/lib/ruby26_parser.y +50 -16
- data/lib/ruby27_parser.rb +575 -539
- data/lib/ruby27_parser.y +50 -16
- data/lib/ruby30_parser.rb +358 -332
- data/lib/ruby30_parser.y +42 -16
- data/lib/ruby31_parser.rb +175 -149
- data/lib/ruby31_parser.y +42 -16
- data/lib/ruby32_parser.rb +13664 -0
- data/lib/ruby32_parser.y +3519 -0
- data/lib/ruby3_parser.yy +44 -16
- data/lib/ruby_parser.rb +2 -0
- data/lib/ruby_parser.yy +50 -16
- data/lib/ruby_parser_extras.rb +19 -13
- data/test/test_ruby_parser.rb +170 -6
- data.tar.gz.sig +0 -0
- metadata +16 -14
- metadata.gz.sig +0 -0
data/lib/ruby3_parser.yy
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
class Ruby30Parser
|
5
5
|
#elif V == 31
|
6
6
|
class Ruby31Parser
|
7
|
+
#elif V == 32
|
8
|
+
class Ruby32Parser
|
7
9
|
#else
|
8
10
|
fail "version not specified or supported on code generation"
|
9
11
|
#endif
|
@@ -227,6 +229,7 @@ rule
|
|
227
229
|
| lhs tEQL mrhs
|
228
230
|
{
|
229
231
|
lhs, _, rhs = val
|
232
|
+
|
230
233
|
result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
|
231
234
|
}
|
232
235
|
| mlhs tEQL mrhs_arg kRESCUE_MOD stmt
|
@@ -1146,8 +1149,10 @@ rule
|
|
1146
1149
|
|
1147
1150
|
paren_args: tLPAREN2 opt_call_args rparen
|
1148
1151
|
{
|
1149
|
-
_, args, _ = val
|
1152
|
+
_, args, (_, line_max) = val
|
1153
|
+
|
1150
1154
|
result = args
|
1155
|
+
result.line_max = line_max if args
|
1151
1156
|
}
|
1152
1157
|
| tLPAREN2 args tCOMMA args_forward rparen
|
1153
1158
|
{
|
@@ -1377,12 +1382,14 @@ rule
|
|
1377
1382
|
{
|
1378
1383
|
result = wrap :colon3, val[1]
|
1379
1384
|
}
|
1380
|
-
| tLBRACK { result = lexer.lineno } aref_args
|
1385
|
+
| tLBRACK { result = lexer.lineno } aref_args rbracket
|
1381
1386
|
{
|
1382
|
-
_, line, args, _ = val
|
1387
|
+
_, line, args, (_, line_max) = val
|
1388
|
+
|
1383
1389
|
result = args || s(:array)
|
1384
1390
|
result.sexp_type = :array # aref_args is :args
|
1385
1391
|
result.line line
|
1392
|
+
result.line_max = line_max
|
1386
1393
|
}
|
1387
1394
|
| tLBRACE
|
1388
1395
|
{
|
@@ -1973,13 +1980,19 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1973
1980
|
{
|
1974
1981
|
call, args = val
|
1975
1982
|
|
1976
|
-
result = call
|
1983
|
+
result = call
|
1984
|
+
|
1985
|
+
if args then
|
1986
|
+
call.concat args.sexp_body
|
1987
|
+
result.line_max = args.line_max
|
1988
|
+
end
|
1977
1989
|
}
|
1978
1990
|
| primary_value call_op operation2 opt_paren_args
|
1979
1991
|
{
|
1980
|
-
recv, call_op, (op,
|
1992
|
+
recv, call_op, (op, op_line), args = val
|
1981
1993
|
|
1982
1994
|
result = new_call recv, op.to_sym, args, call_op
|
1995
|
+
result.line_max = op_line unless args
|
1983
1996
|
}
|
1984
1997
|
| primary_value tCOLON2 operation2 paren_args
|
1985
1998
|
{
|
@@ -2749,15 +2762,17 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2749
2762
|
|
2750
2763
|
words: tWORDS_BEG tSPACE tSTRING_END
|
2751
2764
|
{
|
2752
|
-
(_, line), _, _ = val
|
2765
|
+
(_, line), _, (_, line_max) = val
|
2753
2766
|
|
2754
2767
|
result = s(:array).line line
|
2768
|
+
result.line_max = line_max
|
2755
2769
|
}
|
2756
2770
|
| tWORDS_BEG word_list tSTRING_END
|
2757
2771
|
{
|
2758
|
-
(_, line), list, _ = val
|
2772
|
+
(_, line), list, (_, line_max) = val
|
2759
2773
|
|
2760
2774
|
result = list.line line
|
2775
|
+
result.line_max = line_max
|
2761
2776
|
}
|
2762
2777
|
|
2763
2778
|
word_list: none
|
@@ -2777,15 +2792,17 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2777
2792
|
|
2778
2793
|
symbols: tSYMBOLS_BEG tSPACE tSTRING_END
|
2779
2794
|
{
|
2780
|
-
(_, line), _, _ = val
|
2795
|
+
(_, line), _, (_, line_max) = val
|
2781
2796
|
|
2782
2797
|
result = s(:array).line line
|
2798
|
+
result.line_max = line_max
|
2783
2799
|
}
|
2784
2800
|
| tSYMBOLS_BEG symbol_list tSTRING_END
|
2785
2801
|
{
|
2786
|
-
(_, line), list, _, = val
|
2787
|
-
|
2788
|
-
result = list
|
2802
|
+
(_, line), list, (_, line_max), = val
|
2803
|
+
|
2804
|
+
result = list.line line
|
2805
|
+
result.line_max = line_max
|
2789
2806
|
}
|
2790
2807
|
|
2791
2808
|
symbol_list: none
|
@@ -2800,28 +2817,32 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2800
2817
|
|
2801
2818
|
qwords: tQWORDS_BEG tSPACE tSTRING_END
|
2802
2819
|
{
|
2803
|
-
(_, line), _, _ = val
|
2820
|
+
(_, line), _, (_, line_max) = val
|
2804
2821
|
|
2805
2822
|
result = s(:array).line line
|
2823
|
+
result.line_max = line_max
|
2806
2824
|
}
|
2807
2825
|
| tQWORDS_BEG qword_list tSTRING_END
|
2808
2826
|
{
|
2809
|
-
(_, line), list, _ = val
|
2827
|
+
(_, line), list, (_, line_max) = val
|
2810
2828
|
|
2811
2829
|
result = list.line line
|
2830
|
+
result.line_max = line_max
|
2812
2831
|
}
|
2813
2832
|
|
2814
2833
|
qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
|
2815
2834
|
{
|
2816
|
-
(_, line), _, _ = val
|
2835
|
+
(_, line), _, (_, line_max) = val
|
2817
2836
|
|
2818
2837
|
result = s(:array).line line
|
2838
|
+
result.line_max = line_max
|
2819
2839
|
}
|
2820
2840
|
| tQSYMBOLS_BEG qsym_list tSTRING_END
|
2821
2841
|
{
|
2822
|
-
(_, line), list, _ = val
|
2842
|
+
(_, line), list, (_, line_max) = val
|
2823
2843
|
|
2824
2844
|
result = list.line line
|
2845
|
+
result.line_max = line_max
|
2825
2846
|
}
|
2826
2847
|
|
2827
2848
|
qword_list: none
|
@@ -3257,7 +3278,14 @@ f_opt_paren_args: f_paren_args
|
|
3257
3278
|
result = s(:args, list).line list.line
|
3258
3279
|
end
|
3259
3280
|
|
3260
|
-
|
3281
|
+
if Sexp === item then
|
3282
|
+
line_max = item.line_max
|
3283
|
+
else
|
3284
|
+
item, line_max = item
|
3285
|
+
end
|
3286
|
+
|
3287
|
+
result << item
|
3288
|
+
result.line_max = line_max
|
3261
3289
|
}
|
3262
3290
|
|
3263
3291
|
f_label: tLABEL
|
data/lib/ruby_parser.rb
CHANGED
@@ -81,10 +81,12 @@ require "ruby26_parser"
|
|
81
81
|
require "ruby27_parser"
|
82
82
|
require "ruby30_parser"
|
83
83
|
require "ruby31_parser"
|
84
|
+
require "ruby32_parser"
|
84
85
|
|
85
86
|
class RubyParser # HACK
|
86
87
|
VERSIONS.clear # also a HACK caused by racc namespace issues
|
87
88
|
|
89
|
+
class V32 < ::Ruby32Parser; end
|
88
90
|
class V31 < ::Ruby31Parser; end
|
89
91
|
class V30 < ::Ruby30Parser; end
|
90
92
|
class V27 < ::Ruby27Parser; end
|
data/lib/ruby_parser.yy
CHANGED
@@ -253,6 +253,7 @@ rule
|
|
253
253
|
| lhs tEQL mrhs
|
254
254
|
{
|
255
255
|
lhs, _, rhs = val
|
256
|
+
|
256
257
|
result = new_assign lhs, s(:svalue, rhs).line(rhs.line)
|
257
258
|
}
|
258
259
|
#if V == 20
|
@@ -1107,8 +1108,10 @@ rule
|
|
1107
1108
|
|
1108
1109
|
paren_args: tLPAREN2 opt_call_args rparen
|
1109
1110
|
{
|
1110
|
-
_, args, _ = val
|
1111
|
+
_, args, (_, line_max) = val
|
1112
|
+
|
1111
1113
|
result = args
|
1114
|
+
result.line_max = line_max if args
|
1112
1115
|
}
|
1113
1116
|
#if V >= 27
|
1114
1117
|
| tLPAREN2 args tCOMMA args_forward rparen
|
@@ -1335,12 +1338,14 @@ rule
|
|
1335
1338
|
{
|
1336
1339
|
result = wrap :colon3, val[1]
|
1337
1340
|
}
|
1338
|
-
| tLBRACK { result = lexer.lineno } aref_args
|
1341
|
+
| tLBRACK { result = lexer.lineno } aref_args rbracket
|
1339
1342
|
{
|
1340
|
-
_, line, args, _ = val
|
1343
|
+
_, line, args, (_, line_max) = val
|
1344
|
+
|
1341
1345
|
result = args || s(:array)
|
1342
1346
|
result.sexp_type = :array # aref_args is :args
|
1343
1347
|
result.line line
|
1348
|
+
result.line_max = line_max
|
1344
1349
|
}
|
1345
1350
|
| tLBRACE
|
1346
1351
|
{
|
@@ -1942,13 +1947,19 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
1942
1947
|
{
|
1943
1948
|
call, args = val
|
1944
1949
|
|
1945
|
-
result = call
|
1950
|
+
result = call
|
1951
|
+
|
1952
|
+
if args then
|
1953
|
+
call.concat args.sexp_body
|
1954
|
+
result.line_max = args.line_max
|
1955
|
+
end
|
1946
1956
|
}
|
1947
1957
|
| primary_value call_op operation2 opt_paren_args
|
1948
1958
|
{
|
1949
|
-
recv, call_op, (op,
|
1959
|
+
recv, call_op, (op, op_line), args = val
|
1950
1960
|
|
1951
1961
|
result = new_call recv, op.to_sym, args, call_op
|
1962
|
+
result.line_max = op_line unless args
|
1952
1963
|
}
|
1953
1964
|
| primary_value tCOLON2 operation2 paren_args
|
1954
1965
|
{
|
@@ -2674,15 +2685,17 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2674
2685
|
|
2675
2686
|
words: tWORDS_BEG tSPACE tSTRING_END
|
2676
2687
|
{
|
2677
|
-
(_, line), _, _ = val
|
2688
|
+
(_, line), _, (_, line_max) = val
|
2678
2689
|
|
2679
2690
|
result = s(:array).line line
|
2691
|
+
result.line_max = line_max
|
2680
2692
|
}
|
2681
2693
|
| tWORDS_BEG word_list tSTRING_END
|
2682
2694
|
{
|
2683
|
-
(_, line), list, _ = val
|
2695
|
+
(_, line), list, (_, line_max) = val
|
2684
2696
|
|
2685
2697
|
result = list.line line
|
2698
|
+
result.line_max = line_max
|
2686
2699
|
}
|
2687
2700
|
|
2688
2701
|
word_list: none
|
@@ -2702,15 +2715,17 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2702
2715
|
|
2703
2716
|
symbols: tSYMBOLS_BEG tSPACE tSTRING_END
|
2704
2717
|
{
|
2705
|
-
(_, line), _, _ = val
|
2718
|
+
(_, line), _, (_, line_max) = val
|
2706
2719
|
|
2707
2720
|
result = s(:array).line line
|
2721
|
+
result.line_max = line_max
|
2708
2722
|
}
|
2709
2723
|
| tSYMBOLS_BEG symbol_list tSTRING_END
|
2710
2724
|
{
|
2711
|
-
(_, line), list, _, = val
|
2712
|
-
|
2713
|
-
result = list
|
2725
|
+
(_, line), list, (_, line_max), = val
|
2726
|
+
|
2727
|
+
result = list.line line
|
2728
|
+
result.line_max = line_max
|
2714
2729
|
}
|
2715
2730
|
|
2716
2731
|
symbol_list: none
|
@@ -2725,28 +2740,32 @@ opt_block_args_tail: tCOMMA block_args_tail
|
|
2725
2740
|
|
2726
2741
|
qwords: tQWORDS_BEG tSPACE tSTRING_END
|
2727
2742
|
{
|
2728
|
-
(_, line), _, _ = val
|
2743
|
+
(_, line), _, (_, line_max) = val
|
2729
2744
|
|
2730
2745
|
result = s(:array).line line
|
2746
|
+
result.line_max = line_max
|
2731
2747
|
}
|
2732
2748
|
| tQWORDS_BEG qword_list tSTRING_END
|
2733
2749
|
{
|
2734
|
-
(_, line), list, _ = val
|
2750
|
+
(_, line), list, (_, line_max) = val
|
2735
2751
|
|
2736
2752
|
result = list.line line
|
2753
|
+
result.line_max = line_max
|
2737
2754
|
}
|
2738
2755
|
|
2739
2756
|
qsymbols: tQSYMBOLS_BEG tSPACE tSTRING_END
|
2740
2757
|
{
|
2741
|
-
(_, line), _, _ = val
|
2758
|
+
(_, line), _, (_, line_max) = val
|
2742
2759
|
|
2743
2760
|
result = s(:array).line line
|
2761
|
+
result.line_max = line_max
|
2744
2762
|
}
|
2745
2763
|
| tQSYMBOLS_BEG qsym_list tSTRING_END
|
2746
2764
|
{
|
2747
|
-
(_, line), list, _ = val
|
2765
|
+
(_, line), list, (_, line_max) = val
|
2748
2766
|
|
2749
2767
|
result = list.line line
|
2768
|
+
result.line_max = line_max
|
2750
2769
|
}
|
2751
2770
|
|
2752
2771
|
qword_list: none
|
@@ -3197,7 +3216,14 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
3197
3216
|
result = s(:args, list).line list.line
|
3198
3217
|
end
|
3199
3218
|
|
3200
|
-
|
3219
|
+
if Sexp === item then
|
3220
|
+
line_max = item.line_max
|
3221
|
+
else
|
3222
|
+
item, line_max = item
|
3223
|
+
end
|
3224
|
+
|
3225
|
+
result << item
|
3226
|
+
result.line_max = line_max
|
3201
3227
|
}
|
3202
3228
|
|
3203
3229
|
#if V == 20
|
@@ -3449,7 +3475,15 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
|
|
3449
3475
|
opt_terms: | terms
|
3450
3476
|
opt_nl: | tNL
|
3451
3477
|
rparen: opt_nl tRPAREN
|
3478
|
+
{
|
3479
|
+
_, close = val
|
3480
|
+
result = [close, lexer.lineno]
|
3481
|
+
}
|
3452
3482
|
rbracket: opt_nl tRBRACK
|
3483
|
+
{
|
3484
|
+
_, close = val
|
3485
|
+
result = [close, lexer.lineno]
|
3486
|
+
}
|
3453
3487
|
#if V >= 27
|
3454
3488
|
rbrace: opt_nl tRCURLY
|
3455
3489
|
#endif
|
data/lib/ruby_parser_extras.rb
CHANGED
@@ -18,7 +18,7 @@ class Sexp
|
|
18
18
|
end
|
19
19
|
|
20
20
|
##
|
21
|
-
# Returns the
|
21
|
+
# Returns the minimum line number of the children of self.
|
22
22
|
|
23
23
|
def line_min
|
24
24
|
@line_min ||= [self.deep_each.map(&:line).min, self.line].compact.min
|
@@ -30,7 +30,7 @@ class Sexp
|
|
30
30
|
end
|
31
31
|
|
32
32
|
module RubyParserStuff
|
33
|
-
VERSION = "3.
|
33
|
+
VERSION = "3.20.1"
|
34
34
|
|
35
35
|
attr_accessor :lexer, :in_def, :in_single, :file
|
36
36
|
attr_accessor :in_kwarg
|
@@ -153,6 +153,7 @@ module RubyParserStuff
|
|
153
153
|
result.line lexer.lineno
|
154
154
|
else
|
155
155
|
result.line ss.first.line
|
156
|
+
result.line_max = ss.first.line_max
|
156
157
|
end
|
157
158
|
|
158
159
|
args.each do |arg|
|
@@ -330,9 +331,8 @@ module RubyParserStuff
|
|
330
331
|
end
|
331
332
|
|
332
333
|
args.each do |arg|
|
333
|
-
|
334
|
-
|
335
|
-
end
|
334
|
+
# ruby 3.0+ TODO: next if arg in [String, Integer] # eg ["(", 1]
|
335
|
+
next if arg.class == Array && arg.map(&:class) == [String, Integer]
|
336
336
|
|
337
337
|
case arg
|
338
338
|
when Sexp then
|
@@ -794,6 +794,7 @@ module RubyParserStuff
|
|
794
794
|
case lhs.sexp_type
|
795
795
|
when :lasgn, :iasgn, :cdecl, :cvdecl, :gasgn, :cvasgn, :attrasgn, :safe_attrasgn then
|
796
796
|
lhs << rhs
|
797
|
+
lhs.line_max = rhs.line_max
|
797
798
|
when :const then
|
798
799
|
lhs.sexp_type = :cdecl
|
799
800
|
lhs << rhs
|
@@ -885,12 +886,13 @@ module RubyParserStuff
|
|
885
886
|
# TODO: need a test with f(&b) to produce block_pass
|
886
887
|
# TODO: need a test with f(&b) { } to produce warning
|
887
888
|
|
888
|
-
if args
|
889
|
+
if args then
|
889
890
|
if ARG_TYPES[args.sexp_type] then
|
890
891
|
result.concat args.sexp_body
|
891
892
|
else
|
892
893
|
result << args
|
893
894
|
end
|
895
|
+
result.line_max = args.line_max
|
894
896
|
end
|
895
897
|
|
896
898
|
# line = result.grep(Sexp).map(&:line).compact.min
|
@@ -927,7 +929,7 @@ module RubyParserStuff
|
|
927
929
|
|
928
930
|
def new_class val
|
929
931
|
# TODO: get line from class keyword
|
930
|
-
line, path, superclass,
|
932
|
+
_, line, path, superclass, _, body, (_, line_max) = val
|
931
933
|
|
932
934
|
path = path.first if path.instance_of? Array
|
933
935
|
|
@@ -942,6 +944,7 @@ module RubyParserStuff
|
|
942
944
|
end
|
943
945
|
|
944
946
|
result.line = line
|
947
|
+
result.line_max = line_max
|
945
948
|
result.comments = self.comments.pop
|
946
949
|
result
|
947
950
|
end
|
@@ -970,13 +973,14 @@ module RubyParserStuff
|
|
970
973
|
end
|
971
974
|
|
972
975
|
def new_defn val
|
973
|
-
_, (name, line), in_def, args, body, _ = val
|
976
|
+
_, (name, line), in_def, args, body, (_, line_max) = val
|
974
977
|
|
975
978
|
body ||= s(:nil).line line
|
976
979
|
|
977
980
|
args.line line
|
978
981
|
|
979
982
|
result = s(:defn, name.to_sym, args).line line
|
983
|
+
result.line_max = line_max
|
980
984
|
|
981
985
|
if body.sexp_type == :block then
|
982
986
|
result.push(*body.sexp_body)
|
@@ -1033,13 +1037,14 @@ module RubyParserStuff
|
|
1033
1037
|
end
|
1034
1038
|
|
1035
1039
|
def new_defs val
|
1036
|
-
_, recv, (name, line), in_def, args, body, _ = val
|
1040
|
+
_, recv, (name, line), in_def, args, body, (_, line_max) = val
|
1037
1041
|
|
1038
1042
|
body ||= s(:nil).line line
|
1039
1043
|
|
1040
1044
|
args.line line
|
1041
1045
|
|
1042
1046
|
result = s(:defs, recv, name.to_sym, args).line line
|
1047
|
+
result.line_max = line_max
|
1043
1048
|
|
1044
1049
|
# TODO: remove_begin
|
1045
1050
|
# TODO: reduce_nodes
|
@@ -1204,12 +1209,12 @@ module RubyParserStuff
|
|
1204
1209
|
end
|
1205
1210
|
|
1206
1211
|
def new_module val
|
1207
|
-
|
1208
|
-
line, path, body = val[1], val[2], val[4]
|
1212
|
+
(_, line_min), _, path, _, body, (_, line_max) = val
|
1209
1213
|
|
1210
1214
|
path = path.first if path.instance_of? Array
|
1211
1215
|
|
1212
|
-
result = s(:module, path).line
|
1216
|
+
result = s(:module, path).line line_min
|
1217
|
+
result.line_max = line_max
|
1213
1218
|
|
1214
1219
|
if body then # REFACTOR?
|
1215
1220
|
if body.sexp_type == :block then
|
@@ -1291,9 +1296,10 @@ module RubyParserStuff
|
|
1291
1296
|
end
|
1292
1297
|
|
1293
1298
|
def new_regexp val
|
1294
|
-
(_, line), node, (options,
|
1299
|
+
(_, line), node, (options, line_max) = val
|
1295
1300
|
|
1296
1301
|
node ||= s(:str, "").line line
|
1302
|
+
node.line_max = line_max
|
1297
1303
|
|
1298
1304
|
o, k = 0, nil
|
1299
1305
|
options.split(//).uniq.each do |c| # FIX: this has a better home
|
data/test/test_ruby_parser.rb
CHANGED
@@ -15,11 +15,26 @@ class Sexp
|
|
15
15
|
def == other # :nodoc:
|
16
16
|
if other.class == self.class then
|
17
17
|
super and
|
18
|
-
(line.nil?
|
18
|
+
(line.nil? or other.line.nil? or line == other.line) and
|
19
|
+
(!defined?(@line_max) or @line_max.nil? or line_max == other.line_max)
|
20
|
+
# (line_max.nil? or other.line_max.nil? or line_max == other.line_max)
|
19
21
|
else
|
20
22
|
false
|
21
23
|
end
|
22
24
|
end
|
25
|
+
|
26
|
+
# convenience function just for testing
|
27
|
+
alias dead line_max
|
28
|
+
def line_max n = UNASSIGNED
|
29
|
+
if n != UNASSIGNED then
|
30
|
+
raise ArgumentError, "setting %p.line_max %p" % [self, n] unless Integer === n
|
31
|
+
@line_max = n
|
32
|
+
self
|
33
|
+
else
|
34
|
+
# raise "Accessing before @line_max defined" unless defined?(@line_max)
|
35
|
+
@line_max ||= self.deep_each.map(&:line).compact.max
|
36
|
+
end
|
37
|
+
end
|
23
38
|
end
|
24
39
|
|
25
40
|
module TestRubyParserShared
|
@@ -965,7 +980,12 @@ module TestRubyParserShared
|
|
965
980
|
end
|
966
981
|
|
967
982
|
def test_heredoc_with_extra_carriage_horrible_mix?
|
968
|
-
rb =
|
983
|
+
rb = <<~RUBY
|
984
|
+
<<'eot'\r
|
985
|
+
body\r
|
986
|
+
eot
|
987
|
+
RUBY
|
988
|
+
|
969
989
|
pt = s(:str, "body\r\n")
|
970
990
|
|
971
991
|
assert_parse rb, pt
|
@@ -1051,9 +1071,9 @@ module TestRubyParserShared
|
|
1051
1071
|
end
|
1052
1072
|
|
1053
1073
|
def test_i_fucking_hate_line_numbers2
|
1054
|
-
rb =
|
1074
|
+
rb = <<~EOM
|
1055
1075
|
if true then
|
1056
|
-
p(
|
1076
|
+
p("a")
|
1057
1077
|
b = 1
|
1058
1078
|
p b
|
1059
1079
|
c =1
|
@@ -1074,6 +1094,138 @@ module TestRubyParserShared
|
|
1074
1094
|
assert_parse rb, pt
|
1075
1095
|
end
|
1076
1096
|
|
1097
|
+
line_max_array = s(:array,
|
1098
|
+
s(:lit, :line2).line(2),
|
1099
|
+
s(:lit, :line3).line(3)).line(1).line_max(4)
|
1100
|
+
line_max_array_empty = s(:array).line(1).line_max(4)
|
1101
|
+
[
|
1102
|
+
[:plain_array,
|
1103
|
+
"[\n:line2,\n:line3\n]",
|
1104
|
+
line_max_array,
|
1105
|
+
],
|
1106
|
+
[:pct_i,
|
1107
|
+
"%i[\nline2\nline3\n]",
|
1108
|
+
line_max_array,
|
1109
|
+
],
|
1110
|
+
[:pct_i_empty,
|
1111
|
+
"%i[\n\n\n]",
|
1112
|
+
line_max_array_empty,
|
1113
|
+
],
|
1114
|
+
[:pct_I,
|
1115
|
+
"%I[\nline2\nline3\n]",
|
1116
|
+
line_max_array,
|
1117
|
+
],
|
1118
|
+
[:pct_I_empty,
|
1119
|
+
"%I[\n\n\n]",
|
1120
|
+
line_max_array_empty,
|
1121
|
+
],
|
1122
|
+
[:call_parens,
|
1123
|
+
"x(\n:line2,\n:line3\n)",
|
1124
|
+
s(:call, nil, :x, *line_max_array.sexp_body).line(1).line_max(4),
|
1125
|
+
],
|
1126
|
+
[:pct_w,
|
1127
|
+
"%w[\nline2\nline3\n]",
|
1128
|
+
s(:array,
|
1129
|
+
s(:str, "line2").line(2),
|
1130
|
+
s(:str, "line3").line(3)).line(1).line_max(4),
|
1131
|
+
],
|
1132
|
+
[:pct_w_empty,
|
1133
|
+
"%w[\n\n\n]",
|
1134
|
+
line_max_array_empty,
|
1135
|
+
],
|
1136
|
+
[:pct_W,
|
1137
|
+
"%W[\nline2\nline3\n]",
|
1138
|
+
s(:array,
|
1139
|
+
s(:str, "line2").line(2),
|
1140
|
+
s(:str, "line3").line(3)).line(1).line_max(4),
|
1141
|
+
],
|
1142
|
+
[:pct_W_empty,
|
1143
|
+
"%W[\n\n\n]",
|
1144
|
+
line_max_array_empty,
|
1145
|
+
],
|
1146
|
+
[:regexp,
|
1147
|
+
"%r[\n\n\n]", # double-quotes to have the \n counted as lines on input
|
1148
|
+
s(:lit, %r[#{"\n\n\n"}]).line(1).line_max(4),
|
1149
|
+
],
|
1150
|
+
[:module,
|
1151
|
+
<<~"RUBY",
|
1152
|
+
module X # line 1
|
1153
|
+
module Y # line 2
|
1154
|
+
Z = 42 # line 3
|
1155
|
+
end # line 4
|
1156
|
+
end # line 5
|
1157
|
+
RUBY
|
1158
|
+
s(:module, :X,
|
1159
|
+
s(:module, :Y,
|
1160
|
+
s(:cdecl, :Z, s(:lit, 42).line(3)).line(3).line_max(3)
|
1161
|
+
).line(2).line_max(4)
|
1162
|
+
).line(1).line_max(5)],
|
1163
|
+
[:class,
|
1164
|
+
<<~"RUBY",
|
1165
|
+
class X # line 1
|
1166
|
+
class Y # line 2
|
1167
|
+
Z = 42 # line 3
|
1168
|
+
end # line 4
|
1169
|
+
end # line 5
|
1170
|
+
RUBY
|
1171
|
+
s(:class, :X, nil,
|
1172
|
+
s(:class, :Y, nil,
|
1173
|
+
s(:cdecl, :Z, s(:lit, 42).line(3)).line(3).line_max(3)
|
1174
|
+
).line(2).line_max(4)
|
1175
|
+
).line(1).line_max(5)],
|
1176
|
+
[:cdecl,
|
1177
|
+
<<~"RUBY",
|
1178
|
+
module X
|
1179
|
+
X = [
|
1180
|
+
:line3,
|
1181
|
+
:line4,
|
1182
|
+
]
|
1183
|
+
end
|
1184
|
+
RUBY
|
1185
|
+
s(:module, :X,
|
1186
|
+
s(:cdecl, :X,
|
1187
|
+
s(:array,
|
1188
|
+
s(:lit, :line3).line(3),
|
1189
|
+
s(:lit, :line4).line(4)).line(2).line_max(5),
|
1190
|
+
).line(2).line_max(5),
|
1191
|
+
).line(1).line_max(6)
|
1192
|
+
],
|
1193
|
+
[:defn,
|
1194
|
+
<<~"RUBY",
|
1195
|
+
class X # line 1
|
1196
|
+
def y(a, # line 2
|
1197
|
+
b) # line 3
|
1198
|
+
a + b # line 4
|
1199
|
+
end # line 5
|
1200
|
+
end # line 6
|
1201
|
+
RUBY
|
1202
|
+
s(:class, :X, nil,
|
1203
|
+
s(:defn, :y, s(:args, :a, :b).line(2).line_max(3),
|
1204
|
+
s(:call, s(:lvar, :a).line(4), :+, s(:lvar, :b).line(4)).line(4)
|
1205
|
+
).line(2).line_max(5),
|
1206
|
+
).line(1).line_max(6),
|
1207
|
+
],
|
1208
|
+
[:defs,
|
1209
|
+
<<~"RUBY",
|
1210
|
+
class X # line 1
|
1211
|
+
def self.y(a, # line 2
|
1212
|
+
b) # line 3
|
1213
|
+
a + b # line 4
|
1214
|
+
end # line 5
|
1215
|
+
end # line 6
|
1216
|
+
RUBY
|
1217
|
+
s(:class, :X, nil,
|
1218
|
+
s(:defs, s(:self).line(2), :y, s(:args, :a, :b).line(2).line_max(3),
|
1219
|
+
s(:call, s(:lvar, :a).line(4), :+, s(:lvar, :b).line(4)).line(4)
|
1220
|
+
).line(2).line_max(5),
|
1221
|
+
).line(1).line_max(6),
|
1222
|
+
],
|
1223
|
+
].each do |(name, rb, pt)|
|
1224
|
+
define_method "test_line_numbers__max_line__#{name}" do
|
1225
|
+
assert_parse rb, pt
|
1226
|
+
end
|
1227
|
+
end
|
1228
|
+
|
1077
1229
|
def test_if_elsif
|
1078
1230
|
rb = "if 1; elsif 2; end"
|
1079
1231
|
pt = s(:if, s(:lit, 1), nil, s(:if, s(:lit, 2), nil, nil))
|
@@ -5478,6 +5630,10 @@ module TestRubyParserShared31Plus
|
|
5478
5630
|
end
|
5479
5631
|
end
|
5480
5632
|
|
5633
|
+
module TestRubyParserShared32Plus
|
5634
|
+
include TestRubyParserShared31Plus
|
5635
|
+
end
|
5636
|
+
|
5481
5637
|
class Minitest::Test
|
5482
5638
|
def skip s = "blah"
|
5483
5639
|
warn "ignoring skip for %s: %s" % [name, s]
|
@@ -5778,8 +5934,6 @@ class TestRubyParserV26 < RubyParserTestCase
|
|
5778
5934
|
end
|
5779
5935
|
|
5780
5936
|
class TestRubyParserV27 < RubyParserTestCase
|
5781
|
-
make_my_diffs_pretty!
|
5782
|
-
|
5783
5937
|
include TestRubyParserShared27Plus
|
5784
5938
|
|
5785
5939
|
def setup
|
@@ -5829,6 +5983,16 @@ class TestRubyParserV31 < RubyParserTestCase
|
|
5829
5983
|
end
|
5830
5984
|
end
|
5831
5985
|
|
5986
|
+
class TestRubyParserV32 < RubyParserTestCase
|
5987
|
+
include TestRubyParserShared32Plus
|
5988
|
+
|
5989
|
+
def setup
|
5990
|
+
super
|
5991
|
+
|
5992
|
+
self.processor = RubyParser::V32.new
|
5993
|
+
end
|
5994
|
+
end
|
5995
|
+
|
5832
5996
|
RubyParser::VERSIONS.each do |klass|
|
5833
5997
|
v = klass.version
|
5834
5998
|
describe "block args arity #{v}" do
|