ruby2ruby 2.5.2 → 2.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c64f2d5a6bbdc7e93781d52bed2848dff7a5981dcfa69dcbb6f7e6018041fe67
4
- data.tar.gz: 9d3edc0270776e1e0c51ee0a7e5c4d7f91221e044cbf1f3dc423de7e1337a7cf
3
+ metadata.gz: 47b02eac6d9da093ec8d57bd84e3b6d4d9e18120280b21de3265fa6e65cd87ae
4
+ data.tar.gz: ad4413f10e596d3e6f7130c80f9dbda8e27c6899009f5c3a1da3b9f1cd59b249
5
5
  SHA512:
6
- metadata.gz: f5c7711e43250ccf0378474f7967e65bc18674bfcd79d1a2f5a682c7b6355a0038b586595e4f50c2c83cd724dbb521c5019dacf40caa4a77f9eacb2d37077111
7
- data.tar.gz: 38cf570d752fca4d6884a14601cb1508d544e6476af73ac55bddfd80a577875298cb2106cfa1945bccd2124c47aecca2fc5ec908f3b06ba10e4b3982610f0d3e
6
+ metadata.gz: 06adf0bca90a2226800500f505de13a9432139d3472996f68377614c0eaca0a8e893055ca2fc8584e68dbdc8c8043eef7f9f91bd1b7c446c935803bcc5e101ba
7
+ data.tar.gz: ac08f4635b66aca9005ab9f1c04d8f3a4b9a8aab863e250e6348ace8bb913858f7ca44385f82ca91bce4ac6b7bc08bbf790b983bb92a772131b8944d9709cb16
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,21 @@
1
+ === 2.6.1 / 2026-01-26
2
+
3
+ * 1 bug fix:
4
+
5
+ * Fixed handling of defined? in certain contexts. (triskweline)
6
+
7
+ === 2.6.0 / 2025-12-24
8
+
9
+ * 3 minor enhancements:
10
+
11
+ * Added prism as a development dependency.
12
+ * Bumped ruby_version to 3.2+.
13
+ * Removed ruby_parser as a runtime dependency.
14
+
15
+ * 1 bug fix:
16
+
17
+ * Minor fixes to impl for comment processing. Prism returns chomped string.
18
+
1
19
  === 2.5.2 / 2025-03-25
2
20
 
3
21
  * 1 bug fix:
data/Rakefile CHANGED
@@ -4,7 +4,6 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  Hoe.add_include_dirs("lib",
7
- "../../ruby_parser/dev/lib",
8
7
  "../../sexp_processor/dev/lib")
9
8
 
10
9
  Hoe.plugin :seattlerb
@@ -17,14 +16,21 @@ Hoe.spec 'ruby2ruby' do
17
16
  license "MIT"
18
17
 
19
18
  dependency "sexp_processor", "~> 4.6"
20
- dependency "ruby_parser", "~> 3.1"
19
+ dependency "prism", "~> 1.7", :dev
20
+
21
+ require_ruby_version ">= 3.2"
22
+
23
+ self.isolate_multiruby = true
21
24
  end
22
25
 
23
26
  def process ruby, file="stdin"
24
- require "ruby_parser"
27
+ require "prism"
28
+ require "prism/translation/ruby_parser"
25
29
  require "ruby2ruby"
26
30
 
27
- parser = RubyParser.new
31
+ not_ruby_parser = Class.new Prism::Translation::RubyParser
32
+
33
+ parser = not_ruby_parser.new
28
34
  ruby2ruby = Ruby2Ruby.new
29
35
 
30
36
  begin
@@ -40,7 +46,6 @@ end
40
46
 
41
47
  task :stress do
42
48
  $: << "lib"
43
- $: << "../../ruby_parser/dev/lib"
44
49
  require "pp"
45
50
 
46
51
  files = Dir["../../*/dev/**/*.rb"].reject { |s| s =~ %r%/gems/% }
@@ -80,10 +85,13 @@ task :debug => :isolate do
80
85
  end
81
86
 
82
87
  task :parse => :isolate do
83
- require "ruby_parser"
88
+ require "prism"
89
+ require "prism/translation/ruby_parser"
84
90
  require "pp"
