ruby_parser 3.20.0 → 3.20.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -117,11 +132,13 @@ module TestRubyParserShared
117
132
  # for the array. Luckily, the arary elements all seemt to get the correct
118
133
  # line number.
119
134
  rb = "[\n'a',\n'b']\n1"
135
+
120
136
  pt = s(:block,
121
137
  s(:array,
122
138
  s(:str, "a").line(2),
123
- s(:str, "b").line(3)),
139
+ s(:str, "b").line(3)).line(1),
124
140
  s(:lit, 1).line(4)).line 1
141
+
125
142
  assert_parse rb, pt
126
143
  end
127
144
 
@@ -965,7 +982,12 @@ module TestRubyParserShared
965
982
  end
966
983
 
967
984
  def test_heredoc_with_extra_carriage_horrible_mix?
968
- rb = "<<'eot'\r\nbody\r\neot\n"
985
+ rb = <<~RUBY
986
+ <<'eot'\r
987
+ body\r
988
+ eot
989
+ RUBY
990
+
969
991
  pt = s(:str, "body\r\n")
970
992
 
971
993
  assert_parse rb, pt
@@ -1051,9 +1073,9 @@ module TestRubyParserShared
1051
1073
  end
1052
1074
 
1053
1075
  def test_i_fucking_hate_line_numbers2
1054
- rb = <<-EOM.gsub(/^ {6}/, "")
1076
+ rb = <<~EOM
1055
1077
  if true then
1056
- p('a')
1078
+ p("a")
1057
1079
  b = 1
1058
1080
  p b
1059
1081
  c =1
@@ -1074,6 +1096,138 @@ module TestRubyParserShared
1074
1096
  assert_parse rb, pt
1075
1097
  end
1076
1098
 
