ruby2ruby 2.5.1 → 2.6.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce3916335beb18e635634b93a85be8c88aaaab6029aea5ba5426b429cebbb2a6
4
- data.tar.gz: e443e89cd7216bee0ae5d2fc8b182cafb94827357cb82d2b248cb19e2a26b6bd
3
+ metadata.gz: c6f7e4e4fcbd415175663732f01b2dbb0291578dc12e0121e8e777d73b9dbb90
4
+ data.tar.gz: 6282de7f06e33662c5d9f3b8fc531685cd32e90d74682f119f13f6d1d5e39702
5
5
  SHA512:
6
- metadata.gz: 62655af018fce2402bb410d7606afb34f7a6f332c88fc74aca6ebf9faf5f37abd23d9827cfd5d5742d3240d89ae838f4ef7d28f92da7bc520c335467b89a448a
7
- data.tar.gz: 637c87a736b4da72487c95bc8fa981d49ba9b57e3e8f48c2013ef52bbbcb09176c0abfae18b272cba551adcb5961bcad6e94fa38dee8352f154986861cf7e616
6
+ metadata.gz: a8d4ba7db3c8b768c659c0873e85037a98ba39d1008f91c3f84bc5f3d3ffa5e7efad9fc05d3c610dbab5f71239b1f068a8a727292dcbdc21311ab11ba7141d83
7
+ data.tar.gz: cace0a14c47e09fc9ef555b62207ebe630e958d51bcc0cdb9493c6e279065a0b23229c983c3e865c0ecd70aef3b779ea10f4426aa57a50880fe0163b9bf32574
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,21 @@
1
+ === 2.6.0 / 2025-12-24
2
+
3
+ * 3 minor enhancements:
4
+
5
+ * Added prism as a development dependency.
6
+ * Bumped ruby_version to 3.2+.
7
+ * Removed ruby_parser as a runtime dependency.
8
+
9
+ * 1 bug fix:
10
+
11
+ * Minor fixes to impl for comment processing. Prism returns chomped string.
12
+
13
+ === 2.5.2 / 2025-03-25
14
+
15
+ * 1 bug fix:
16
+
17
+ * Added support for 3 slot op_asgn (eg `a &= 1`)
18
+
1
19
  === 2.5.1 / 2024-07-08
2
20
 
3
21
  * 1 bug fix:
data/Rakefile CHANGED
@@ -17,7 +17,11 @@ Hoe.spec 'ruby2ruby' do
17
17
  license "MIT"
18
18
 
19
19
  dependency "sexp_processor", "~> 4.6"
20
- dependency "ruby_parser", "~> 3.1"
20
+ dependency "prism", "~> 1.7", :dev
21
+
22
+ require_ruby_version ">= 3.2"
23
+
24
+ self.isolate_multiruby = true
21
25
  end
22
26
 
23
27
  def process ruby, file="stdin"
data/lib/ruby2ruby.rb CHANGED
@@ -31,7 +31,7 @@ end
31
31
  # Generate ruby code from a sexp.
32
32
 
33
33
  class Ruby2Ruby < SexpProcessor
34
- VERSION = "2.5.1" # :nodoc:
34
+ VERSION = "2.6.0" # :nodoc:
35
35
 
36
36
  # cutoff for one-liners
37
37
  LINE_LENGTH = 78
@@ -350,8 +350,14 @@ class Ruby2Ruby < SexpProcessor
350
350
  end
351
351
  end
352
352
 
353
+ def comments exp # :nodoc:
354
+ comments = exp.comments
355
+ comments += "\n" unless comments.end_with?("\n") if comments
356
+ comments
357
+ end
358
+
353
359
  def process_class exp # :nodoc:
354
- "#{exp.comments}class #{util_module_or_class(exp, true)}"
360
+ "#{comments exp}class #{util_module_or_class(exp, true)}"
355
361
  end
356
362
 
357
363
  def process_colon2 exp # :nodoc:
@@ -411,7 +417,7 @@ class Ruby2Ruby < SexpProcessor
411
417
  def process_defn(exp) # :nodoc:
412
418
  _, name, args, *body = exp
413
419
 
414
- comm = exp.comments
420
+ comm = comments exp
415
421
  args = process args
