ruby_parser 3.20.3 → 3.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/History.rdoc +32 -0
  4. data/Manifest.txt +14 -24
  5. data/README.rdoc +3 -3
  6. data/Rakefile +113 -115
  7. data/compare/normalize.rb +2 -0
  8. data/lib/ruby_lexer.rb +9 -16
  9. data/lib/ruby_lexer.rex.rb +1 -2
  10. data/lib/ruby_parser.rb +15 -13
  11. data/lib/{ruby_parser.yy → ruby_parser2.yy} +3 -10
  12. data/lib/{ruby20_parser.rb → ruby_parser20.rb} +9 -12
  13. data/lib/{ruby21_parser.rb → ruby_parser21.rb} +9 -12
  14. data/lib/{ruby22_parser.rb → ruby_parser22.rb} +9 -12
  15. data/lib/{ruby23_parser.rb → ruby_parser23.rb} +9 -12
  16. data/lib/{ruby24_parser.rb → ruby_parser24.rb} +9 -12
  17. data/lib/{ruby25_parser.rb → ruby_parser25.rb} +9 -12
  18. data/lib/{ruby26_parser.rb → ruby_parser26.rb} +9 -12
  19. data/lib/{ruby27_parser.rb → ruby_parser27.rb} +9 -12
  20. data/lib/{ruby3_parser.yy → ruby_parser3.yy} +7 -33
  21. data/lib/{ruby30_parser.rb → ruby_parser30.rb} +11 -35
  22. data/lib/{ruby31_parser.rb → ruby_parser31.rb} +11 -35
  23. data/lib/{ruby32_parser.rb → ruby_parser32.rb} +11 -35
  24. data/lib/ruby_parser33.rb +13577 -0
  25. data/lib/ruby_parser_extras.rb +34 -17
  26. data/test/test_ruby_lexer.rb +5 -5
  27. data/test/test_ruby_parser.rb +21 -19
  28. data.tar.gz.sig +0 -0
  29. metadata +41 -51
  30. metadata.gz.sig +0 -0
  31. data/lib/ruby20_parser.y +0 -2707
  32. data/lib/ruby21_parser.y +0 -2724
  33. data/lib/ruby22_parser.y +0 -2735
  34. data/lib/ruby23_parser.y +0 -2737
  35. data/lib/ruby24_parser.y +0 -2745
  36. data/lib/ruby25_parser.y +0 -2745
  37. data/lib/ruby26_parser.y +0 -2760
  38. data/lib/ruby27_parser.y +0 -3360
  39. data/lib/ruby30_parser.y +0 -3508
  40. data/lib/ruby31_parser.y +0 -3542
  41. data/lib/ruby32_parser.y +0 -3543
@@ -30,11 +30,11 @@ class Sexp
30
30
  end
31
31
 
32
32
  module RubyParserStuff
33
- VERSION = "3.20.3"
33
+ VERSION = "3.21.0"
34
34
 
35
35
  attr_accessor :lexer, :in_def, :in_single, :file, :in_argdef
36
36
  attr_accessor :in_kwarg
37
- attr_reader :env, :comments
37
+ attr_reader :env
38
38
 
39
39
  ##
40
40
  # Canonicalize conditionals. Eg:
@@ -92,6 +92,7 @@ module RubyParserStuff
92
92
  [k, true]
93
93
  }.to_h
94
94
 
95
+ # TODO: remove
95
96
  has_enc = "".respond_to? :encoding
96
97
 
97
98
  # This is in sorted order of occurrence according to
@@ -125,7 +126,6 @@ module RubyParserStuff
125
126
  self.in_argdef = false
126
127
 
127
128
  @env = RubyParserStuff::Environment.new
128
- @comments = []
129
129
 
130
130
  @canonicalize_conditions = true
131
131
 
@@ -567,7 +567,7 @@ module RubyParserStuff
567
567
 
568
568
  def handle_encoding str
569
569
  str = str.dup
570
- has_enc = str.respond_to? :encoding
570
+ has_enc = str.respond_to? :encoding # TODO: remove
571
571
  encoding = nil
572
572
 
573
573
  header = str.each_line.first(2)