85
91
 
86
- parser = RubyParser.for_current_ruby
92
+ not_ruby_parser = Class.new Prism::Translation::RubyParser
93
+
94
+ parser = not_ruby_parser.new
87
95
 
88
96
  file = ENV["F"]
89
97
  ruby = ENV["R"]
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.2" # :nodoc:
34
+ VERSION = "2.6.1" # :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:
@@ -405,13 +411,17 @@ class Ruby2Ruby < SexpProcessor
405
411
 
406
412
  def process_defined exp # :nodoc:
407
413
  _, rhs = exp
408
- "defined? #{process rhs}"
414
+ if context[1] == :if then # HACK?
415
+ "defined?(#{process rhs})"
416
+ else
417
+ "defined? #{process rhs}"
418
+ end
409
419
  end
410
420
 
411
421
  def process_defn(exp) # :nodoc:
412
422
  _, name, args, *body = exp
413
423
 
414
- comm = exp.comments
424
+ comm = comments exp
415
425
  args = process args
416
426
  args = "" if args == "()"
417
427
 
@@ -887,7 +897,7 @@ class Ruby2Ruby < SexpProcessor
887
897
  end
888
898
 
889
899
  def process_module(exp) # :nodoc:
890
- "#{exp.comments}module #{util_module_or_class(exp)}"
900
+ "#{comments exp}module #{util_module_or_class(exp)}"
891
901
  end
892
902
 
893
903
  def process_next(exp) # :nodoc:
@@ -9,7 +9,23 @@ 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
+ require "timeout" # remove once upstreamed
14
+ # require "prism/translation/ruby_parser" # not until upstreamed
15
+
16
+ class NotRubyParser < Prism::Translation::RubyParser # remove once upstreamed
17
+ attr_accessor :scopes
18
+
19
+ def initialize scopes:nil
20
+ super()
21
+ self.scopes = [scopes] if scopes
22
+ end
23
+
24
+ # overridden from prism to add scopes arg
25
+ def parse(source, filepath = "(string)")
26
+ translate(Prism.parse(source, filepath:, partial_script: true, scopes:), filepath)
27
+ end
28
+ end
13
29
 
14
30
  class R2RTestCase < ParseTreeTestCase
15
31
  def self.previous key
@@ -42,13 +58,8 @@ class TestRuby2Ruby < R2RTestCase
42
58
  @processor = Ruby2Ruby.new
43
59
  end
44
60
 
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"
61
+ def skip_prism
62
+ skip "not fully happy with prism yet"
52
63
  end
53
64
 
54
65
  def do_not_check_sexp!
@@ -183,11 +194,11 @@ class TestRuby2Ruby < R2RTestCase
183
194
  end
184
195
 
185
196
  def assert_str exp, src
186
- assert_equal s(:str, exp), RubyParser.new.process(src)
197
+ assert_equal s(:str, exp), NotRubyParser.new.process(src)
187
198
  end
188
199
 
189
200
  def assert_dstr exp, int, src
190
- assert_equal s(:dstr, exp, s(:evstr, int).compact), RubyParser.new.process(src)
201
+ assert_equal s(:dstr, exp, s(:evstr, int).compact), NotRubyParser.new.process(src)
191
202
  end
192
203
 
193
204
  def assert_r2r exp, sexp
@@ -195,7 +206,7 @@ class TestRuby2Ruby < R2RTestCase
195
206
  end
196
207
 
197
208
  def assert_rt src, exp = src.dup
198
- assert_equal exp, Ruby2Ruby.new.process(RubyParser.new.parse(src))
209
+ assert_equal exp, Ruby2Ruby.new.process(NotRubyParser.new.parse(src))
199
210
  end
200
211
 
201
212
  def test_bug_033
@@ -441,7 +452,6 @@ class TestRuby2Ruby < R2RTestCase
441
452
  end
442
453
 
443
454
  def test_forward_args__call
444
- skip31
445
455
 
446
456
  inn = s(:defn, :x, s(:args, s(:forward_args)), s(:call, nil, :y, s(:forward_args)))