416
422
  args = "" if args == "()"
417
423
 
@@ -887,7 +893,7 @@ class Ruby2Ruby < SexpProcessor
887
893
  end
888
894
 
889
895
  def process_module(exp) # :nodoc:
890
- "#{exp.comments}module #{util_module_or_class(exp)}"
896
+ "#{comments exp}module #{util_module_or_class(exp)}"
891
897
  end
892
898
 
893
899
  def process_next(exp) # :nodoc:
@@ -916,11 +922,14 @@ class Ruby2Ruby < SexpProcessor
916
922
  end
917
923
 
918
924
  def process_op_asgn exp # :nodoc:
919
- # [[:lvar, :x], [:call, nil, :z, [:lit, 1]], :y, :"||"]
920
-
921
925
  case exp.length
922
926
  when 4
923
- raise "NOT YET: op_asgn 4"
927
+ _, lhs, op, rhs = exp
928
+
929
+ lhs = process lhs
930
+ rhs = process rhs
931
+
932
+ "#{lhs} #{op}= #{rhs}"
924
933
  when 5
925
934
  _, lhs, rhs, index, op = exp
926
935
 
@@ -9,7 +9,21 @@ require "ruby2ruby"
9
9
  require "pt_testcase"
10
10
  require "fileutils"
11
11
  require "tmpdir"
12
- require "ruby_parser" if ENV["CHECK_SEXPS"]
12
+ require "prism"
13
+
14
+ class NotRubyParser < Prism::Translation::RubyParser
15
+ attr_accessor :scopes
16
+
17
+ def initialize scopes:nil
18
+ super()
19
+ self.scopes = [scopes] if scopes
20
+ end
21
+
22
+ # overridden from prism to add scopes arg
23
+ def parse(source, filepath = "(string)")
24
+ translate(Prism.parse(source, filepath:, partial_script: true, scopes:), filepath)
25
+ end
26
+ end
13
27
 
14
28
  class R2RTestCase < ParseTreeTestCase
15
29
  def self.previous key
@@ -42,13 +56,8 @@ class TestRuby2Ruby < R2RTestCase
42
56
  @processor = Ruby2Ruby.new
43
57
  end
44
58
 
45
- # some things don't work in earlier rubies... oh well.
46
- def skip30
47
- skip unless RUBY_VERSION > "3.0"
48
- end
49
-
50
- def skip31
51
- skip unless RUBY_VERSION > "3.1"
59
+ def skip_prism
60
+ skip "not fully happy with prism yet"
52
61
  end
53
62
 
54
63
  def do_not_check_sexp!
@@ -135,8 +144,6 @@ class TestRuby2Ruby < R2RTestCase
135
144
  end
136
145
 
137
146
  def test_hash_shorthand_invalid_key_type
138
- do_not_check_sexp!
139
-
140
147
  inn = s(:hash, s(:str, 'k'), nil)
141
148
  out = '{ k: }'
142
149
  assert_raises do
@@ -185,11 +192,11 @@ class TestRuby2Ruby < R2RTestCase
185
192
  end
186
193
 
187
194
  def assert_str exp, src
188
- assert_equal s(:str, exp), RubyParser.new.process(src)
195
+ assert_equal s(:str, exp), NotRubyParser.new.process(src)
189
196
  end
190
197
 
191
198
  def assert_dstr exp, int, src
192
- assert_equal s(:dstr, exp, s(:evstr, int).compact), RubyParser.new.process(src)
199
+ assert_equal s(:dstr, exp, s(:evstr, int).compact), NotRubyParser.new.process(src)
193
200
  end
194
201
 
195
202
  def assert_r2r exp, sexp
@@ -197,7 +204,7 @@ class TestRuby2Ruby < R2RTestCase
197
204
  end
198
205
 
199
206
  def assert_rt src, exp = src.dup
200
- assert_equal exp, Ruby2Ruby.new.process(RubyParser.new.parse(src))
207
+ assert_equal exp, Ruby2Ruby.new.process(NotRubyParser.new.parse(src))
201
208
  end
202
209
 
203
210
  def test_bug_033
@@ -329,8 +336,6 @@ class TestRuby2Ruby < R2RTestCase
329
336
  end
