live_ast 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +5 -1
- data/MANIFEST +1 -0
- data/README.rdoc +9 -5
- data/devel/levitate.rb +64 -73
- data/lib/live_ast/replace_eval.rb +3 -0
- data/lib/live_ast/version.rb +1 -1
- data/test/encoding_test.rb +8 -17
- data/test/readme_test.rb +1 -0
- data/test/rubygems_test.rb +18 -0
- metadata +2 -1
data/CHANGES.rdoc
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
|
2
2
|
= live_ast Changes
|
3
3
|
|
4
|
+
== Version 0.7.1
|
5
|
+
|
6
|
+
* fix rubygems problem when parser not loaded after live_ast/full
|
7
|
+
|
4
8
|
== Version 0.7.0
|
5
9
|
|
6
10
|
* eval replacement option now included in the gem
|
7
11
|
* new 'boc' gem for eval replacement -- no more syntax restrictions
|
8
|
-
* add require 'live_ast/full' -- shortcut for
|
12
|
+
* add require 'live_ast/full' -- shortcut for live_ast + live_ast/replace_eval
|
9
13
|
* rubyspec conformance for require 'live_ast/full'
|
10
14
|
* added required_ruby_version to gemspec
|
11
15
|
* fixed error when IRB is partially required
|
data/MANIFEST
CHANGED
data/README.rdoc
CHANGED
@@ -133,7 +133,7 @@ for AST-accessible objects. +ast_eval+ has the same semantics as
|
|
133
133
|
p u.to_ast
|
134
134
|
# => s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:str, "dynamic3"))
|
135
135
|
|
136
|
-
== Full
|
136
|
+
== Full Integration
|
137
137
|
|
138
138
|
In order for LiveAST to be transparent to the user, +eval+ must be
|
139
139
|
replaced. This requires the +boc+ gem (http://quix.github.com/boc)
|
@@ -165,7 +165,7 @@ Since LiveAST itself is pure ruby, any new platforms supported by
|
|
165
165
|
== Limitations
|
166
166
|
|
167
167
|
A method or block definition must not share a line with other methods
|
168
|
-
or blocks in order for its AST to be
|
168
|
+
or blocks in order for its AST to be accessible.
|
169
169
|
|
170
170
|
require 'live_ast'
|
171
171
|
|
@@ -176,16 +176,20 @@ or blocks in order for its AST to be available.
|
|
176
176
|
|
177
177
|
a = lambda { } ; b = lambda { }
|
178
178
|
a.to_ast # => raises LiveAST::MultipleDefinitionsOnSameLineError
|
179
|
-
|
179
|
+
|
180
180
|
Code given to the <code>-e</code> command-line switch is not
|
181
181
|
AST-accessible.
|
182
182
|
|
183
|
-
|
183
|
+
Evaled code appearing before <code>require 'live_ast/full'</code> is
|
184
|
+
not AST-accessible.
|
184
185
|
|
186
|
+
In some circumstances +ast_eval+ and the replaced +eval+ will not give
|
187
|
+
the same backtrace as the original +eval+ (next section).
|
188
|
+
|
189
|
+
----
|
185
190
|
== <em>Technical Issues</em>
|
186
191
|
|
187
192
|
You can probably skip these next sections. Goodbye.
|
188
|
-
|
189
193
|
----
|
190
194
|
|
191
195
|
== Backtraces
|
data/devel/levitate.rb
CHANGED
@@ -5,79 +5,47 @@ class Levitate
|
|
5
5
|
require 'fileutils'
|
6
6
|
require 'rbconfig'
|
7
7
|
require 'find'
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
else
|
19
|
-
dest = File.join(dest_root, source.sub(%r!\A\./lib!, ""))
|
20
|
-
|
21
|
-
install = lambda {
|
22
|
-
if File.directory?(source)
|
23
|
-
unless File.directory?(dest)
|
24
|
-
puts "mkdir #{dest}"
|
25
|
-
FileUtils.mkdir(dest)
|
26
|
-
end
|
27
|
-
else
|
28
|
-
puts "install #{source} --> #{dest}"
|
29
|
-
FileUtils.install(source, dest)
|
30
|
-
end
|
31
|
-
}
|
32
|
-
|
33
|
-
uninstall = lambda {
|
34
|
-
if File.directory?(source)
|
35
|
-
if File.directory?(dest)
|
36
|
-
puts "rmdir #{dest}"
|
37
|
-
FileUtils.rmdir(dest)
|
38
|
-
end
|
39
|
-
else
|
40
|
-
if File.file?(dest)
|
41
|
-
puts "rm #{dest}"
|
42
|
-
FileUtils.rm(dest)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
}
|
46
|
-
|
47
|
-
acc << {
|
48
|
-
:source => source,
|
49
|
-
:dest => dest,
|
50
|
-
:install => install,
|
51
|
-
:uninstall => uninstall,
|
52
|
-
}
|
53
|
-
end
|
54
|
-
}
|
8
|
+
|
9
|
+
rb_root = RbConfig::CONFIG["sitelibdir"]
|
10
|
+
@spec = []
|
11
|
+
|
12
|
+
Find.find "lib" do |source|
|
13
|
+
next if source == "lib"
|
14
|
+
next unless File.directory?(source) || File.extname(source) == ".rb"
|
15
|
+
dest = File.join(rb_root, source.sub(%r!\Alib/!, ""))
|
16
|
+
@spec << { :source => source, :dest => dest }
|
17
|
+
end
|
55
18
|
end
|
56
19
|
|
57
|
-
def install_file?(source)
|
58
|
-
File.directory?(source) or
|
59
|
-
(File.file?(source) and File.extname(source) == ".rb")
|
60
|
-
end
|
61
|
-
|
62
20
|
def install
|
63
|
-
@spec.each
|
64
|
-
entry
|
65
|
-
|
21
|
+
@spec.each do |entry|
|
22
|
+
source, dest = entry.values_at(:source, :dest)
|
23
|
+
if File.directory?(source)
|
24
|
+
unless File.directory?(dest)
|
25
|
+
puts "mkdir #{dest}"
|
26
|
+
FileUtils.mkdir(dest)
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts "install #{source} --> #{dest}"
|
30
|
+
FileUtils.install(source, dest)
|
31
|
+
end
|
32
|
+
end
|
66
33
|
end
|
67
34
|
|
68
35
|
def uninstall
|
69
|
-
@spec.reverse.each
|
70
|
-
entry
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
36
|
+
@spec.reverse.each do |entry|
|
37
|
+
source, dest = entry.values_at(:source, :dest)
|
38
|
+
if File.directory?(source)
|
39
|
+
if File.directory?(dest)
|
40
|
+
puts "rmdir #{dest}"
|
41
|
+
FileUtils.rmdir(dest)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
if File.file?(dest)
|
45
|
+
puts "rm #{dest}"
|
46
|
+
FileUtils.rm(dest)
|
47
|
+
end
|
48
|
+
end
|
81
49
|
end
|
82
50
|
end
|
83
51
|
end
|
@@ -522,6 +490,13 @@ class Levitate
|
|
522
490
|
attribute :extensions do
|
523
491
|
["ext/#{gem_name}/extconf.rb"].select { |f| File.file? f }
|
524
492
|
end
|
493
|
+
|
494
|
+
attribute :so_file do
|
495
|
+
unless extensions.empty?
|
496
|
+
require 'rbconfig'
|
497
|
+
"lib/" + gem_name + "." + RbConfig::CONFIG["DLEXT"]
|
498
|
+
end
|
499
|
+
end
|
525
500
|
|
526
501
|
def define_clean
|
527
502
|
require 'rake/clean'
|
@@ -699,12 +674,28 @@ class Levitate
|
|
699
674
|
def define_install
|
700
675
|
desc "direct install (no gem)"
|
701
676
|
task :install do
|
702
|
-
Installer.new.
|
677
|
+
Installer.new.install
|
703
678
|
end
|
704
679
|
|
705
680
|
desc "direct uninstall (no gem)"
|
706
681
|
task :uninstall do
|
707
|
-
Installer.new.
|
682
|
+
Installer.new.uninstall
|
683
|
+
end
|
684
|
+
|
685
|
+
if so_file
|
686
|
+
dest = File.join(RbConfig::CONFIG["sitearchdir"], File.basename(so_file))
|
687
|
+
|
688
|
+
task :install => so_file do
|
689
|
+
puts "install #{so_file} --> #{dest}"
|
690
|
+
FileUtils.install(so_file, dest)
|
691
|
+
end
|
692
|
+
|
693
|
+
task :uninstall do
|
694
|
+
if File.file?(dest)
|
695
|
+
puts "rm #{dest}"
|
696
|
+
FileUtils.rm(dest)
|
697
|
+
end
|
698
|
+
end
|
708
699
|
end
|
709
700
|
end
|
710
701
|
|
@@ -804,7 +795,7 @@ class Levitate
|
|
804
795
|
end
|
805
796
|
|
806
797
|
def define_extension
|
807
|
-
|
798
|
+
if so_file and (source_control? or !File.file?(so_file))
|
808
799
|
require 'rbconfig'
|
809
800
|
require 'rake/extensiontask'
|
810
801
|
|
@@ -817,9 +808,8 @@ class Levitate
|
|
817
808
|
end
|
818
809
|
end
|
819
810
|
|
820
|
-
|
821
|
-
|
822
|
-
task :test => so
|
811
|
+
if Rake::Task[so_file].needed?
|
812
|
+
task :test => so_file
|
823
813
|
end
|
824
814
|
|
825
815
|
task :cross_native_gem do
|
@@ -917,6 +907,7 @@ class Levitate
|
|
917
907
|
raise "parse error"
|
918
908
|
end
|
919
909
|
)
|
910
|
+
code.gsub!(/^\s*%.*$/, "") # ignore shell command examples
|
920
911
|
run_doc_code(code, expected, index, instance, &block)
|
921
912
|
index += 1
|
922
913
|
}
|
data/lib/live_ast/version.rb
CHANGED
data/test/encoding_test.rb
CHANGED
@@ -1,34 +1,23 @@
|
|
1
1
|
require_relative 'main'
|
2
2
|
|
3
|
-
require_relative 'encoding_test/default.rb'
|
4
|
-
require_relative 'encoding_test/usascii.rb'
|
5
|
-
require_relative 'encoding_test/utf8.rb'
|
6
|
-
require_relative 'encoding_test/utf8bom.rb'
|
7
|
-
require_relative 'encoding_test/utf8bom_only.rb'
|
8
|
-
require_relative 'encoding_test/usascii_with_utf8bom.rb'
|
9
|
-
require_relative 'encoding_test/koi8_with_utf8bom.rb'
|
10
|
-
require_relative 'encoding_test/cp932.rb'
|
11
|
-
require_relative 'encoding_test/eucjp.rb'
|
12
|
-
require_relative 'encoding_test/koi8.rb'
|
13
|
-
require_relative 'encoding_test/koi8_shebang.rb'
|
14
|
-
|
15
3
|
class AllEncodingTest < RegularTest
|
16
|
-
|
17
|
-
|
18
|
-
%w[
|
19
|
-
|
4
|
+
ENC_TESTS = Hash[*%w[
|
20
5
|
default US-ASCII
|
21
6
|
usascii US-ASCII
|
22
7
|
utf8 UTF-8
|
23
8
|
utf8bom UTF-8
|
9
|
+
utf8bom_only UTF-8
|
24
10
|
usascii_with_utf8bom US-ASCII
|
25
11
|
koi8_with_utf8bom KOI8-R
|
26
12
|
cp932 Windows-31J
|
27
13
|
eucjp EUC-JP
|
28
14
|
koi8 KOI8-R
|
29
15
|
koi8_shebang KOI8-R
|
16
|
+
]]
|
17
|
+
|
18
|
+
ENC_TESTS.each_pair do |abbr, name|
|
19
|
+
require_relative "encoding_test/#{abbr}"
|
30
20
|
|
31
|
-
].each_slice(2) do |abbr, name|
|
32
21
|
define_method "test_#{abbr}" do
|
33
22
|
str = send("#{abbr}_string")
|
34
23
|
assert_equal name, str.encoding.to_s
|
@@ -43,6 +32,8 @@ class AllEncodingTest < RegularTest
|
|
43
32
|
end
|
44
33
|
end
|
45
34
|
|
35
|
+
include EncodingTest
|
36
|
+
|
46
37
|
def test_bad
|
47
38
|
orig = assert_raises ArgumentError do
|
48
39
|
live_ast_original_load "./test/encoding_test/bad.rb"
|
data/test/readme_test.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'main'
|
2
|
+
require_relative '../devel/levitate'
|
3
|
+
|
4
|
+
class RubygemsTest < RegularTest
|
5
|
+
def test_rubygems
|
6
|
+
lib = File.expand_path(File.dirname(__FILE__) + "/../lib")
|
7
|
+
result = Levitate::Ruby.run_code_and_capture %{
|
8
|
+
$LOAD_PATH.unshift '#{lib}'
|
9
|
+
require 'live_ast/full'
|
10
|
+
defined?(LiveASTRipper) and LiveASTRipper.steamroll = true
|
11
|
+
f = eval %{
|
12
|
+
lambda { 'abc' }
|
13
|
+
}
|
14
|
+
p f.to_ast
|
15
|
+
}
|
16
|
+
assert_equal no_arg_block(:lambda, 'abc').to_s, result.chomp
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: live_ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James M. Lawrence
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- test/redefine_method_test.rb
|
94
94
|
- test/reload_test.rb
|
95
95
|
- test/replace_eval_test.rb
|
96
|
+
- test/rubygems_test.rb
|
96
97
|
- test/rubyspec_test.rb
|
97
98
|
- test/stdlib_test.rb
|
98
99
|
- test/thread_test.rb
|