447
457
  out = "def x(...)\n y(...)\nend"
@@ -683,6 +693,12 @@ class TestRuby2Ruby < R2RTestCase
683
693
  assert_parse inn, out
684
694
  end
685
695
 
696
+ def test_if_defined
697
+ inn = s(:if, s(:defined, s(:const, :Foo)), s(:lit, 1), s(:lit, 2))
698
+ out = "defined?(Foo) ? (1) : (2)" # TODO: remove parens on 1/2
699
+ assert_parse inn, out
700
+ end
701
+
686
702
  def test_if_empty
687
703
  inn = s(:if, s(:call, nil, :x), nil, nil)
688
704
  out = "if x then\n # do nothing\nend"
@@ -740,7 +756,12 @@ class TestRuby2Ruby < R2RTestCase
740
756
  end
741
757
 
742
758
  def test_case_in__array_pat_04
743
- 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)))
759
+ pt = s(:array_pat,
760
+ nil,
761
+ s(:array_pat, nil, s(:lit, :b), s(:lvar, :c)),
762
+ s(:array_pat, nil, s(:lit, :d), s(:lvar, :a)))
763
+
764
+ assert_case_in "[[:b, ^c], [:d, ^a]]", pt
744
765
  end
745
766
 
746
767
  def test_case_in__array_pat_06
@@ -768,22 +789,16 @@ class TestRuby2Ruby < R2RTestCase
768
789
  end
769
790
 
770
791
  def test_case_in__array_pat_19
771
- skip31
772
-
773
792
  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
774
793
  end
775
794
 
776
795
  def test_case_in__find_pat_1
777
- skip30
778
-
779
796
  assert_case_in "[*a, :+, *b]", s(:find_pat, nil, :"*a",
780
797
  s(:lit, :+),
781
798
  :"*b")
782
799
  end
783
800
 
784
801
  def test_case_in__find_pat_2
785
- skip30
786
-
787
802
  assert_case_in "[*, :b, ^c, *]", s(:find_pat, nil,
788
803
  :*,
789
804
  s(:lit, :b), s(:lvar, :c),
@@ -791,35 +806,30 @@ class TestRuby2Ruby < R2RTestCase
791
806
  end
792
807
 
793
808
  def test_case_in__find_pat_3
794
- skip30
795
-
796
- assert_case_in("Array(*b, n, { a: }, m, *a)",
809
+ assert_case_in("Array(*b, n, { a: }, m, *c)",
797
810
  s(:find_pat,
798
811
  s(:const, :Array),
799
812
  :"*b",
800
813
  s(:lasgn, :n),
801
814
  s(:hash_pat, nil, s(:lit, :a), nil),
802
815
  s(:lasgn, :m),
803
- :"*a"),
804
- "Array[*b, n, { a: }, m, *a]")
816
+ :"*c"),
817
+ "Array[*b, n, { a: }, m, *c]")
805
818
  end
806
819
 
807
820
  def test_case_in__find_pat_4
808
- skip30
809
-
810
- assert_case_in("*b, n, { a: }, m, *a", s(:find_pat,
811
- nil,
812
- :"*b",
813
- s(:lasgn, :n),
814
- s(:hash_pat, nil, s(:lit, :a), nil),
815
- s(:lasgn, :m),
816
- :"*a"),
817
- "[*b, n, { a: }, m, *a]")
821
+ assert_case_in("*b, n, { a: }, m, *c",
822
+ s(:find_pat,
823
+ nil,
824
+ :"*b",
825
+ s(:lasgn, :n),
826
+ s(:hash_pat, nil, s(:lit, :a), nil),
827
+ s(:lasgn, :m),
828
+ :"*c"),
829
+ "[*b, n, { a: }, m, *c]")
818
830
  end
819
831
 
820
832
  def test_case_in__find_pat_5
821
- skip30
822
-
823
833
  assert_case_in("Array(*lhs, ^b, *rhs)", s(:find_pat,
824
834
  s(:const, :Array),
825
835
  :"*lhs",
@@ -943,10 +953,10 @@ class TestRuby2Ruby < R2RTestCase
943
953
  s(:array_pat,
944
954
  nil,
945
955
  s(:lit, :d),
946
- s(:lvar, :e)),
956
+ s(:lvar, :a)),
947
957
  )