330
337
 
331
338
  def test_dregx_slash
332
- do_not_check_sexp!
333
-
334
339
  inn = util_thingy(:dregx)
335
340
  out = '/a"b#{(1 + 1)}c"d\/e/'
336
341
  assert_parse inn, out, /a"b2c"d\/e/
@@ -349,8 +354,6 @@ class TestRuby2Ruby < R2RTestCase
349
354
  end
350
355
 
351
356
  def test_lit_regexp_slash
352
- do_not_check_sexp! # dunno why on this one
353
-
354
357
  assert_parse s(:lit, /blah\/blah/), '/blah\/blah/', /blah\/blah/
355
358
  end
356
359
 
@@ -447,7 +450,6 @@ class TestRuby2Ruby < R2RTestCase
447
450
  end
448
451
 
449
452
  def test_forward_args__call
450
- skip31
451
453
 
452
454
  inn = s(:defn, :x, s(:args, s(:forward_args)), s(:call, nil, :y, s(:forward_args)))
453
455
  out = "def x(...)\n y(...)\nend"
@@ -746,7 +748,12 @@ class TestRuby2Ruby < R2RTestCase
746
748
  end
747
749
 
748
750
  def test_case_in__array_pat_04
749
- assert_case_in "[[:b, ^c], [:d, ^e]]", s(:array_pat, nil, s(:array_pat, nil, s(:lit, :b), s(:lvar, :c)), s(:array_pat, nil, s(:lit, :d), s(:lvar, :e)))
751
+ pt = s(:array_pat,
752
+ nil,
753
+ s(:array_pat, nil, s(:lit, :b), s(:lvar, :c)),
754
+ s(:array_pat, nil, s(:lit, :d), s(:lvar, :a)))
755
+
756
+ assert_case_in "[[:b, ^c], [:d, ^a]]", pt
750
757
  end
751
758
 
752
759
  def test_case_in__array_pat_06
@@ -774,22 +781,16 @@ class TestRuby2Ruby < R2RTestCase
774
781
  end
775
782
 
776
783
  def test_case_in__array_pat_19
777
- skip31
778
-
779
784
  assert_case_in "[^@a, ^$b, ^@@c]", s(:array_pat, nil, s(:ivar, :@a), s(:gvar, :$b), s(:cvar, :@@c)) # HACK: really not sure about this one
780
785
  end
781
786
 
782
787
  def test_case_in__find_pat_1
783
- skip30
784
-
785
788
  assert_case_in "[*a, :+, *b]", s(:find_pat, nil, :"*a",
786
789
  s(:lit, :+),
787
790
  :"*b")
788
791
  end
789
792
 
790
793
  def test_case_in__find_pat_2
791
- skip30
792
-
793
794
  assert_case_in "[*, :b, ^c, *]", s(:find_pat, nil,
794
795
  :*,
795
796
  s(:lit, :b), s(:lvar, :c),
@@ -797,35 +798,30 @@ class TestRuby2Ruby < R2RTestCase
797
798
  end
798
799
 
799
800
  def test_case_in__find_pat_3
800
- skip30
801
-
802
- assert_case_in("Array(*b, n, { a: }, m, *a)",
801
+ assert_case_in("Array(*b, n, { a: }, m, *c)",
803
802
  s(:find_pat,
804
803
  s(:const, :Array),
805
804
  :"*b",
806
805
  s(:lasgn, :n),
807
806
  s(:hash_pat, nil, s(:lit, :a), nil),
808
807
  s(:lasgn, :m),
809
- :"*a"),
810
- "Array[*b, n, { a: }, m, *a]")
808
+ :"*c"),
809
+ "Array[*b, n, { a: }, m, *c]")
811
810
  end
812
811
 
813
812
  def test_case_in__find_pat_4
814
- skip30
815
-
816
- assert_case_in("*b, n, { a: }, m, *a", s(:find_pat,
817
- nil,
818
- :"*b",
819
- s(:lasgn, :n),
820
- s(:hash_pat, nil, s(:lit, :a), nil),
821
- s(:lasgn, :m),
822
- :"*a"),
823
- "[*b, n, { a: }, m, *a]")
813
+ assert_case_in("*b, n, { a: }, m, *c",
814
+ s(:find_pat,
815
+ nil,
816
+ :"*b",
817
+ s(:lasgn, :n),
818
+ s(:hash_pat, nil, s(:lit, :a), nil),
819
+ s(:lasgn, :m),
820
+ :"*c"),
821
+ "[*b, n, { a: }, m, *c]")
824
822
  end