@@ -929,7 +929,7 @@ module RubyParserStuff
929
929
  end
930
930
 
931
931
  def new_class val
932
- (_, line), path, superclass, _, body, (_, line_max) = val
932
+ (_, line, comment), path, superclass, _, body, (_, line_max) = val
933
933
 
934
934
  path = path.first if path.instance_of? Array
935
935
 
@@ -945,7 +945,7 @@ module RubyParserStuff
945
945
 
946
946
  result.line = line
947
947
  result.line_max = line_max
948
- result.comments = self.comments.pop
948
+ result.comments = comment if comment
949
949
  result
950
950
  end
951
951
 
@@ -973,7 +973,11 @@ module RubyParserStuff
973
973
  end
974
974
 
975
975
  def new_defn val
976
- _, (name, line), in_def, args, body, (_, line_max) = val
976
+ if val.size == 4 then
977
+ ((_, line, comment), (name, _line, in_def)), args, body, (_, line_max) = val
978
+ else
979
+ (_, line, comment), (name, line), in_def, args, body, (_, line_max) = val
980
+ end
977
981
 
978
982
  body ||= s(:nil).line line
979
983
 
@@ -988,13 +992,14 @@ module RubyParserStuff
988
992
  result.push body
989
993
  end
990
994
 
991
- result.comments = self.comments.pop
995
+ result.comments = comment if comment
992
996
 
993
997
  [result, in_def]
994
998
  end
995
999
 
996
1000
  def new_endless_defn val
997
- (name, line, in_def), args, _, body, _, resbody = val
1001
+ # not available in 2.x so we don't need to check size
1002
+ ((_, line, comment), (name, _, in_def)), args, _, body, _, resbody = val
998
1003
 
999
1004
  result =
1000
1005
  if resbody then
@@ -1009,13 +1014,15 @@ module RubyParserStuff
1009
1014
  local_pop in_def
1010
1015
  endless_method_name result
1011
1016
 
1012
- result.comments = self.comments.pop
1017
+ result.comments = comment if comment
1013
1018
 
1014
1019
  result
1015
1020
  end
1016
1021
 
1017
1022
  def new_endless_defs val
1018
- (recv, (name, line, in_def)), args, _, body, _, resbody = val
1023
+ # not available in 2.x so we don't need to check size
1024
+ ((_, line, comment), recv, _, _, (name, line, in_def)), \
1025
+ args, _, body, _, resbody = val
1019
1026
 
1020
1027
  result =
1021
1028
  if resbody then
@@ -1031,13 +1038,19 @@ module RubyParserStuff
1031
1038
  local_pop in_def
1032
1039
  endless_method_name result
1033
1040
 
1034
- result.comments = self.comments.pop
1041
+ result.comments = comment if comment
1035
1042
 
1036
1043
  result
1037
1044
  end
1038
1045
 
1039
1046
  def new_defs val
1040
- _, recv, (name, line), in_def, args, body, (_, line_max) = val
1047
+ if val.size == 4 then
1048
+ ((_, line, comment), recv, _, _, (name, line, in_def)), \
1049
+ args, body, (_, line_max) = val
1050
+ else
1051
+ (_, line, comment), recv, (name, _), in_def, \
1052
+ args, body, (_, line_max) = val
1053
+ end
1041
1054
 
1042
1055
  body ||= s(:nil).line line
1043
1056
 
@@ -1055,7 +1068,7 @@ module RubyParserStuff
1055
1068
  result.push body
1056
1069
  end
1057
1070
 
1058
- result.comments = self.comments.pop
1071
+ result.comments = comment if comment
1059
1072
 
1060
1073
  [result, in_def]
1061
1074
  end
@@ -1209,7 +1222,7 @@ module RubyParserStuff
1209
1222
  end
1210
1223
 
1211
1224
  def new_module val
1212
- (_, line_min), path, _, body, (_, line_max) = val
1225
+ (_, line_min, comment), path, _, body, (_, line_max) = val
1213
1226
 
1214
1227
  path = path.first if path.instance_of? Array
1215
1228
 
@@ -1224,7 +1237,7 @@ module RubyParserStuff
1224
1237
  end
1225
1238
  end
1226
1239
 