1099
+ line_max_array = s(:array,
1100
+ s(:lit, :line2).line(2),
1101
+ s(:lit, :line3).line(3)).line(1).line_max(4)
1102
+ line_max_array_empty = s(:array).line(1).line_max(4)
1103
+ [
1104
+ [:plain_array,
1105
+ "[\n:line2,\n:line3\n]",
1106
+ line_max_array,
1107
+ ],
1108
+ [:pct_i,
1109
+ "%i[\nline2\nline3\n]",
1110
+ line_max_array,
1111
+ ],
1112
+ [:pct_i_empty,
1113
+ "%i[\n\n\n]",
1114
+ line_max_array_empty,
1115
+ ],
1116
+ [:pct_I,
1117
+ "%I[\nline2\nline3\n]",
1118
+ line_max_array,
1119
+ ],
1120
+ [:pct_I_empty,
1121
+ "%I[\n\n\n]",
1122
+ line_max_array_empty,
1123
+ ],
1124
+ [:call_parens,
1125
+ "x(\n:line2,\n:line3\n)",
1126
+ s(:call, nil, :x, *line_max_array.sexp_body).line(1).line_max(4),
1127
+ ],
1128
+ [:pct_w,
1129
+ "%w[\nline2\nline3\n]",
1130
+ s(:array,
1131
+ s(:str, "line2").line(2),
1132
+ s(:str, "line3").line(3)).line(1).line_max(4),
1133
+ ],
1134
+ [:pct_w_empty,
1135
+ "%w[\n\n\n]",
1136
+ line_max_array_empty,
1137
+ ],
1138
+ [:pct_W,
1139
+ "%W[\nline2\nline3\n]",
1140
+ s(:array,
1141
+ s(:str, "line2").line(2),
1142
+ s(:str, "line3").line(3)).line(1).line_max(4),
1143
+ ],
1144
+ [:pct_W_empty,
1145
+ "%W[\n\n\n]",
1146
+ line_max_array_empty,
1147
+ ],
1148
+ [:regexp,
1149
+ "%r[\n\n\n]", # double-quotes to have the \n counted as lines on input
1150
+ s(:lit, %r[#{"\n\n\n"}]).line(1).line_max(4),
1151
+ ],
1152
+ [:module,
1153
+ <<~"RUBY",
1154
+ module X # line 1
1155
+ module Y # line 2
1156
+ Z = 42 # line 3
1157
+ end # line 4
1158
+ end # line 5
1159
+ RUBY
1160
+ s(:module, :X,
1161
+ s(:module, :Y,
1162
+ s(:cdecl, :Z, s(:lit, 42).line(3)).line(3).line_max(3)
1163
+ ).line(2).line_max(4)
1164
+ ).line(1).line_max(5)],
1165
+ [:class,
1166
+ <<~"RUBY",
1167
+ class X # line 1
1168
+ class Y # line 2
1169
+ Z = 42 # line 3
1170
+ end # line 4
1171
+ end # line 5
1172
+ RUBY
1173
+ s(:class, :X, nil,
1174
+ s(:class, :Y, nil,
1175
+ s(:cdecl, :Z, s(:lit, 42).line(3)).line(3).line_max(3)
1176
+ ).line(2).line_max(4)
1177
+ ).line(1).line_max(5)],
1178
+ [:cdecl,
1179
+ <<~"RUBY",
1180
+ module X
1181
+ X = [
1182
+ :line3,
1183
+ :line4,
1184
+ ]
1185
+ end
1186
+ RUBY
1187
+ s(:module, :X,
1188
+ s(:cdecl, :X,
1189
+ s(:array,
1190
+ s(:lit, :line3).line(3),
1191
+ s(:lit, :line4).line(4)).line(2).line_max(5),
1192
+ ).line(2).line_max(5),
1193
+ ).line(1).line_max(6)
1194
+ ],
1195
+ [:defn,
1196
+ <<~"RUBY",
1197
+ class X # line 1
1198
+ def y(a, # line 2
1199
+ b) # line 3
1200
+ a + b # line 4
1201
+ end # line 5
1202
+ end # line 6
1203
+ RUBY
1204
+ s(:class, :X, nil,
1205
+ s(:defn, :y, s(:args, :a, :b).line(2).line_max(3),
1206
+ s(:call, s(:lvar, :a).line(4), :+, s(:lvar, :b).line(4)).line(4)
1207
+ ).line(2).line_max(5),
1208
+ ).line(1).line_max(6),
1209
+ ],
1210
+ [:defs,
1211
+ <<~"RUBY",
1212
+ class X # line 1
1213
+ def self.y(a, # line 2
1214
+ b) # line 3
1215
+ a + b # line 4
1216
+ end # line 5
1217
+ end # line 6
1218
+ RUBY
1219
+ s(:class, :X, nil,
1220
+ s(:defs, s(:self).line(2), :y, s(:args, :a, :b).line(2).line_max(3),
1221
+ s(:call, s(:lvar, :a).line(4), :+, s(:lvar, :b).line(4)).line(4)
1222
+ ).line(2).line_max(5),
1223
+ ).line(1).line_max(6),
1224
+ ],
1225
+ ].each do |(name, rb, pt)|
1226
+ define_method "test_line_numbers__max_line__#{name}" do
1227
+ assert_parse rb, pt
1228
+ end
1229
+ end
1230
+
1077
1231
  def test_if_elsif
1078
1232
  rb = "if 1; elsif 2; end"
1079
1233
  pt = s(:if, s(:lit, 1), nil, s(:if, s(:lit, 2), nil, nil))
@@ -5402,6 +5556,14 @@ module TestRubyParserShared31Plus
5402
5556
  assert_case_in rb, pt
5403
5557
  end
5404
5558
 
5559
+ def test_defn_forward_args__no_parens
5560
+ rb = "def f ...\n m(...)\nend"
5561
+ pt = s(:defn, :f, s(:args, s(:forward_args)),
5562
+ s(:call, nil, :m, s(:forward_args).line(2)).line(2))
5563
+
5564
+ assert_parse rb, pt
5565
+ end
5566
+
5405
5567
  def test_case_in_carat_nonlocal_vars
5406
5568
  processor.env[:a] = :lvar
5407
5569
 
@@ -5480,6 +5642,34 @@ end
5480
5642
 
5481
5643
  module TestRubyParserShared32Plus
5482
5644
  include TestRubyParserShared31Plus
5645
+
5646
+ def test_args_star__anon_solo
5647
+ rb = "f(*)"
5648
+ pt = s(:call, nil, :f, s(:splat))
5649
+
5650
+ assert_parse rb, pt
5651
+ end
5652
+
5653
+ def test_args_star__anon_trailing
5654
+ rb = "f(x, *)"
5655
+ pt = s(:call, nil, :f, s(:call, nil, :x), s(:splat))
5656
+
5657
+ assert_parse rb, pt
5658
+ end
5659
+
5660
+ def test_args_dstar__anon_solo
5661
+ rb = "f(**)"
5662
+ pt = s(:call, nil, :f, s(:hash, s(:kwsplat))) # TODO double check this
5663
+
5664
+ assert_parse rb, pt
5665
+ end
5666
+
5667
+ def test_args_dstar__anon_trailing
5668
+ rb = "f(x, **)"
5669
+ pt = s(:call, nil, :f, s(:call, nil, :x), s(:hash, s(:kwsplat))) # TODO double check this
5670
+
5671
+ assert_parse rb, pt
5672
+ end
5483
5673
  end
5484
5674
 
5485
5675
  class Minitest::Test
@@ -5782,8 +5972,6 @@ class TestRubyParserV26 < RubyParserTestCase
5782
5972
  end
5783
5973
 
5784
5974
  class TestRubyParserV27 < RubyParserTestCase
5785
- make_my_diffs_pretty!
5786
-
5787
5975
  include TestRubyParserShared27Plus
5788
5976
 
5789
5977
  def setup
data/tools/munge.rb CHANGED
@@ -174,6 +174,10 @@ ARGF.each_line do |line|
174
174
  last_token = token
175
175
  when /^Reading a token: / then
176
176
  next # skip
177
+ when /^Reading a token$/ then # wtf?
178
+ next # skip
179
+ when /^(?:add_delayed_token|parser_dispatch)/ then # dunno what this is yet
180
+ next # skip
177
181
  when /^read\s+:(\w+)/ then # read :tNL(tNL) nil
178
182
  token = munge $1
179
183
  next if last_token == token
@@ -212,7 +216,9 @@ ARGF.each_line do |line|
212
216
  reduce_line = nil
213
217
  stack.clear
214
218
  when /^reduce/ then # ruby_parser side
215
- puts munge line.chomp
219
+ s = munge line.chomp
220
+ next if s =~ /reduce\s+(\w+) --> \1/
221
+ puts s
216
222
  puts
217
223
  when /^(\w+_stack)\.(\w+)/ then
218
224
  # TODO: make pretty, but still informative w/ line numbers etc
@@ -223,7 +229,7 @@ ARGF.each_line do |line|
223
229
  # puts line
224
230
  # TODO: make pretty, but still informative w/ line numbers etc
225
231
  puts line.gsub("true", "1").gsub("false", "0")
226
- when /^lex_state: :?([\w|]+) -> :?([\w|]+)(?: (?:at|from) (.*))?/ then
232
+ when /^lex_state: :?([\w|()]+) -> :?([\w|]+)(?: (?:at|from) (.*))?/ then
227
233
  a, b, c = $1.upcase, $2.upcase, $3
228
234
  a.gsub!(/EXPR_/, "")
229
235
  b.gsub!(/EXPR_/, "")
data/tools/ripper.rb CHANGED
@@ -21,18 +21,20 @@ end
21
21
  ARGV.each do |path|
22
22
  src = path == "-" ? $stdin.read : File.read(path)
23
23
 
24
- sexp = if $b then
25
- Ripper.sexp src
26
- else
27
- rip = MySexpBuilder.new src
28
- rip.yydebug = $d
29
- rip.parse
30
-
31
- if rip.error? then
32
- warn "skipping"
33
- next
34
- end
35
- end
24
+ sexp = nil
25
+
26
+ if $b then
27
+ sexp = Ripper.sexp src
28
+ else
29
+ rip = MySexpBuilder.new src
30
+ rip.yydebug = $d
31
+ sexp = rip.parse
32
+
33
+ if rip.error? then
34
+ warn "skipping"
35
+ next
36
+ end
37
+ end
36
38
 
37
39
  puts "accept"
38
40
 
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.3
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-07-12 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