948
958
 
949
- assert_case_in "[[:b, c], [:d, ^e]]", pt
959
+ assert_case_in "[[:b, c], [:d, ^a]]", pt
950
960
  end
951
961
 
952
962
  def test_case_in__hash_pat_00
@@ -1111,13 +1121,7 @@ class TestRuby2Ruby < R2RTestCase
1111
1121
  end
1112
1122
 
1113
1123
  def ruby_parser
1114
- parser = RubyParser.latest
1115
-
1116
- %i[a b c d].each do |v|
1117
- parser.env[v] = :lvar
1118
- end
1119
-
1120
- parser
1124
+ NotRubyParser.new scopes: %i[a b c d]
1121
1125
  end
1122
1126
 
1123
1127
  def assert_parse sexp, expected_ruby, expected_eval = nil
@@ -1176,11 +1180,8 @@ end
1176
1180
  tr2r = File.read(__FILE__).lines[start + 1..__LINE__ - 2].join
1177
1181
  ir2r = File.read("lib/ruby2ruby.rb")
1178
1182
 
1179
- require "ruby_parser"
1180
-
1181
1183
  def morph_and_eval src, from, to, processor
1182
- parser = RubyParser.latest
1183
- new_src = processor.new.process(parser.process(src.sub(from, to)))
1184
+ new_src = processor.new.process(NotRubyParser.new.process(src.sub(from, to)))
1184
1185
 
1185
1186
  eval new_src
1186
1187
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby2ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -9,9 +9,9 @@ bindir: bin
9
9
  cert_chain:
10
10
  - |
11
11
  -----BEGIN CERTIFICATE-----
12
- MIIDPjCCAiagAwIBAgIBCTANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
12
+ MIIDPjCCAiagAwIBAgIBCjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
13
13
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
14
- GRYDY29tMB4XDTI1MDEwNjIzMjcwMVoXDTI2MDEwNjIzMjcwMVowRTETMBEGA1UE
14
+ GRYDY29tMB4XDTI2MDEwNzAxMDkxNFoXDTI3MDEwNzAxMDkxNFowRTETMBEGA1UE
15
15
  AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
16
16
  JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcN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30
  -----END CERTIFICATE-----
31
- date: 2025-03-25 00:00:00.000000000 Z
31
+ date: 1980-01-02 00:00:00.000000000 Z
32
32
  dependencies:
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: sexp_processor
@@ -45,53 +45,53 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '4.6'
47
47
  - !ruby/object:Gem::Dependency
48
- name: ruby_parser
48
+ name: prism
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '3.1'
54
- type: :runtime
53
+ version: '1.7'
54
+ type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '3.1'
60
+ version: '1.7'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rdoc
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - ">="
66
66
  - !ruby/object:Gem::Version
67
- version: '4.0'
67
+ version: '6.0'
68
68
  - - "<"
69
69
  - !ruby/object:Gem::Version
70
- version: '7'
70
+ version: '8'
71
71
  type: :development
72
72
  prerelease: false
73
73
  version_requirements: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: '4.0'
77
+ version: '6.0'
78
78
  - - "<"
79
79
  - !ruby/object:Gem::Version
80
- version: '7'
80
+ version: '8'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: hoe
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
86
86
  - !ruby/object:Gem::Version
87
- version: '4.2'
87
+ version: '4.5'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
- version: '4.2'
94
+ version: '4.5'
95
95
  description: |-
96
96
  ruby2ruby provides a means of generating pure ruby code easily from
97
97
  RubyParser compatible Sexps. This makes making dynamic language
@@ -128,14 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '3.2'
132
132
  required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
136
  version: '0'
137
137
  requirements: []
138
- rubygems_version: 3.6.3
138
+ rubygems_version: 3.7.2
139
139
  specification_version: 4
140
140
  summary: ruby2ruby provides a means of generating pure ruby code easily from RubyParser
141
141
  compatible Sexps
metadata.gz.sig CHANGED
Binary file