lazibi 0.1.12 → 0.1.13
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 +9 -0
- data/Manifest.txt +12 -0
- data/README.txt +5 -0
- data/lib/helper/task_helper.rb +2 -2
- data/lib/lazibi/version.rb +1 -1
- data/lib/parser.rb +28 -10
- data/lib/vendor/beautifier.rb +3 -3
- data/test/fixtures/functional/ruby/brackets_block.txt +5 -0
- data/test/fixtures/functional/ruby/classical.txt +10 -0
- data/test/fixtures/functional/ruby/describe.txt +11 -0
- data/test/fixtures/functional/ruby/do_block.txt +12 -0
- data/test/fixtures/functional/ruby/lambda.txt +10 -0
- data/test/fixtures/functional/ruby/square_brackets.txt +6 -0
- data/test/fixtures/functional/simply/brackets_block.txt +4 -0
- data/test/fixtures/functional/simply/classical.txt +7 -0
- data/test/fixtures/functional/simply/describe.txt +7 -0
- data/test/fixtures/functional/simply/do_block.txt +9 -0
- data/test/fixtures/functional/simply/lambda.txt +9 -0
- data/test/fixtures/functional/simply/square_brackets.txt +5 -0
- data/test/test_functional.rb +42 -0
- data/test/test_unit.rb +5 -0
- data/website/index.html +13 -2
- data/website/index.txt +5 -0
- metadata +26 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -32,6 +32,18 @@ test/fixtures/clean/re.txt
|
|
32
32
|
test/fixtures/clean/semi_colon_after_end.txt
|
33
33
|
test/fixtures/clean/sep_line.txt
|
34
34
|
test/fixtures/clean/unless_problem.txt
|
35
|
+
test/fixtures/functional/ruby/brackets_block.txt
|
36
|
+
test/fixtures/functional/ruby/classical.txt
|
37
|
+
test/fixtures/functional/ruby/describe.txt
|
38
|
+
test/fixtures/functional/ruby/do_block.txt
|
39
|
+
test/fixtures/functional/ruby/lambda.txt
|
40
|
+
test/fixtures/functional/ruby/square_brackets.txt
|
41
|
+
test/fixtures/functional/simply/brackets_block.txt
|
42
|
+
test/fixtures/functional/simply/classical.txt
|
43
|
+
test/fixtures/functional/simply/describe.txt
|
44
|
+
test/fixtures/functional/simply/do_block.txt
|
45
|
+
test/fixtures/functional/simply/lambda.txt
|
46
|
+
test/fixtures/functional/simply/square_brackets.txt
|
35
47
|
test/fixtures/meta/basic_class.txt
|
36
48
|
test/fixtures/meta/case.txt
|
37
49
|
test/fixtures/meta/class_with_def.txt
|
data/README.txt
CHANGED
@@ -110,6 +110,11 @@ Start hacking in meta :/
|
|
110
110
|
|
111
111
|
Lazibi is written using Lazibi itself ( incrementally ). Personally I think autotest from http://www.zenspider.com/ZSS/Products/ZenTest/ is a must have, and Lazibi works pretty well using TDD.
|
112
112
|
|
113
|
+
A few projects are used as test code:
|
114
|
+
ActiveRecord, ActionMailer, ActionPack, ActiveSupport, Mongrel, RSpec, redMine.
|
115
|
+
|
116
|
+
Lazibi was used to generate .py.rb files from these projects, and then to .rb files back ( this is the default process ). Tests were then run to ensure compatibility.
|
117
|
+
|
113
118
|
== Known issues
|
114
119
|
|
115
120
|
Here docs, eval, javascript related libs, and complex string evaluation are currently not supported.
|
data/lib/helper/task_helper.rb
CHANGED
data/lib/lazibi/version.rb
CHANGED
data/lib/parser.rb
CHANGED
@@ -15,9 +15,9 @@ module Lazibi
|
|
15
15
|
next
|
16
16
|
end
|
17
17
|
l = remove_colon_at_end(l)
|
18
|
-
|
18
|
+
|
19
19
|
s = l
|
20
|
-
if comment_at_end(l)
|
20
|
+
if comment_at_end(l)
|
21
21
|
s = s.sub(/(\s*;\s*end*\s*)(#.*)/, ' \2')
|
22
22
|
s = s.sub(/(\s+end*\s*)(#.*)/, ' \2')
|
23
23
|
else
|
@@ -39,7 +39,7 @@ module Lazibi
|
|
39
39
|
l.sub /;*$/, ''
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def to_rb( content, filters = [] )
|
44
44
|
return '' if content.strip == ''
|
45
45
|
lines = content.split("\n")
|
@@ -58,9 +58,13 @@ module Lazibi
|
|
58
58
|
lines = @lines[progress..-1]
|
59
59
|
lines.each_index do |index|
|
60
60
|
# run through filters
|
61
|
+
# destructively
|
61
62
|
l = filter_for_to_rb(lines, index, filters)
|
62
|
-
|
63
|
+
@lines[progress] = l
|
63
64
|
safe_l = clean_block(clean_line(get_rest(l)))
|
65
|
+
if l =~ /dependencies/
|
66
|
+
puts l, safe_l, clean_line(get_rest(l))
|
67
|
+
end
|
64
68
|
if start_anchor? safe_l
|
65
69
|
relative_index_for_end = find_end( lines[index..-1], get_indent(l))
|
66
70
|
unless relative_index_for_end
|
@@ -68,15 +72,19 @@ module Lazibi
|
|
68
72
|
break
|
69
73
|
end
|
70
74
|
index_for_end = relative_index_for_end + index
|
75
|
+
|
71
76
|
if relative_index_for_end == 0 && !comment_at_end(l)
|
72
|
-
l = lines[index_for_end]
|
77
|
+
#l = lines[index_for_end]
|
73
78
|
lines[index_for_end] = lines[index_for_end].rstrip + '; end'
|
74
79
|
else
|
75
80
|
lines[index_for_end] = lines[index_for_end] + "\n" + ' ' * get_indent(l) + "end"
|
76
81
|
end
|
77
82
|
head = @lines[0...progress]
|
78
83
|
tail = lines[index..-1].join("\n").split("\n")
|
84
|
+
|
79
85
|
@lines = head + tail
|
86
|
+
|
87
|
+
|
80
88
|
progress += 1
|
81
89
|
break
|
82
90
|
end
|
@@ -126,7 +134,6 @@ module Lazibi
|
|
126
134
|
if filters.include?( :optional_do )
|
127
135
|
l = optional_do_filter_to_rb(lines, index)
|
128
136
|
end
|
129
|
-
|
130
137
|
# destructive behaviour
|
131
138
|
lines[index] = l
|
132
139
|
l
|
@@ -135,13 +142,24 @@ module Lazibi
|
|
135
142
|
def optional_do_filter_to_rb(lines, index)
|
136
143
|
l = lines[index]
|
137
144
|
return l if l.strip == ''
|
138
|
-
|
145
|
+
return l if l =~ /[\{\[]\s*$/
|
146
|
+
rest = get_rest(l)
|
139
147
|
return l if start_anchor?(rest) || middle_anchor?(rest) || end_anchor?(rest)
|
140
148
|
|
141
149
|
l_check = clean_line l
|
142
|
-
|
143
|
-
|
144
|
-
|
150
|
+
# bad code
|
151
|
+
# return l if nasty_line?(l_check)
|
152
|
+
next_line = ''
|
153
|
+
if index + 1 < lines.size
|
154
|
+
lines[index+1..-1].each_index do |i|
|
155
|
+
abs_i = index + 1 + i
|
156
|
+
next if lines[abs_i].strip == ''
|
157
|
+
next_line = lines[abs_i]
|
158
|
+
break
|
159
|
+
end
|
160
|
+
else
|
161
|
+
return l
|
162
|
+
end
|
145
163
|
if get_indent(next_line) > get_indent(l)
|
146
164
|
return l.rstrip + ' do'
|
147
165
|
else
|
data/lib/vendor/beautifier.rb
CHANGED
@@ -72,12 +72,12 @@ module Beautifier
|
|
72
72
|
|
73
73
|
tline.gsub!(/#\{.*?\}/,"")
|
74
74
|
tline.gsub!(/\\\"/,"'")
|
75
|
-
|
75
|
+
|
76
76
|
# deal with nested syntax
|
77
|
-
|
77
|
+
|
78
78
|
tline.gsub!(/"\/*?"/,"\"\"")
|
79
79
|
tline.gsub!(/\/.*?[^\\]\//,"//")
|
80
|
-
|
80
|
+
|
81
81
|
# again
|
82
82
|
tline.gsub!(/".*?"/,"\"\"")
|
83
83
|
tline.gsub!(/'.*?'/,"''")
|
@@ -0,0 +1,12 @@
|
|
1
|
+
def require_dependencies(layer, dependencies)
|
2
|
+
dependencies.flatten.each do |dependency|
|
3
|
+
begin
|
4
|
+
require_dependency(dependency.to_s)
|
5
|
+
rescue LoadError => e
|
6
|
+
raise LoadError.new("Missing #{layer} #{dependency}.rb").copy_blame!(e)
|
7
|
+
rescue Exception => exception # error from loaded file
|
8
|
+
exception.blame_file! "=> #{layer} #{dependency}.rb"
|
9
|
+
raise
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
it "should read several example names from file if --example is given an existing file name" do
|
2
|
+
options = parse(["--example", File.dirname(__FILE__) + '/examples.txt'])
|
3
|
+
options.examples.should eql([
|
4
|
+
"Sir, if you were my husband, I would poison your drink.",
|
5
|
+
"Madam, if you were my wife, I would drink it."])
|
6
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
def require_dependencies(layer, dependencies)
|
2
|
+
dependencies.flatten.each do |dependency|
|
3
|
+
begin
|
4
|
+
require_dependency(dependency.to_s)
|
5
|
+
rescue LoadError => e
|
6
|
+
raise LoadError.new("Missing #{layer} #{dependency}.rb").copy_blame!(e)
|
7
|
+
rescue Exception => exception # error from loaded file
|
8
|
+
exception.blame_file! "=> #{layer} #{dependency}.rb"
|
9
|
+
raise
|
@@ -0,0 +1,5 @@
|
|
1
|
+
it "should read several example names from file if --example is given an existing file name"
|
2
|
+
options = parse(["--example", File.dirname(__FILE__) + '/examples.txt'])
|
3
|
+
options.examples.should eql([
|
4
|
+
"Sir, if you were my husband, I would poison your drink.",
|
5
|
+
"Madam, if you were my wife, I would drink it."])
|
data/test/test_functional.rb
CHANGED
@@ -4,6 +4,30 @@ require 'pp'
|
|
4
4
|
class TestLazibiFunctional < Test::Unit::TestCase
|
5
5
|
|
6
6
|
def setup
|
7
|
+
# load fixtures
|
8
|
+
@ruby = {}
|
9
|
+
@beauty = {}
|
10
|
+
@simply = {}
|
11
|
+
|
12
|
+
ruby_dir = File.dirname(__FILE__) + '/fixtures/functional/ruby'
|
13
|
+
Dir.open(ruby_dir).each do |fn|
|
14
|
+
next unless fn =~ /[.]txt$/
|
15
|
+
@ruby[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(ruby_dir + "/#{fn}")
|
16
|
+
end
|
17
|
+
|
18
|
+
beauty_dir = File.dirname(__FILE__) + '/fixtures/functional/beauty'
|
19
|
+
Dir.open(beauty_dir).each do |fn|
|
20
|
+
next unless fn =~ /[.]txt$/
|
21
|
+
@beauty[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(beauty_dir + "/#{fn}")
|
22
|
+
end
|
23
|
+
|
24
|
+
simply_dir = File.dirname(__FILE__) + '/fixtures/functional/simply'
|
25
|
+
Dir.open(simply_dir).each do |fn|
|
26
|
+
next unless fn =~ /[.]txt$/
|
27
|
+
@simply[fn.scan(/(.*)[.]/).to_s.to_sym] = File.read(simply_dir + "/#{fn}")
|
28
|
+
end
|
29
|
+
|
30
|
+
|
7
31
|
@r = Lazibi::Runner.new
|
8
32
|
@r.load_config
|
9
33
|
end
|
@@ -30,4 +54,22 @@ class TestLazibiFunctional < Test::Unit::TestCase
|
|
30
54
|
assert_equal @r.to_py('it do' ), 'it do'
|
31
55
|
assert_equal @r.to_rb("it\n abc" ), "it\n abc"
|
32
56
|
end
|
57
|
+
|
58
|
+
def test_optional_do_filter
|
59
|
+
list = [:classical, :lambda, :brackets_block, :describe, :square_brackets, :do_block]
|
60
|
+
for token in list
|
61
|
+
assert_filter :optional_do, token
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def assert_filter( filters, name )
|
67
|
+
if filters.class == 'Array'
|
68
|
+
f = filters
|
69
|
+
else
|
70
|
+
f = [filters]
|
71
|
+
end
|
72
|
+
assert_equal @r.to_py(@ruby[name], f), @simply[name]
|
73
|
+
assert_equal @r.to_rb(@simply[name], f), @ruby[name]
|
74
|
+
end
|
33
75
|
end
|
data/test/test_unit.rb
CHANGED
@@ -39,13 +39,18 @@ class TestLazibiUnit < Test::Unit::TestCase
|
|
39
39
|
assert @r.start_anchor?( 'do |abc,def| ')
|
40
40
|
assert !@r.start_anchor?( '"abc do "')
|
41
41
|
assert !@r.start_anchor?( '"abc do |"')
|
42
|
+
assert !@r.start_anchor?( 'lambda')
|
42
43
|
end
|
43
44
|
|
44
45
|
def test_middle_anchor?
|
45
46
|
assert !@r.middle_anchor?( '' )
|
46
47
|
assert @r.middle_anchor?( 'rescue' )
|
48
|
+
assert !@r.middle_anchor?( 'lambda')
|
47
49
|
end
|
48
50
|
|
51
|
+
def test_end_anchor?
|
52
|
+
assert !@r.end_anchor?( 'lambda' )
|
53
|
+
end
|
49
54
|
def test_find_end
|
50
55
|
assert_find :basic_class, 0, 0
|
51
56
|
assert_find :class_with_def, 0, 1
|
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Welcome to Lazibi</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/lazibi"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.
|
36
|
+
<a href="http://rubyforge.org/projects/lazibi" class="numbers">0.1.13</a>
|
37
37
|
</div>
|
38
38
|
<p>
|
39
39
|
Lazibi is a preprocessor that allows you to use Python style indentation in
|
@@ -180,6 +180,17 @@ Lazibi is written using Lazibi itself ( incrementally ). Personally I think
|
|
180
180
|
autotest from http://www.zenspider.com/ZSS/Products/ZenTest/ is a must
|
181
181
|
have, and Lazibi works pretty well using TDD.
|
182
182
|
</p>
|
183
|
+
<p>
|
184
|
+
A few projects are used as test code:
|
185
|
+
</p>
|
186
|
+
<pre>
|
187
|
+
ActiveRecord, ActionMailer, ActionPack, ActiveSupport, Mongrel, RSpec, redMine.
|
188
|
+
</pre>
|
189
|
+
<p>
|
190
|
+
Lazibi was used to generate .py.rb files from these projects, and then to
|
191
|
+
.rb files back ( this is the default process ). Tests were then run to
|
192
|
+
ensure compatibility.
|
193
|
+
</p>
|
183
194
|
<h2>Known issues</h2>
|
184
195
|
<p>
|
185
196
|
Here docs, eval, javascript related libs, and complex string evaluation are
|
@@ -212,7 +223,7 @@ Released under the MIT license (included)
|
|
212
223
|
</p>
|
213
224
|
|
214
225
|
<p class="coda">
|
215
|
-
<a href="mailto:nfjinjing@gmail.com">Jinjing</a>,
|
226
|
+
<a href="mailto:nfjinjing@gmail.com">Jinjing</a>, 21st June 2007<br>
|
216
227
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
217
228
|
</p>
|
218
229
|
</div>
|
data/website/index.txt
CHANGED
@@ -110,6 +110,11 @@ Start hacking in meta :/
|
|
110
110
|
|
111
111
|
Lazibi is written using Lazibi itself ( incrementally ). Personally I think autotest from http://www.zenspider.com/ZSS/Products/ZenTest/ is a must have, and Lazibi works pretty well using TDD.
|
112
112
|
|
113
|
+
A few projects are used as test code:
|
114
|
+
ActiveRecord, ActionMailer, ActionPack, ActiveSupport, Mongrel, RSpec, redMine.
|
115
|
+
|
116
|
+
Lazibi was used to generate .py.rb files from these projects, and then to .rb files back ( this is the default process ). Tests were then run to ensure compatibility.
|
117
|
+
|
113
118
|
== Known issues
|
114
119
|
|
115
120
|
Here docs, eval, javascript related libs, and complex string evaluation are currently not supported.
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: lazibi
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-06-
|
6
|
+
version: 0.1.13
|
7
|
+
date: 2007-06-22 00:00:00 +08:00
|
8
8
|
summary: Python like syntax for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -63,6 +63,18 @@ files:
|
|
63
63
|
- test/fixtures/clean/semi_colon_after_end.txt
|
64
64
|
- test/fixtures/clean/sep_line.txt
|
65
65
|
- test/fixtures/clean/unless_problem.txt
|
66
|
+
- test/fixtures/functional/ruby/brackets_block.txt
|
67
|
+
- test/fixtures/functional/ruby/classical.txt
|
68
|
+
- test/fixtures/functional/ruby/describe.txt
|
69
|
+
- test/fixtures/functional/ruby/do_block.txt
|
70
|
+
- test/fixtures/functional/ruby/lambda.txt
|
71
|
+
- test/fixtures/functional/ruby/square_brackets.txt
|
72
|
+
- test/fixtures/functional/simply/brackets_block.txt
|
73
|
+
- test/fixtures/functional/simply/classical.txt
|
74
|
+
- test/fixtures/functional/simply/describe.txt
|
75
|
+
- test/fixtures/functional/simply/do_block.txt
|
76
|
+
- test/fixtures/functional/simply/lambda.txt
|
77
|
+
- test/fixtures/functional/simply/square_brackets.txt
|
66
78
|
- test/fixtures/meta/basic_class.txt
|
67
79
|
- test/fixtures/meta/case.txt
|
68
80
|
- test/fixtures/meta/class_with_def.txt
|
@@ -143,6 +155,18 @@ extra_rdoc_files:
|
|
143
155
|
- test/fixtures/clean/semi_colon_after_end.txt
|
144
156
|
- test/fixtures/clean/sep_line.txt
|
145
157
|
- test/fixtures/clean/unless_problem.txt
|
158
|
+
- test/fixtures/functional/ruby/brackets_block.txt
|
159
|
+
- test/fixtures/functional/ruby/classical.txt
|
160
|
+
- test/fixtures/functional/ruby/describe.txt
|
161
|
+
- test/fixtures/functional/ruby/do_block.txt
|
162
|
+
- test/fixtures/functional/ruby/lambda.txt
|
163
|
+
- test/fixtures/functional/ruby/square_brackets.txt
|
164
|
+
- test/fixtures/functional/simply/brackets_block.txt
|
165
|
+
- test/fixtures/functional/simply/classical.txt
|
166
|
+
- test/fixtures/functional/simply/describe.txt
|
167
|
+
- test/fixtures/functional/simply/do_block.txt
|
168
|
+
- test/fixtures/functional/simply/lambda.txt
|
169
|
+
- test/fixtures/functional/simply/square_brackets.txt
|
146
170
|
- test/fixtures/meta/basic_class.txt
|
147
171
|
- test/fixtures/meta/case.txt
|
148
172
|
- test/fixtures/meta/class_with_def.txt
|