live_ast 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.rdoc +6 -0
- data/MANIFEST +3 -1
- data/README.rdoc +4 -4
- data/Rakefile +3 -3
- data/devel/{jumpstart.rb → levitate.rb} +9 -9
- data/lib/live_ast/error.rb +3 -12
- data/lib/live_ast/linker.rb +3 -3
- data/lib/live_ast/version.rb +1 -1
- data/test/attr_test.rb +24 -0
- data/test/error_test.rb +1 -1
- data/test/flush_cache_test.rb +3 -3
- data/test/main.rb +2 -2
- data/test/nested_test.rb +29 -0
- data/test/readme_test.rb +4 -3
- data/test/to_ruby_test.rb +2 -3
- metadata +6 -4
data/CHANGES.rdoc
CHANGED
data/MANIFEST
CHANGED
@@ -2,7 +2,7 @@ CHANGES.rdoc
|
|
2
2
|
MANIFEST
|
3
3
|
README.rdoc
|
4
4
|
Rakefile
|
5
|
-
devel/
|
5
|
+
devel/levitate.rb
|
6
6
|
lib/live_ast.rb
|
7
7
|
lib/live_ast/ast_eval.rb
|
8
8
|
lib/live_ast/ast_load.rb
|
@@ -19,6 +19,7 @@ lib/live_ast/to_ruby.rb
|
|
19
19
|
lib/live_ast/version.rb
|
20
20
|
test/ast_eval_feature_test.rb
|
21
21
|
test/ast_load_feature_test.rb
|
22
|
+
test/attr_test.rb
|
22
23
|
test/backtrace_test.rb
|
23
24
|
test/covert_define_method_test.rb
|
24
25
|
test/def_test.rb
|
@@ -44,6 +45,7 @@ test/lambda_test.rb
|
|
44
45
|
test/load_path_test.rb
|
45
46
|
test/load_test.rb
|
46
47
|
test/main.rb
|
48
|
+
test/nested_test.rb
|
47
49
|
test/noninvasive_test.rb
|
48
50
|
test/readme_test.rb
|
49
51
|
test/recursive_eval_test.rb
|
data/README.rdoc
CHANGED
@@ -182,8 +182,8 @@ To override the default parser,
|
|
182
182
|
LiveAST.parser = YourParser
|
183
183
|
|
184
184
|
To test it, provide some examples of what the ASTs look like in
|
185
|
-
<code>YourParser::
|
186
|
-
|
185
|
+
<code>YourParser::Test</code>. See the +live_ast_ruby_parser+ gem for
|
186
|
+
reference.
|
187
187
|
|
188
188
|
== Noninvasive Mode
|
189
189
|
|
@@ -223,12 +223,12 @@ The following alternative interface is available.
|
|
223
223
|
# => s(:defn, :f, s(:args), s(:scope, s(:block, s(:str, "A#f"))))
|
224
224
|
|
225
225
|
p LiveAST.ast(lambda { })
|
226
|
-
# => s(:iter, s(:call, nil, :lambda, s(:arglist)), nil
|
226
|
+
# => s(:iter, s(:call, nil, :lambda, s(:arglist)), nil)
|
227
227
|
|
228
228
|
f = LiveAST.eval("lambda { }", binding)
|
229
229
|
|
230
230
|
p LiveAST.ast(f)
|
231
|
-
# => s(:iter, s(:call, nil, :lambda, s(:arglist)), nil
|
231
|
+
# => s(:iter, s(:call, nil, :lambda, s(:arglist)), nil)
|
232
232
|
|
233
233
|
ast_eval # => raises NameError
|
234
234
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require_relative 'devel/
|
1
|
+
require_relative 'devel/levitate'
|
2
2
|
|
3
|
-
|
3
|
+
Levitate.new "live_ast" do |s|
|
4
4
|
s.developers << ["James M. Lawrence", "quixoticsycophant@gmail.com"]
|
5
5
|
s.github_user = "quix"
|
6
6
|
s.rubyforge_info = ["quix", "liveast"]
|
@@ -16,5 +16,5 @@ Jumpstart.new "live_ast" do |s|
|
|
16
16
|
]
|
17
17
|
s.rdoc_options << "-a"
|
18
18
|
|
19
|
-
s.dependencies << ["live_ast_ruby_parser", ">= 0.
|
19
|
+
s.dependencies << ["live_ast_ruby_parser", ">= 0.6.0"]
|
20
20
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
class
|
2
|
+
class Levitate
|
3
3
|
class Installer
|
4
4
|
def initialize
|
5
5
|
require 'fileutils'
|
@@ -816,8 +816,8 @@ class Jumpstart
|
|
816
816
|
begin
|
817
817
|
}
|
818
818
|
footer = %{
|
819
|
-
rescue Exception =>
|
820
|
-
puts "raises \#{
|
819
|
+
rescue Exception => __levitate_exception
|
820
|
+
puts "raises \#{__levitate_exception.class}"
|
821
821
|
end
|
822
822
|
}
|
823
823
|
final_code = header + code + footer
|
@@ -860,15 +860,15 @@ class Jumpstart
|
|
860
860
|
end
|
861
861
|
|
862
862
|
def doc_to_spec(file, *sections, &block)
|
863
|
-
|
863
|
+
levitate = self
|
864
864
|
describe file do
|
865
865
|
sections.each { |section|
|
866
866
|
describe "section `#{section}'" do
|
867
867
|
it "should run as claimed" do
|
868
868
|
if block
|
869
|
-
|
869
|
+
levitate.run_doc_section(file, section, self, &block)
|
870
870
|
else
|
871
|
-
|
871
|
+
levitate.run_doc_section(file, section, self) {
|
872
872
|
|expected, actual, index|
|
873
873
|
actual.should == expected
|
874
874
|
}
|
@@ -880,14 +880,14 @@ class Jumpstart
|
|
880
880
|
end
|
881
881
|
|
882
882
|
def doc_to_test(file, *sections, &block)
|
883
|
-
|
883
|
+
levitate = self
|
884
884
|
klass = Class.new MiniTest::Unit::TestCase do
|
885
885
|
sections.each { |section|
|
886
886
|
define_method "test_#{file}_#{section}" do
|
887
887
|
if block
|
888
|
-
|
888
|
+
levitate.run_doc_section(file, section, self, &block)
|
889
889
|
else
|
890
|
-
|
890
|
+
levitate.run_doc_section(file, section, self) {
|
891
891
|
|expected, actual, index|
|
892
892
|
assert_equal expected, actual
|
893
893
|
}
|
data/lib/live_ast/error.rb
CHANGED
@@ -7,23 +7,14 @@ module LiveAST
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class ASTNotFoundError < StandardError
|
10
|
-
end
|
11
|
-
|
12
|
-
class RawEvalError < ASTNotFoundError
|
13
10
|
def message
|
14
|
-
"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class NoSourceError < ASTNotFoundError
|
19
|
-
def message
|
20
|
-
"No source found for the requested AST."
|
11
|
+
"The requested AST could not be found (AST flushed or compiled code)."
|
21
12
|
end
|
22
13
|
end
|
23
14
|
|
24
|
-
class
|
15
|
+
class RawEvalError < ASTNotFoundError
|
25
16
|
def message
|
26
|
-
"
|
17
|
+
"Must use ast_eval instead of eval in order to obtain AST."
|
27
18
|
end
|
28
19
|
end
|
29
20
|
end
|
data/lib/live_ast/linker.rb
CHANGED
@@ -53,7 +53,7 @@ module LiveAST
|
|
53
53
|
def find_proc_ast(obj)
|
54
54
|
@mutex.synchronize do
|
55
55
|
fetch_proc_attachment(obj) or (
|
56
|
-
ast = find_ast(*obj.source_location) or raise
|
56
|
+
ast = find_ast(*obj.source_location) or raise ASTNotFoundError
|
57
57
|
attach_to_proc(obj, ast)
|
58
58
|
)
|
59
59
|
end
|
@@ -63,7 +63,7 @@ module LiveAST
|
|
63
63
|
@mutex.synchronize do
|
64
64
|
case ast = find_ast(*location)
|
65
65
|
when nil
|
66
|
-
fetch_method_attachment(klass, name) or raise
|
66
|
+
fetch_method_attachment(klass, name) or raise ASTNotFoundError
|
67
67
|
else
|
68
68
|
attach_to_method(klass, name, ast)
|
69
69
|
end
|
@@ -71,7 +71,7 @@ module LiveAST
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def find_ast(*location)
|
74
|
-
raise
|
74
|
+
raise ASTNotFoundError unless location.size == 2
|
75
75
|
raise RawEvalError if location.first == "(eval)"
|
76
76
|
ast = fetch_from_cache(*location)
|
77
77
|
raise MultipleDefinitionsOnSameLineError if ast == :multiple
|
data/lib/live_ast/version.rb
CHANGED
data/test/attr_test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'main'
|
2
|
+
|
3
|
+
class AttrTest < RegularTest
|
4
|
+
class A
|
5
|
+
attr_accessor :f
|
6
|
+
attr_reader :g
|
7
|
+
attr_writer :h
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_attr
|
11
|
+
assert_raises LiveAST::ASTNotFoundError do
|
12
|
+
A.instance_method(:f).to_ast
|
13
|
+
end
|
14
|
+
assert_raises LiveAST::ASTNotFoundError do
|
15
|
+
A.instance_method(:f=).to_ast
|
16
|
+
end
|
17
|
+
assert_raises LiveAST::ASTNotFoundError do
|
18
|
+
A.instance_method(:g).to_ast
|
19
|
+
end
|
20
|
+
assert_raises LiveAST::ASTNotFoundError do
|
21
|
+
A.instance_method(:h=).to_ast
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/error_test.rb
CHANGED
data/test/flush_cache_test.rb
CHANGED
@@ -39,7 +39,7 @@ define_unsorted_test_case "FlushCacheTest", RegularTest do
|
|
39
39
|
|
40
40
|
LiveAST.flush_cache
|
41
41
|
|
42
|
-
assert_raises LiveAST::
|
42
|
+
assert_raises LiveAST::ASTNotFoundError do
|
43
43
|
klass.instance_method(:g).to_ast
|
44
44
|
end
|
45
45
|
end
|
@@ -59,7 +59,7 @@ define_unsorted_test_case "FlushCacheTest", RegularTest do
|
|
59
59
|
assert_equal f_ast.object_id,
|
60
60
|
klass.instance_method(:f).to_ast.object_id
|
61
61
|
|
62
|
-
assert_raises LiveAST::
|
62
|
+
assert_raises LiveAST::ASTNotFoundError do
|
63
63
|
klass.instance_method(:g).to_ast
|
64
64
|
end
|
65
65
|
end
|
@@ -91,7 +91,7 @@ define_unsorted_test_case "FlushCacheTest", RegularTest do
|
|
91
91
|
|
92
92
|
assert_equal a_ast.object_id, a.to_ast.object_id
|
93
93
|
|
94
|
-
assert_raises LiveAST::
|
94
|
+
assert_raises LiveAST::ASTNotFoundError do
|
95
95
|
b.to_ast
|
96
96
|
end
|
97
97
|
end
|
data/test/main.rb
CHANGED
@@ -30,7 +30,7 @@ class JLMiniTest < MiniTest::Unit::TestCase
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def delim(char)
|
33
|
-
"
|
33
|
+
"\n" << (char*72) << "\n"
|
34
34
|
end
|
35
35
|
|
36
36
|
def mu_pp(obj)
|
@@ -74,7 +74,7 @@ class JLMiniTest < MiniTest::Unit::TestCase
|
|
74
74
|
end
|
75
75
|
|
76
76
|
class BaseTest < JLMiniTest
|
77
|
-
include LiveAST.parser::
|
77
|
+
include LiveAST.parser::Test
|
78
78
|
|
79
79
|
DATA_DIR = File.expand_path(File.dirname(__FILE__) + "/data")
|
80
80
|
|
data/test/nested_test.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'main'
|
2
|
+
|
3
|
+
class NestedTest < RegularTest
|
4
|
+
def test_lambda
|
5
|
+
a = lambda {
|
6
|
+
lambda {
|
7
|
+
"33"
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
assert_equal nested_lambdas("33"), a.to_ast
|
12
|
+
assert_equal no_arg_block(:lambda, "33"), a.call.to_ast
|
13
|
+
end
|
14
|
+
|
15
|
+
class A
|
16
|
+
def f
|
17
|
+
Class.new do
|
18
|
+
def g
|
19
|
+
"44"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_defs
|
26
|
+
assert_equal nested_defs(:f, :g, "44"), A.instance_method(:f).to_ast
|
27
|
+
assert_equal no_arg_def(:g, "44"), A.new.f.instance_method(:g).to_ast
|
28
|
+
end
|
29
|
+
end
|
data/test/readme_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require_relative 'main'
|
2
|
-
require_relative '../devel/
|
2
|
+
require_relative '../devel/levitate'
|
3
3
|
|
4
|
-
if LiveAST.parser.respond_to?(:
|
4
|
+
if LiveAST.parser::Test.respond_to?(:unified_sexp?) and
|
5
|
+
LiveAST.parser::Test.unified_sexp?
|
5
6
|
sections = [
|
6
7
|
"Synopsis",
|
7
8
|
"Loading Source",
|
@@ -9,5 +10,5 @@ if LiveAST.parser.respond_to?(:unified?) and LiveAST.parser.unified?
|
|
9
10
|
"+to_ruby+",
|
10
11
|
]
|
11
12
|
|
12
|
-
|
13
|
+
Levitate.doc_to_test("README.rdoc", *sections)
|
13
14
|
end
|
data/test/to_ruby_test.rb
CHANGED
@@ -83,6 +83,5 @@ class AAC_ToRubyTest < RegularTest
|
|
83
83
|
end.instance_method(:f).to_ruby
|
84
84
|
assert_equal src, dst
|
85
85
|
end
|
86
|
-
end if
|
87
|
-
|
88
|
-
un.ruby2ruby?
|
86
|
+
end if LiveAST.parser::Test.respond_to?(:unparser_matches_ruby2ruby?) &&
|
87
|
+
LiveAST.parser::Test.unparser_matches_ruby2ruby?
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: live_ast
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James M. Lawrence
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-26 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ">="
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 0.
|
24
|
+
version: 0.6.0
|
25
25
|
type: :runtime
|
26
26
|
version_requirements: *id001
|
27
27
|
description: LiveAST enables a program to find the ASTs of objects created by dynamically generated code.
|
@@ -37,7 +37,7 @@ files:
|
|
37
37
|
- CHANGES.rdoc
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
|
-
- devel/
|
40
|
+
- devel/levitate.rb
|
41
41
|
- lib/live_ast.rb
|
42
42
|
- lib/live_ast/ast_eval.rb
|
43
43
|
- lib/live_ast/ast_load.rb
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/live_ast/version.rb
|
55
55
|
- test/ast_eval_feature_test.rb
|
56
56
|
- test/ast_load_feature_test.rb
|
57
|
+
- test/attr_test.rb
|
57
58
|
- test/backtrace_test.rb
|
58
59
|
- test/covert_define_method_test.rb
|
59
60
|
- test/def_test.rb
|
@@ -79,6 +80,7 @@ files:
|
|
79
80
|
- test/load_path_test.rb
|
80
81
|
- test/load_test.rb
|
81
82
|
- test/main.rb
|
83
|
+
- test/nested_test.rb
|
82
84
|
- test/noninvasive_test.rb
|
83
85
|
- test/readme_test.rb
|
84
86
|
- test/recursive_eval_test.rb
|