ruby2ruby 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -0
- data/lib/ruby2ruby.rb +9 -4
- data/test/test_ruby2ruby.rb +17 -93
- metadata +2 -2
data/History.txt
CHANGED
data/lib/ruby2ruby.rb
CHANGED
@@ -11,9 +11,9 @@ class NilClass # Objective-C trick
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class RubyToRuby < SexpProcessor
|
14
|
-
VERSION = '1.1.
|
14
|
+
VERSION = '1.1.3'
|
15
15
|
|
16
|
-
def self.translate(klass_or_str, method=nil)
|
16
|
+
def self.translate(klass_or_str, method = nil)
|
17
17
|
self.new.process(ParseTree.translate(klass_or_str, method))
|
18
18
|
end
|
19
19
|
|
@@ -448,7 +448,12 @@ class RubyToRuby < SexpProcessor
|
|
448
448
|
end
|
449
449
|
|
450
450
|
def process_iasgn(exp)
|
451
|
-
|
451
|
+
lhs = exp.shift
|
452
|
+
if exp.empty? then # part of an masgn
|
453
|
+
lhs.to_s
|
454
|
+
else
|
455
|
+
"#{lhs} = #{process exp.shift}"
|
456
|
+
end
|
452
457
|
end
|
453
458
|
|
454
459
|
def cond_indent_process(pt)
|
@@ -522,7 +527,7 @@ class RubyToRuby < SexpProcessor
|
|
522
527
|
|
523
528
|
def process_masgn(exp)
|
524
529
|
lhs = exp.shift
|
525
|
-
rhs = exp.shift
|
530
|
+
rhs = exp.shift rescue nil
|
526
531
|
|
527
532
|
assert_type lhs, :array
|
528
533
|
lhs.shift
|
data/test/test_ruby2ruby.rb
CHANGED
@@ -46,103 +46,27 @@ class TestRubyToRuby < Test::Unit::TestCase
|
|
46
46
|
assert_equal out, @processor.rewrite_resbody(inn)
|
47
47
|
end
|
48
48
|
|
49
|
+
eval ParseTreeTestCase.testcases.map { |node, data|
|
50
|
+
"def test_#{node}
|
51
|
+
pt = #{data['ParseTree'].inspect}
|
52
|
+
rb = #{(data['Ruby2Ruby'] || data['Ruby']).inspect}
|
49
53
|
|
50
|
-
|
51
|
-
|
52
|
-
pt = data['ParseTree'].deep_clone
|
53
|
-
rb = (data['Ruby2Ruby'] || data['Ruby']).deep_clone
|
54
|
+
assert_not_nil pt, \"ParseTree for #{node} undefined\"
|
55
|
+
assert_not_nil rb, \"Ruby for #{node} undefined\"
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
assert_equal rb, result
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_self_translation
|
64
|
-
r2r2r = RubyToRuby.translate(RubyToRuby).sub("RubyToRuby","RubyToRubyToRuby")
|
65
|
-
|
66
|
-
begin
|
67
|
-
Object.class_eval r2r2r
|
68
|
-
rescue SyntaxError => e
|
69
|
-
$stderr.puts r2r2r
|
70
|
-
flunk "syntax error, see above (#{e.inspect})"
|
71
|
-
end
|
72
|
-
|
73
|
-
r2r2r2 = RubyToRubyToRuby.translate(RubyToRuby).sub("RubyToRuby","RubyToRubyToRuby")
|
74
|
-
r2r2r2r = RubyToRubyToRuby.translate(RubyToRubyToRuby)
|
75
|
-
assert_equal(r2r2r, r2r2r2, "first generation must equal second generation")
|
76
|
-
assert_equal(r2r2r, r2r2r2r, "first generation must equal third generation")
|
77
|
-
end
|
78
|
-
|
79
|
-
def hairy_method(z,x=10,y=20*z.abs,&blok)
|
80
|
-
n = 1 + 2 * 40.0 / (z - 2)
|
81
|
-
retried = false
|
82
|
-
begin
|
83
|
-
raise ArgumentError, n if retried
|
84
|
-
n -= yield x,y,z,[z,x,y].map(&blok)
|
85
|
-
n = n / 1.1 until n < 500 # TODO: translated isn't respecting post iter
|
86
|
-
n = "hop hop #{"%.4f" % n}"
|
87
|
-
raise n
|
88
|
-
rescue RuntimeError => e
|
89
|
-
raise if n != e.message
|
90
|
-
n = lambda do |i|
|
91
|
-
lambda do |j|
|
92
|
-
"#{i} #{z+2*2} #{j.message.reverse}"
|
93
|
-
end
|
94
|
-
end[n].call(e)
|
95
|
-
unless retried
|
96
|
-
retried = true
|
97
|
-
retry
|
98
|
-
end
|
99
|
-
rescue ArgumentError => e
|
100
|
-
e.message
|
101
|
-
rescue
|
102
|
-
end
|
103
|
-
ensure
|
104
|
-
x << "ensure a-working"
|
105
|
-
end
|
106
|
-
|
107
|
-
def foobar a, █ block.call(a) end
|
108
|
-
def k; foobar [1,2,3].each { |x| x*2 } do |x| x*2 end end
|
109
|
-
|
110
|
-
def test_block_precedence_escape
|
111
|
-
eval RubyToRuby.translate(self.class, :k).sub(" k"," l")
|
112
|
-
assert_equal(k, l)
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_hairy_method
|
116
|
-
src = RubyToRuby.translate(self.class, :hairy_method).sub(" h", " f")
|
57
|
+
assert_equal rb, @processor.process(pt)
|
58
|
+
end"
|
59
|
+
}.join("\n")
|
60
|
+
end
|
117
61
|
|
118
|
-
|
62
|
+
# Self-Translation: 1st Generation
|
63
|
+
eval RubyToRuby.translate(RubyToRuby).sub("RubyToRuby", "RubyToRuby2")
|
119
64
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
else
|
124
|
-
x.to_i*y*z*arr.inject(1){|s,i| s+i}
|
125
|
-
end
|
126
|
-
}
|
127
|
-
x1 = ""
|
128
|
-
x2 = ""
|
129
|
-
res = [hairy_method(-5,x1,&blk), fairy_method(-5,x2,&blk)]
|
130
|
-
assert_equal(res.first, res.last)
|
131
|
-
assert_equal(x1, x2)
|
132
|
-
assert_equal("ensure a-working", x1)
|
65
|
+
class TestRubyToRuby2 < TestRubyToRuby
|
66
|
+
def setup
|
67
|
+
@processor = RubyToRuby2.new
|
133
68
|
end
|
134
69
|
end
|
135
70
|
|
136
|
-
#
|
137
|
-
|
138
|
-
# begin
|
139
|
-
# Object.class_eval r2r2
|
140
|
-
# rescue SyntaxError => e
|
141
|
-
# $stderr.puts r2r2
|
142
|
-
# flunk "syntax error, see above (#{e.inspect})"
|
143
|
-
# end
|
144
|
-
# class TestRubyToRubyToRuby < TestRubyToRuby
|
145
|
-
# def setup
|
146
|
-
# @processor = RubyToRuby2.new
|
147
|
-
# end
|
148
|
-
# end
|
71
|
+
# Self-Translation: 2nd Generation - against the tests this time
|
72
|
+
eval RubyToRuby2.translate(TestRubyToRuby).sub("TestRubyToRuby", "TestRubyToRuby3")
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: ruby2ruby
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.1.
|
7
|
-
date: 2006-12-
|
6
|
+
version: 1.1.3
|
7
|
+
date: 2006-12-20 00:00:00 -08: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
|