1227
- result.comments = self.comments.pop
1240
+ result.comments = comment if comment
1228
1241
  result
1229
1242
  end
1230
1243
 
@@ -1518,11 +1531,16 @@ module RubyParserStuff
1518
1531
  end
1519
1532
  end
1520
1533
 
1534
+ KEEP_COMMENT_TOKENS = [:kCLASS, :kMODULE, :kDEF, :tNL]
1535
+
1521
1536
  def next_token
1522
1537
  token = self.lexer.next_token
1523
1538
 
1524
1539
  if token and token.first != RubyLexer::EOF then
1525
1540
  self.last_token_type = token
1541
+
1542
+ self.lexer.comment = nil unless KEEP_COMMENT_TOKENS.include? token.first
1543
+
1526
1544
  return token
1527
1545
  elsif !token
1528
1546
  return self.lexer.next_token
@@ -1582,7 +1600,6 @@ module RubyParserStuff
1582
1600
  self.in_def = false
1583
1601
  self.in_single = 0
1584
1602
  self.env.reset
1585
- self.comments.clear
1586
1603
  self.last_token_type = nil
1587
1604
  end
1588
1605
 
@@ -584,7 +584,7 @@ class TestRubyLexer < Minitest::Test
584
584
  :tNL, nil, EXPR_BEG,
585
585
  :tINTEGER, 2, EXPR_NUM)
586
586
 
587
- assert_equal "# one\n# two\n", @lex.comments
587
+ assert_equal "# one\n# two\n", @lex.comment
588
588
  end
589
589
 
590
590
  def test_yylex_comment_begin
@@ -592,13 +592,13 @@ class TestRubyLexer < Minitest::Test
592
592
  nil,
593
593
  :tINTEGER, 42, EXPR_NUM)
594
594
 
595
- assert_equal "=begin\nblah\nblah\n=end\n", @lex.comments
595
+ assert_equal "=begin\nblah\nblah\n=end\n", @lex.comment
596
596
  end
597
597
 
598
598
  def test_yylex_comment_begin_bad
599
599
  refute_lex("=begin\nblah\nblah\n")
600
600
 
601
- assert_equal "", @lex.comments
601
+ assert_nil @lex.comment
602
602
  end
603
603
 
604
604
  def test_yylex_comment_begin_not_comment
@@ -617,13 +617,13 @@ class TestRubyLexer < Minitest::Test
617
617
  def test_yylex_comment_begin_space
618
618
  assert_lex3("=begin blah\nblah\n=end\n", nil)
619
619
 
620
- assert_equal "=begin blah\nblah\n=end\n", @lex.comments
620
+ assert_equal "=begin blah\nblah\n=end\n", @lex.comment
621
621
  end
622
622
 
623
623
  def test_yylex_comment_end_space_and_text
624
624
  assert_lex3("=begin blah\nblah\n=end blab\n", nil)
625
625
 
626
- assert_equal "=begin blah\nblah\n=end blab\n", @lex.comments
626
+ assert_equal "=begin blah\nblah\n=end blab\n", @lex.comment
627
627
  end
628
628
 
629
629
  def test_yylex_comment_eos
@@ -500,7 +500,7 @@ module TestRubyParserShared
500
500
  exp = rb.strip + "\n"
501
501
 
502
502
  refute_parse rb
503
- assert_equal exp, processor.lexer.comments
503
+ assert_equal exp, processor.lexer.comment
504
504
  end
505
505
 
506
506
  def test_bug_cond_pct
@@ -1722,11 +1722,10 @@ module TestRubyParserShared
1722
1722
 
1723
1723
  assert_equal "# class comment\n", sexp.comments
1724
1724
  act = sexp.find_nodes(:defn).map(&:comments)
1725
- exp = ["", "# Returns a list of things\n"]
1725
+ exp = [nil, "# Returns a list of things\n"]
1726
1726
 
1727
1727
  assert_equal exp, act
1728
- assert_equal [], processor.comments
1729
- assert_equal "", processor.lexer.comments
1728
+ assert_nil processor.lexer.comment
1730
1729
  end
1731
1730
 
1732
1731
  def test_parse_if_not_canonical