825
823
 
826
824
  def test_case_in__find_pat_5
827
- skip30
828
-
829
825
  assert_case_in("Array(*lhs, ^b, *rhs)", s(:find_pat,
830
826
  s(:const, :Array),
831
827
  :"*lhs",
@@ -949,10 +945,10 @@ class TestRuby2Ruby < R2RTestCase
949
945
  s(:array_pat,
950
946
  nil,
951
947
  s(:lit, :d),
952
- s(:lvar, :e)),
948
+ s(:lvar, :a)),
953
949
  )
954
950
 
955
- assert_case_in "[[:b, c], [:d, ^e]]", pt
951
+ assert_case_in "[[:b, c], [:d, ^a]]", pt
956
952
  end
957
953
 
958
954
  def test_case_in__hash_pat_00
@@ -1067,6 +1063,13 @@ class TestRuby2Ruby < R2RTestCase
1067
1063
  assert_parse inn, out
1068
1064
  end
1069
1065
 
1066
+ def test_op_asgn_4
1067
+ inn = s(:op_asgn, s(:colon3, :X), :"&", s(:lit, 1))
1068
+
1069
+ out = "::X &= 1"
1070
+ assert_parse inn, out
1071
+ end
1072
+
1070
1073
  def test_rescue_block
1071
1074
  inn = s(:rescue,
1072
1075
  s(:call, nil, :alpha),
@@ -1096,7 +1099,7 @@ class TestRuby2Ruby < R2RTestCase
1096
1099
  end
1097
1100
 
1098
1101
  def test_unless_vs_if_not
1099
- do_not_check_sexp! # TODO: remove? dunno if that's possible w/ this one
1102
+ do_not_check_sexp! # dunno if it's possible to remove this one
1100
1103
 
1101
1104
  rb1 = "a unless b"
1102
1105
  rb2 = "a if (not b)"
@@ -1110,13 +1113,7 @@ class TestRuby2Ruby < R2RTestCase
1110
1113
  end
1111
1114
 
1112
1115
  def ruby_parser
1113
- parser = RubyParser.latest
1114
-
1115
- %i[a b c d].each do |v|
1116
- parser.env[v] = :lvar
1117
- end
1118
-
1119
- parser
1116
+ NotRubyParser.new scopes: %i[a b c d]
1120
1117
  end
1121
1118
 
1122
1119
  def assert_parse sexp, expected_ruby, expected_eval = nil
@@ -1178,8 +1175,7 @@ ir2r = File.read("lib/ruby2ruby.rb")
1178
1175
  require "ruby_parser"
1179
1176
 
1180
1177
  def morph_and_eval src, from, to, processor
1181
- parser = RubyParser.latest
1182
- new_src = processor.new.process(parser.process(src.sub(from, to)))
1178
+ new_src = processor.new.process(NotRubyParser.new.process(src.sub(from, to)))
1183
1179
 
1184
1180
  eval new_src
1185
1181
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain:
11
10
  - |
12
11
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBCDANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
12
+ MIIDPjCCAiagAwIBAgIBCTANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
13
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
15
- GRYDY29tMB4XDTI0MDEwMjIxMjEyM1oXDTI1MDEwMTIxMjEyM1owRTETMBEGA1UE
14
+ GRYDY29tMB4XDTI1MDEwNjIzMjcwMVoXDTI2MDEwNjIzMjcwMVowRTETMBEGA1UE
16
15
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
17
16
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
18
17
  b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
@@ -22,14 +21,14 @@ cert_chain:
22
21
  qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
23
22
  gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
24
23
  HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
25
- AQCygvpmncmkiSs9r/Kceo4bBPDszhTv6iBi4LwMReqnFrpNLMOWJw7xi8x+3eL2
26
- XS09ZPNOt2zm70KmFouBMgOysnDY4k2dE8uF6B8JbZOO8QfalW+CoNBliefOTcn2
27
- bg5IOP7UoGM5lC174/cbDJrJnRG9bzig5FAP0mvsgA8zgTRXQzIUAZEo92D5K7p4
28
- B4/O998ho6BSOgYBI9Yk1ttdCtti6Y+8N9+fZESsjtWMykA+WXWeGUScHqiU+gH8
29
- S7043fq9EbQdBr2AXdj92+CDwuTfHI6/Hj5FVBDULufrJaan4xUgL70Hvc6pTTeW
30
- deKfBjgVAq7EYHu1AczzlUly
24
+ AQAC0WQJcPOWPFwkojhzweilRVjTJ19UiLhiBTw3C1wJO3LVdBkWDmnnhAmKuX4D
25
+ r7vjQvESlABGIPdutI1Yl7mrHQzTkfLfXvNN6MT0nLChPyIYauT6SZZxubwJrUfA
26
+ 7R0c2CJTIboZ0XaGpLsXqHEF1c29H7TV1QvVuqKAN2mCjh4N82QVn+ZKtys28AwT
27
+ 6GfQX2fqLoi4KSc7xIzHKaNzqxeOICmJofk9w5VZ2rRN6yes8jvFYwz9HR41wdj8
28
+ bwfinv7Yp5fA6AysuZLhCykyfDuZVRrUp0Vb68YCKsLjJly/Theak+euNTxvHsB+
29
+ al9oSgPPHICMEX65qvLywitx
31
30
  -----END CERTIFICATE-----
32
- date: 2024-07-08 00:00:00.000000000 Z
31
+ date: 1980-01-02 00:00:00.000000000 Z
33
32
  dependencies:
34
33
  - !ruby/object:Gem::Dependency
35
34
  name: sexp_processor
@@ -46,19 +45,19 @@ dependencies:
46
45
  - !ruby/object:Gem::Version
47
46
  version: '4.6'
48
47
  - !ruby/object:Gem::Dependency
49
- name: ruby_parser
48
+ name: prism
50
49
  requirement: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '3.1'
55
- type: :runtime
53
+ version: '1.7'
54
+ type: :development
56
55
  prerelease: false
57
56
  version_requirements: !ruby/object:Gem::Requirement
58
57
  requirements:
59
58
  - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '3.1'
60
+ version: '1.7'
62
61
  - !ruby/object:Gem::Dependency
63
62
  name: rdoc
64
63
  requirement: !ruby/object:Gem::Requirement
@@ -85,14 +84,14 @@ dependencies:
85
84
  requirements:
86
85
  - - "~>"
87
86
  - !ruby/object:Gem::Version
88
- version: '4.2'
87
+ version: '4.3'
89
88
  type: :development
90
89
  prerelease: false
91
90
  version_requirements: !ruby/object:Gem::Requirement
92
91
  requirements:
93
92
  - - "~>"
94
93
  - !ruby/object:Gem::Version
95
- version: '4.2'
94
+ version: '4.3'
96
95
  description: |-
97
96
  ruby2ruby provides a means of generating pure ruby code easily from
98
97
  RubyParser compatible Sexps. This makes making dynamic language
@@ -120,7 +119,6 @@ licenses:
120
119
  - MIT
121
120
  metadata:
122
121
  homepage_uri: https://github.com/seattlerb/ruby2ruby
123
- post_install_message:
124
122
  rdoc_options:
125
123
  - "--main"
126
124
  - README.rdoc
@@ -130,15 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
128
  requirements:
131
129
  - - ">="
132
130
  - !ruby/object:Gem::Version
133
- version: '0'
131
+ version: '3.2'
134
132
  required_rubygems_version: !ruby/object:Gem::Requirement
135
133
  requirements:
136
134
  - - ">="
137
135
  - !ruby/object:Gem::Version
138
136
  version: '0'
139
137
  requirements: []
140
- rubygems_version: 3.5.14
141
- signing_key:
138
+ rubygems_version: 3.7.2
142
139
  specification_version: 4
143
140
  summary: ruby2ruby provides a means of generating pure ruby code easily from RubyParser
144
141
  compatible Sexps
metadata.gz.sig CHANGED
Binary file