ruby_parser 3.20.0 → 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.
@@ -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? or other.line.nil? or line == other.line)
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 = "<<'eot'\r\nbody\r\neot\n"
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 = <<-EOM.gsub(/^ {6}/, "")
1074
+ rb = <<~EOM
1055
1075
  if true then
1056
- p('a')
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))
@@ -5782,8 +5934,6 @@ class TestRubyParserV26 < RubyParserTestCase
5782
5934
  end
5783
5935
 
5784
5936
  class TestRubyParserV27 < RubyParserTestCase
5785
- make_my_diffs_pretty!
5786
-
5787
5937
  include TestRubyParserShared27Plus
5788
5938
 
5789
5939
  def setup
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.20.0
4
+ version: 3.20.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  ROfWo9Uyp8ba/j9eVG14KkYRaLydAY1MNQk2yd3R5CGfeOpD1kttxjoypoUJ2dOG
30
30
  nsNBRuQJ1UfiCG97a6DNm+Fr
31
31
  -----END CERTIFICATE-----
32
- date: 2023-03-04 00:00:00.000000000 Z
32
+ date: 2023-05-17 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -245,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
245
  - !ruby/object:Gem::Version
246
246
  version: '0'
247
247
  requirements: []
248
- rubygems_version: 3.4.6
248
+ rubygems_version: 3.4.10
249
249
  signing_key:
250
250
  specification_version: 4
251
251
  summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which
metadata.gz.sig CHANGED
Binary file