@@ -5672,6 +5671,10 @@ module TestRubyParserShared32Plus
5672
5671
  end
5673
5672
  end
5674
5673
 
5674
+ module TestRubyParserShared33Plus
5675
+ include TestRubyParserShared32Plus
5676
+ end
5677
+
5675
5678
  class Minitest::Test
5676
5679
  def skip s = "blah"
5677
5680
  warn "ignoring skip for %s: %s" % [name, s]
@@ -5693,28 +5696,17 @@ class TestRubyParser < Minitest::Test
5693
5696
  pt = s(:call, s(:call, nil, :a), :call)
5694
5697
 
5695
5698
  assert_equal pt, processor.parse(rb)
5696
-
5697
- # bad syntax
5698
- e = assert_raises Racc::ParseError do
5699
- capture_io do
5700
- processor.parse "a.("
5701
- end
5702
- end
5703
-
5704
- assert_includes e.message, 'parse error on value "$" ($end)'
5705
5699
  end
5706
5700
 
5707
- def test_parse_error_from_first
5701
+ def test_parse_error
5708
5702
  processor = RubyParser.new
5709
5703
 
5704
+ # bad syntax
5710
5705
  e = assert_raises Racc::ParseError do
5711
- capture_io do
5712
- processor.parse "a -> () {"
5713
- end
5706
+ processor.parse "a.("
5714
5707
  end
5715
5708
 
5716
- # This is a 2.x error, will fail on 1.8/1.9.
5717
- assert_includes e.message, 'parse error on value "$" ($end)'
5709
+ assert_match(/parse error on value \S+ ..end./, e.message)
5718
5710
  end
5719
5711
  end
5720
5712
 
@@ -6031,6 +6023,16 @@ class TestRubyParserV32 < RubyParserTestCase
6031
6023
  end
6032
6024
  end
6033
6025
 
6026
+ class TestRubyParserV33 < RubyParserTestCase
6027
+ include TestRubyParserShared33Plus
6028
+
6029
+ def setup
6030
+ super
6031
+
6032
+ self.processor = RubyParser::V33.new
6033
+ end
6034
+ end
6035
+
6034
6036
  RubyParser::VERSIONS.each do |klass|
6035
6037
  v = klass.version
6036
6038
  describe "block args arity #{v}" do
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.3
4
+ version: 3.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBBzANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDPjCCAiagAwIBAgIBCDANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTIzMDEwMTA3NTExN1oXDTI0MDEwMTA3NTExN1owRTETMBEGA1UE
15
+ GRYDY29tMB4XDTI0MDEwMjIxMjEyM1oXDTI1MDEwMTIxMjEyM1owRTETMBEGA1UE
16
16
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
17
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
18
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -22,14 +22,14 @@ cert_chain:
22
22
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
23
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
24
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
25
- AQAkg3y+PBnBAPWdxxITm5sPHqdWQgSyCpRA20o4LTuWr8BWhSXBkfQNa7cY6fOn
26
- xyM34VPzBFbExv6XOGDfOMFBVaYTHuN9peC/5/umL7kLl+nflXzL2QA7K6LYj5Bg
27
- sM574Onr0dZDM6Vn69bzQ7rBIFDfK/OhlPzqKZad4nsdcsVH8ODCiT+ATMIZyz5K
28
- WCnNtqlyiWXI8tdTpahDgcUwfcN/oN7v4K8iU5IbLJX6HQ5DKgmKjfb6XyMth16k
29
- ROfWo9Uyp8ba/j9eVG14KkYRaLydAY1MNQk2yd3R5CGfeOpD1kttxjoypoUJ2dOG
30
- nsNBRuQJ1UfiCG97a6DNm+Fr
25
+ AQCygvpmncmkiSs9r/Kceo4bBPDszhTv6iBi4LwMReqnFrpNLMOWJw7xi8x+3eL2
26
+ XS09ZPNOt2zm70KmFouBMgOysnDY4k2dE8uF6B8JbZOO8QfalW+CoNBliefOTcn2
27
+ bg5IOP7UoGM5lC174/cbDJrJnRG9bzig5FAP0mvsgA8zgTRXQzIUAZEo92D5K7p4
28
+ B4/O998ho6BSOgYBI9Yk1ttdCtti6Y+8N9+fZESsjtWMykA+WXWeGUScHqiU+gH8
29
+ S7043fq9EbQdBr2AXdj92+CDwuTfHI6/Hj5FVBDULufrJaan4xUgL70Hvc6pTTeW
30
+ deKfBjgVAq7EYHu1AczzlUly
31
31
  -----END CERTIFICATE-----
