ruby2ruby 1.1.5 → 1.1.6
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.
- data/History.txt +25 -16
- data/lib/ruby2ruby.rb +33 -19
- data/test/test_ruby2ruby.rb +49 -2
- metadata +11 -8
data/History.txt
CHANGED
@@ -1,19 +1,28 @@
|
|
1
|
-
|
1
|
+
=== 1.1.6 / 2007-06-05
|
2
|
+
|
3
|
+
* 2 minor enhancements:
|
4
|
+
* Extended tests for dstr/dsym/drgx to test against embedded slashes and quotes.
|
5
|
+
* Updated for dasgn_curr changes to PT.
|
6
|
+
* 2 bug fixes:
|
7
|
+
* Fixed a bug with begin/rescue/ensure.
|
8
|
+
* Fixed argscat and blockpass bug. blah(42, *args, &block) handled.
|
9
|
+
|
10
|
+
=== 1.1.5 / 2007-02-13
|
2
11
|
|
3
12
|
* 3 minor enhancements:
|
4
|
-
|
5
|
-
|
6
|
-
|
13
|
+
* Can now heckle ActiveRecord::Base in full.
|
14
|
+
* Cleaned up 1-liner generating code.
|
15
|
+
* Made clean/simple rescues 1-liners.
|
7
16
|
* 7 bug fixes:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
* Finally got the rest of block_pass working.
|
18
|
+
* Fixed block_pass on procs in iters. UGH!
|
19
|
+
* Fixed attrasgn in masgn.
|
20
|
+
* Fixed splat in masgn.
|
21
|
+
* Fixed unary/prefix methods.
|
22
|
+
* Fixed attrasgn for []= where there were multiple args inside [].
|
23
|
+
* Fixed a couple resbody bugs.
|
15
24
|
|
16
|
-
|
25
|
+
=== 1.1.4 / 2007-01-15
|
17
26
|
|
18
27
|
* 4 minor enhancements:
|
19
28
|
* Added some extra rewriting code and tests for various bmethods. Ugh.
|
@@ -26,14 +35,14 @@
|
|
26
35
|
* Fixed dmethod. I think the tests were bogus before.
|
27
36
|
* Fixed improper end in method rescues (bug 7396).
|
28
37
|
|
29
|
-
|
38
|
+
=== 1.1.3 / 2006-12-20
|
30
39
|
|
31
40
|
* 1 minor enhancement
|
32
41
|
* Unit tests do self-translation and retesting for 3 generations! Solid. BAM!
|
33
42
|
* 1 bug fixes
|
34
43
|
* iasgn inside masgn was totally borked in ruby2ruby.
|
35
44
|
|
36
|
-
|
45
|
+
=== 1.1.2 / 2006-12-19
|
37
46
|
|
38
47
|
* 2 minor enhancements
|
39
48
|
* Improved []= and [] to be more idiomatic.
|
@@ -43,14 +52,14 @@
|
|
43
52
|
* NEARLY have RubyToRuby self-cloning and passing tests again.
|
44
53
|
* Minor cleanup
|
45
54
|
|
46
|
-
|
55
|
+
=== 1.1.1 / 2006-11-13
|
47
56
|
|
48
57
|
* 3 bug fixes
|
49
58
|
* Fixed procs
|
50
59
|
* Cleaned return when no return values.
|
51
60
|
* Rewrote process_if. No more elsif but no more bugs. :)
|
52
61
|
|
53
|
-
|
62
|
+
=== 1.1.0 / 2006-10-11
|
54
63
|
|
55
64
|
* 2 major enhancements
|
56
65
|
* Released separately from ZenHacks.
|
data/lib/ruby2ruby.rb
CHANGED
@@ -11,7 +11,7 @@ class NilClass # Objective-C trick
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class RubyToRuby < SexpProcessor
|
14
|
-
VERSION = '1.1.
|
14
|
+
VERSION = '1.1.6'
|
15
15
|
LINE_LENGTH = 78
|
16
16
|
|
17
17
|
def self.translate(klass_or_str, method = nil)
|
@@ -90,12 +90,16 @@ class RubyToRuby < SexpProcessor
|
|
90
90
|
|
91
91
|
def process_argscat(exp)
|
92
92
|
args = []
|
93
|
+
|
93
94
|
ary = exp.shift
|
94
95
|
ary.shift # :array
|
95
96
|
until ary.empty? do
|
96
97
|
args << process(ary.shift)
|
97
98
|
end
|
99
|
+
|
98
100
|
args << "*#{process(exp.shift)}"
|
101
|
+
args << process(exp.shift) unless exp.empty? # optional block arg
|
102
|
+
|
99
103
|
args.join ', '
|
100
104
|
end
|
101
105
|
|
@@ -169,7 +173,7 @@ class RubyToRuby < SexpProcessor
|
|
169
173
|
end
|
170
174
|
|
171
175
|
def process_block_pass(exp)
|
172
|
-
bname =
|
176
|
+
bname = s(:block_arg, process(exp.shift)) # FIX
|
173
177
|
call = exp.shift
|
174
178
|
|
175
179
|
if Array === call.last then # HACK - I _really_ need rewrites to happen first
|
@@ -179,6 +183,7 @@ class RubyToRuby < SexpProcessor
|
|
179
183
|
when :array then
|
180
184
|
# do nothing
|
181
185
|
else
|
186
|
+
has_args = Array === call.last and call.last.first == :array
|
182
187
|
call << [:array] unless has_args
|
183
188
|
end
|
184
189
|
call.last << bname
|
@@ -362,8 +367,27 @@ class RubyToRuby < SexpProcessor
|
|
362
367
|
"(#{process exp.shift}...#{process exp.shift})"
|
363
368
|
end
|
364
369
|
|
370
|
+
def util_dthing(exp, dump=false)
|
371
|
+
s = []
|
372
|
+
s << exp.shift.dump[1..-2]
|
373
|
+
until exp.empty?
|
374
|
+
pt = exp.shift
|
375
|
+
s << case pt.first
|
376
|
+
when :str then
|
377
|
+
if dump then
|
378
|
+
pt.last.dump[1..-2]
|
379
|
+
else
|
380
|
+
pt.last.gsub(%r%/%, '\/')
|
381
|
+
end
|
382
|
+
else
|
383
|
+
"#\{#{process(pt)}}"
|
384
|
+
end
|
385
|
+
end
|
386
|
+
s
|
387
|
+
end
|
388
|
+
|
365
389
|
def process_dregx(exp)
|
366
|
-
"/#{
|
390
|
+
"/#{util_dthing(exp).join}/"
|
367
391
|
end
|
368
392
|
|
369
393
|
def process_dregx_once(exp)
|
@@ -371,16 +395,7 @@ class RubyToRuby < SexpProcessor
|
|
371
395
|
end
|
372
396
|
|
373
397
|
def process_dstr(exp)
|
374
|
-
|
375
|
-
until exp.empty?
|
376
|
-
pt = exp.shift
|
377
|
-
if pt.first == :str
|
378
|
-
s << process(pt)[1..-2]
|
379
|
-
else
|
380
|
-
s << '#{' + process(pt) + '}'
|
381
|
-
end
|
382
|
-
end
|
383
|
-
s + '"'
|
398
|
+
"\"#{util_dthing(exp, true).join}\""
|
384
399
|
end
|
385
400
|
|
386
401
|
def process_dsym(exp)
|
@@ -534,8 +549,9 @@ class RubyToRuby < SexpProcessor
|
|
534
549
|
|
535
550
|
def process_lit(exp)
|
536
551
|
obj = exp.shift
|
537
|
-
|
538
|
-
|
552
|
+
case obj
|
553
|
+
when Range then
|
554
|
+
"(#{obj.inspect})"
|
539
555
|
else
|
540
556
|
obj.inspect
|
541
557
|
end
|
@@ -722,7 +738,8 @@ class RubyToRuby < SexpProcessor
|
|
722
738
|
code << "else"
|
723
739
|
code << indent(els)
|
724
740
|
else
|
725
|
-
unless stack.first == "process_block"
|
741
|
+
unless stack.first == "process_block" ||
|
742
|
+
stack.first == "process_ensure" then
|
726
743
|
code << "end\n"
|
727
744
|
else
|
728
745
|
r = [body, resbody.gsub(/rescue\n\s+/, 'rescue ')].join(' ')
|
@@ -909,7 +926,6 @@ class RubyToRuby < SexpProcessor
|
|
909
926
|
end
|
910
927
|
when :bmethod then
|
911
928
|
body[0] = :scope
|
912
|
-
body.block.delete_at(1) # nuke the decl # REFACTOR
|
913
929
|
masgn = body.masgn(true)
|
914
930
|
if masgn then
|
915
931
|
splat = self.splat(masgn[-1][-1])
|
@@ -939,8 +955,6 @@ class RubyToRuby < SexpProcessor
|
|
939
955
|
body.find_and_replace_all(:dvar, :lvar)
|
940
956
|
when :masgn then
|
941
957
|
dasgn = body.masgn(true)
|
942
|
-
# DAMNIT body.block.dasgn_curr(true) - multiple values so can't use
|
943
|
-
body.block.delete_at(1) # nuke the decl
|
944
958
|
splat = self.splat(dasgn[-1][-1])
|
945
959
|
args.push(splat)
|
946
960
|
body.find_and_replace_all(:dvar, :lvar)
|
data/test/test_ruby2ruby.rb
CHANGED
@@ -10,12 +10,58 @@ class TestRubyToRuby < Test::Unit::TestCase
|
|
10
10
|
@processor = RubyToRuby.new
|
11
11
|
end
|
12
12
|
|
13
|
+
def test_lit_regexp_slash
|
14
|
+
inn = s(:lit, /blah\/blah/)
|
15
|
+
out = '/blah\/blah/'
|
16
|
+
|
17
|
+
assert_equal out, @processor.process(inn)
|
18
|
+
|
19
|
+
r = eval(out)
|
20
|
+
assert_equal(/blah\/blah/, r)
|
21
|
+
end
|
22
|
+
|
23
|
+
def util_thingy(type)
|
24
|
+
s(type,
|
25
|
+
"blah",
|
26
|
+
s(:call, s(:lit, 1), :+, s(:array, s(:lit, 1))),
|
27
|
+
s(:str, 'blah"blah/blah'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_dregx_slash
|
31
|
+
inn = util_thingy(:dregx)
|
32
|
+
out = '/blah#{(1 + 1)}blah"blah\/blah/'
|
33
|
+
|
34
|
+
assert_equal out, @processor.process(inn)
|
35
|
+
|
36
|
+
r = eval(out)
|
37
|
+
assert_equal(/blah2blah"blah\/blah/, r)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_dstr_quote
|
41
|
+
inn = util_thingy(:dstr)
|
42
|
+
out = '"blah#{(1 + 1)}blah\"blah/blah"'
|
43
|
+
|
44
|
+
assert_equal out, @processor.process(inn)
|
45
|
+
|
46
|
+
r = eval(out)
|
47
|
+
assert_equal "blah2blah\"blah/blah", r
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_dsym_quote
|
51
|
+
inn = util_thingy(:dsym)
|
52
|
+
out = ':"blah#{(1 + 1)}blah\"blah/blah"'
|
53
|
+
|
54
|
+
assert_equal out, @processor.process(inn)
|
55
|
+
|
56
|
+
r = eval(out)
|
57
|
+
assert_equal :"blah2blah\"blah/blah", r
|
58
|
+
end
|
59
|
+
|
13
60
|
def test_rewrite_defn_define_method
|
14
61
|
inn = s(:defn, :splatted,
|
15
62
|
s(:bmethod,
|
16
63
|
s(:masgn, s(:dasgn_curr, :args)),
|
17
64
|
s(:block,
|
18
|
-
s(:dasgn_curr, :y),
|
19
65
|
s(:dasgn_curr, :y, s(:call, s(:dvar, :args), :first)),
|
20
66
|
s(:call, s(:dvar, :y), :+, s(:array, s(:lit, 42))))))
|
21
67
|
out = s(:defn, :splatted,
|
@@ -34,7 +80,6 @@ class TestRubyToRuby < Test::Unit::TestCase
|
|
34
80
|
s(:bmethod,
|
35
81
|
s(:masgn, s(:dasgn_curr, :params)),
|
36
82
|
s(:block,
|
37
|
-
s(:dasgn_curr, :force_reload, s(:dasgn_curr, :association, s(:dasgn_curr, :retval))),
|
38
83
|
s(:lit, 42)))))
|
39
84
|
out = s(:defn, :group,
|
40
85
|
s(:args, :"*params"),
|
@@ -104,6 +149,8 @@ rescue SyntaxError => e
|
|
104
149
|
exit 1
|
105
150
|
end
|
106
151
|
|
152
|
+
RubyToRuby2::LINE_LENGTH = RubyToRuby::LINE_LENGTH # HACK
|
153
|
+
|
107
154
|
class TestRubyToRuby2 < TestRubyToRuby
|
108
155
|
def setup
|
109
156
|
@processor = RubyToRuby2.new
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby2ruby
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.1.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.1.6
|
7
|
+
date: 2007-06-05 00:00:00 -07:00
|
8
8
|
summary: ruby2ruby provides a means of generating pure ruby code easily from ParseTree's Sexps.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -37,10 +37,13 @@ files:
|
|
37
37
|
- test/test_ruby2ruby.rb
|
38
38
|
test_files:
|
39
39
|
- test/test_ruby2ruby.rb
|
40
|
-
rdoc_options:
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
rdoc_options:
|
41
|
+
- --main
|
42
|
+
- README.txt
|
43
|
+
extra_rdoc_files:
|
44
|
+
- History.txt
|
45
|
+
- Manifest.txt
|
46
|
+
- README.txt
|
44
47
|
executables: []
|
45
48
|
|
46
49
|
extensions: []
|
@@ -64,5 +67,5 @@ dependencies:
|
|
64
67
|
requirements:
|
65
68
|
- - ">="
|
66
69
|
- !ruby/object:Gem::Version
|
67
|
-
version: 1.2.
|
70
|
+
version: 1.2.1
|
68
71
|
version:
|