live_ast_ripper 0.5.1 → 0.6.0
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/CHANGES.rdoc +6 -0
- data/MANIFEST +3 -2
- data/README.rdoc +5 -1
- data/Rakefile +6 -4
- data/devel/{jumpstart.rb → levitate.rb} +9 -9
- data/lib/live_ast_ripper.rb +43 -69
- data/lib/live_ast_ripper/{test_forms.rb → test.rb} +64 -2
- data/lib/live_ast_ripper/version.rb +3 -0
- metadata +8 -7
data/CHANGES.rdoc
CHANGED
data/MANIFEST
CHANGED
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
-
require_relative 'devel/
|
1
|
+
require_relative 'devel/levitate'
|
2
2
|
|
3
|
-
|
3
|
+
Levitate.new "live_ast_ripper" do |s|
|
4
4
|
s.developers << ["James M. Lawrence", "quixoticsycophant@gmail.com"]
|
5
5
|
s.github_user = "quix"
|
6
|
-
s.
|
6
|
+
s.camel_name = "LiveASTRipper"
|
7
7
|
s.description = s.summary
|
8
8
|
end
|
9
9
|
|
10
|
-
# testing done inside live_ast
|
11
10
|
task :test do
|
11
|
+
puts "Testing is done with LiveAST test suite."
|
12
12
|
end
|
13
|
+
|
14
|
+
task :default => :test
|
@@ -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_ripper.rb
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
require 'live_ast/base'
|
2
2
|
require 'ripper'
|
3
3
|
|
4
|
+
#
|
5
|
+
# Ripper-based parser plugin for LiveAST.
|
6
|
+
#
|
4
7
|
class LiveASTRipper
|
5
|
-
class << self
|
6
|
-
#
|
7
|
-
# Whether to strip line/column and other personality traits.
|
8
|
-
#
|
9
|
-
# This is Ripper-specific -- not part of the live_ast API.
|
10
|
-
#
|
11
|
-
attr_accessor :steamroll
|
12
|
-
end
|
13
|
-
|
14
8
|
#
|
15
|
-
# Returns a line
|
16
|
-
#
|
9
|
+
# Returns a line-to-sexp hash where sexp corresponds to the method
|
10
|
+
# or block defined at the given line.
|
11
|
+
#
|
12
|
+
# This method is the only requirement of a LiveAST parser plugin.
|
17
13
|
#
|
18
14
|
def parse(code)
|
19
15
|
@defs = {}
|
@@ -22,78 +18,56 @@ class LiveASTRipper
|
|
22
18
|
end
|
23
19
|
|
24
20
|
def process(sexp)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
line = sexp[1][2][0]
|
39
|
-
|
40
|
-
result = []
|
41
|
-
result << sexp.shift
|
42
|
-
result << sexp.shift
|
43
|
-
result << process(sexp.shift)
|
44
|
-
result << process(sexp.shift)
|
45
|
-
|
46
|
-
result = steamroll(result) if LiveASTRipper.steamroll
|
47
|
-
store_sexp(result, line)
|
48
|
-
|
49
|
-
[]
|
50
|
-
end
|
51
|
-
|
52
|
-
def process_method_add_block(sexp)
|
53
|
-
line =
|
54
|
-
case sexp[1][0]
|
55
|
-
when :method_add_arg
|
56
|
-
sexp[1][1][1].last[0]
|
57
|
-
when :call, :command_call
|
58
|
-
sexp[1][3][2][0]
|
59
|
-
when :command
|
60
|
-
sexp[1][1][2][0]
|
21
|
+
line =
|
22
|
+
case sexp.first
|
23
|
+
when :def
|
24
|
+
sexp[1][2][0]
|
25
|
+
when :method_add_block
|
26
|
+
case sexp[1][0]
|
27
|
+
when :method_add_arg
|
28
|
+
sexp[1][1][1].last[0]
|
29
|
+
when :call, :command_call
|
30
|
+
sexp[1][3][2][0]
|
31
|
+
when :command
|
32
|
+
sexp[1][1][2][0]
|
33
|
+
end
|
61
34
|
end
|
62
35
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
result << process(sexp.shift)
|
67
|
-
|
68
|
-
result = steamroll(result) if LiveASTRipper.steamroll
|
69
|
-
store_sexp(result, line)
|
36
|
+
if line
|
37
|
+
@defs[line] = @defs.has_key?(line) ? :multiple : sexp
|
38
|
+
end
|
70
39
|
|
71
|
-
|
72
|
-
end
|
40
|
+
steamroll(sexp) if LiveASTRipper.steamroll
|
73
41
|
|
74
|
-
|
75
|
-
|
42
|
+
sexp.each do |elem|
|
43
|
+
process(elem) if elem.is_a? Array
|
44
|
+
end
|
76
45
|
end
|
77
46
|
|
78
47
|
def steamroll(sexp)
|
79
|
-
sexp.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
steamroll(sub_elem)
|
88
|
-
elsif elem == :brace_block or elem == :do_block
|
48
|
+
if sexp.first.is_a?(Symbol) and sexp.first[0] == "@"
|
49
|
+
# remove [line, column]
|
50
|
+
sexp.pop
|
51
|
+
end
|
52
|
+
|
53
|
+
sexp.map! { |elem|
|
54
|
+
case elem
|
55
|
+
when :brace_block, :do_block
|
89
56
|
:block
|
90
57
|
else
|
91
58
|
elem
|
92
59
|
end
|
93
60
|
}
|
94
61
|
end
|
62
|
+
|
63
|
+
class << self
|
64
|
+
#
|
65
|
+
# Whether to strip line/column and other personality traits.
|
66
|
+
#
|
67
|
+
attr_accessor :steamroll
|
68
|
+
end
|
95
69
|
end
|
96
70
|
|
97
|
-
LiveASTRipper.autoload :
|
71
|
+
LiveASTRipper.autoload :Test, "live_ast_ripper/test"
|
98
72
|
|
99
73
|
LiveAST.parser = LiveASTRipper
|
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
|
-
#
|
3
|
-
|
2
|
+
#
|
3
|
+
# Used by the LiveAST test suite.
|
4
|
+
#
|
5
|
+
module LiveASTRipper::Test
|
4
6
|
#
|
5
7
|
# no_arg_def(:f, "A#f") returns the ast of
|
6
8
|
#
|
@@ -211,7 +213,67 @@ module LiveASTRipper::TestForms
|
|
211
213
|
op,
|
212
214
|
[:var_ref, [:@ident, "y"]]]]]]
|
213
215
|
end
|
216
|
+
|
217
|
+
#
|
218
|
+
# nested_lambdas("foo") returns the ast of
|
219
|
+
#
|
220
|
+
# lambda {
|
221
|
+
# lambda {
|
222
|
+
# "foo"
|
223
|
+
# }
|
224
|
+
# }
|
225
|
+
#
|
226
|
+
def nested_lambdas(str)
|
227
|
+
[:method_add_block,
|
228
|
+
[:method_add_arg, [:fcall, [:@ident, "lambda"]], []],
|
229
|
+
[:block,
|
230
|
+
nil,
|
231
|
+
[[:method_add_block,
|
232
|
+
[:method_add_arg, [:fcall, [:@ident, "lambda"]], []],
|
233
|
+
[:block,
|
234
|
+
nil,
|
235
|
+
[[:string_literal,
|
236
|
+
[:string_content, [:@tstring_content, str]]]]]]]]]
|
237
|
+
end
|
238
|
+
|
239
|
+
# nested_defs(:f, :g, "foo") returns the ast of
|
240
|
+
#
|
241
|
+
# def f
|
242
|
+
# Class.new do
|
243
|
+
# def g
|
244
|
+
# "foo"
|
245
|
+
# end
|
246
|
+
# end
|
247
|
+
# end
|
248
|
+
#
|
249
|
+
def nested_defs(u, v, str)
|
250
|
+
[:def,
|
251
|
+
[:@ident, u.to_s],
|
252
|
+
[:params, nil, nil, nil, nil, nil],
|
253
|
+
[:bodystmt,
|
254
|
+
[[:method_add_block,
|
255
|
+
[:call,
|
256
|
+
[:var_ref, [:@const, "Class"]],
|
257
|
+
:".",
|
258
|
+
[:@ident, "new"]],
|
259
|
+
[:block,
|
260
|
+
nil,
|
261
|
+
[[:def,
|
262
|
+
[:@ident, v.to_s],
|
263
|
+
[:params, nil, nil, nil, nil, nil],
|
264
|
+
[:bodystmt,
|
265
|
+
[[:string_literal,
|
266
|
+
[:string_content, [:@tstring_content, str]]]],
|
267
|
+
nil,
|
268
|
+
nil,
|
269
|
+
nil]]]]]],
|
270
|
+
nil,
|
271
|
+
nil,
|
272
|
+
nil]]
|
273
|
+
end
|
214
274
|
end
|
215
275
|
|
276
|
+
#
|
216
277
|
# testing assumes sexps are steamrolled
|
278
|
+
#
|
217
279
|
LiveASTRipper.steamroll = true
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: live_ast_ripper
|
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,11 +10,11 @@ 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
|
|
17
|
-
description: A Ripper-based parser
|
17
|
+
description: A Ripper-based parser plugin for LiveAST.
|
18
18
|
email:
|
19
19
|
- quixoticsycophant@gmail.com
|
20
20
|
executables: []
|
@@ -27,9 +27,10 @@ files:
|
|
27
27
|
- CHANGES.rdoc
|
28
28
|
- README.rdoc
|
29
29
|
- Rakefile
|
30
|
-
- devel/
|
30
|
+
- devel/levitate.rb
|
31
31
|
- lib/live_ast_ripper.rb
|
32
|
-
- lib/live_ast_ripper/
|
32
|
+
- lib/live_ast_ripper/test.rb
|
33
|
+
- lib/live_ast_ripper/version.rb
|
33
34
|
- MANIFEST
|
34
35
|
has_rdoc: true
|
35
36
|
homepage: http://quix.github.com/live_ast_ripper
|
@@ -40,7 +41,7 @@ rdoc_options:
|
|
40
41
|
- --main
|
41
42
|
- README.rdoc
|
42
43
|
- --title
|
43
|
-
- "live_ast_ripper: A Ripper-based parser
|
44
|
+
- "live_ast_ripper: A Ripper-based parser plugin for LiveAST."
|
44
45
|
require_paths:
|
45
46
|
- lib
|
46
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -61,6 +62,6 @@ rubyforge_project:
|
|
61
62
|
rubygems_version: 1.5.2
|
62
63
|
signing_key:
|
63
64
|
specification_version: 3
|
64
|
-
summary: A Ripper-based parser
|
65
|
+
summary: A Ripper-based parser plugin for LiveAST.
|
65
66
|
test_files: []
|
66
67
|
|