32
- date: 2023-07-12 00:00:00.000000000 Z
32
+ date: 2024-01-16 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -45,6 +45,20 @@ dependencies:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.16'
48
+ - !ruby/object:Gem::Dependency
49
+ name: racc
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: rake
50
64
  requirement: !ruby/object:Gem::Requirement
@@ -79,20 +93,6 @@ dependencies:
79
93
  - - "~>"
80
94
  - !ruby/object:Gem::Version
81
95
  version: '2.6'
82
- - !ruby/object:Gem::Dependency
83
- name: racc
84
- requirement: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '1.5'
89
- type: :development
90
- prerelease: false
91
- version_requirements: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '1.5'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: rdoc
98
98
  requirement: !ruby/object:Gem::Requirement
@@ -119,14 +119,14 @@ dependencies:
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '4.0'
122
+ version: '4.2'
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '4.0'
129
+ version: '4.2'
130
130
  description: |-
131
131
  ruby_parser (RP) is a ruby parser written in pure ruby (utilizing
132
132
  racc--which does by default use a C extension). It outputs
@@ -184,35 +184,25 @@ files:
184
184
  - lib/.document
185
185
  - lib/rp_extensions.rb
186
186
  - lib/rp_stringscanner.rb
187
- - lib/ruby20_parser.rb
188
- - lib/ruby20_parser.y
189
- - lib/ruby21_parser.rb
190
- - lib/ruby21_parser.y
191
- - lib/ruby22_parser.rb
192
- - lib/ruby22_parser.y
193
- - lib/ruby23_parser.rb
194
- - lib/ruby23_parser.y
195
- - lib/ruby24_parser.rb
196
- - lib/ruby24_parser.y
197
- - lib/ruby25_parser.rb
198
- - lib/ruby25_parser.y
199
- - lib/ruby26_parser.rb
200
- - lib/ruby26_parser.y
201
- - lib/ruby27_parser.rb
202
- - lib/ruby27_parser.y
203
- - lib/ruby30_parser.rb
204
- - lib/ruby30_parser.y
205
- - lib/ruby31_parser.rb
206
- - lib/ruby31_parser.y
207
- - lib/ruby32_parser.rb
208
- - lib/ruby32_parser.y
209
- - lib/ruby3_parser.yy
210
187
  - lib/ruby_lexer.rb
211
188
  - lib/ruby_lexer.rex
212
189
  - lib/ruby_lexer.rex.rb
213
190
  - lib/ruby_lexer_strings.rb
214
191
  - lib/ruby_parser.rb
215
- - lib/ruby_parser.yy
192
+ - lib/ruby_parser2.yy
193
+ - lib/ruby_parser20.rb
194
+ - lib/ruby_parser21.rb
195
+ - lib/ruby_parser22.rb
196
+ - lib/ruby_parser23.rb
197
+ - lib/ruby_parser24.rb
198
+ - lib/ruby_parser25.rb
199
+ - lib/ruby_parser26.rb
200
+ - lib/ruby_parser27.rb
201
+ - lib/ruby_parser3.yy
202
+ - lib/ruby_parser30.rb
203
+ - lib/ruby_parser31.rb
204
+ - lib/ruby_parser32.rb
205
+ - lib/ruby_parser33.rb
216
206
  - lib/ruby_parser_extras.rb
217
207
  - test/test_ruby_lexer.rb
218
208
  - test/test_ruby_parser.rb
@@ -245,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
245
235
  - !ruby/object:Gem::Version
246
236
  version: '0'
247
237
  requirements: []
248
- rubygems_version: 3.4.10
238
+ rubygems_version: 3.5.3
249
239
  signing_key:
250
240
  specification_version: 4
251
241
  summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which
metadata.gz.sig CHANGED
Binary file