ParseTree 1.1.1 → 1.2.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.
@@ -212,15 +212,6 @@ class TestSexp < Test::Unit::TestCase # ZenTest FULL
212
212
  assert_nil(@sexp.shift)
213
213
  end
214
214
 
215
- def test_unpack_equal
216
- assert_equal false, @sexp.unpack
217
- @sexp.unpack = true
218
- assert_equal true, @sexp.unpack
219
- end
220
-
221
- def test_unpack; end # handled
222
- def test_unpack_q; end # handled
223
-
224
215
  end
225
216
 
226
217
  class TestSexpProcessor < Test::Unit::TestCase
metadata CHANGED
@@ -3,19 +3,22 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: ParseTree
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.1.1
7
- date: 2004-11-20
6
+ version: 1.2.0
7
+ date: 2004-11-29
8
8
  summary: Extract and enumerate ruby parse trees.
9
9
  require_paths:
10
- - "."
10
+ - lib
11
+ - test
11
12
  author: Ryan Davis
12
13
  email: ryand-ruby@zenspider.com
13
14
  homepage: http://www.zenspider.com/ZSS/Products/ParseTree/
14
15
  rubyforge_project: parsetree
15
- description: def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end
16
+ description: "ParseTree is a C extension (using RubyInline) that extracts the parse tree for
17
+ an entire class or a specific method and returns it as a s-expression (aka sexp)
18
+ using ruby's arrays, strings, symbols, and integers."
16
19
  autorequire: parse_tree
17
20
  default_executable:
18
- bindir: "."
21
+ bindir: bin
19
22
  has_rdoc: true
20
23
  required_ruby_version: !ruby/object:Gem::Version::Requirement
21
24
  requirements:
@@ -30,22 +33,25 @@ files:
30
33
  - Makefile
31
34
  - Manifest.txt
32
35
  - README.txt
33
- - composite_sexp_processor.rb
34
- - parse_tree.rb
35
- - parse_tree_abc
36
- - parse_tree_show
37
- - sexp_processor.rb
38
- - something.rb
39
- - test_all.rb
40
- - test_composite_sexp_processor.rb
41
- - test_parse_tree.rb
42
- - test_sexp_processor.rb
36
+ - ParseTree.gemspec
37
+ - bin/parse_tree_abc
38
+ - bin/parse_tree_deps
39
+ - bin/parse_tree_show
40
+ - lib/composite_sexp_processor.rb
41
+ - lib/parse_tree.rb
42
+ - lib/sexp_processor.rb
43
+ - test/something.rb
44
+ - test/test_all.rb
45
+ - test/test_composite_sexp_processor.rb
46
+ - test/test_parse_tree.rb
47
+ - test/test_sexp_processor.rb
43
48
  test_files:
44
- - test_all.rb
49
+ - test/test_all.rb
45
50
  rdoc_options: []
46
51
  extra_rdoc_files: []
47
52
  executables:
48
53
  - parse_tree_abc
54
+ - parse_tree_deps
49
55
  - parse_tree_show
50
56
  extensions: []
51
57
  requirements:
@@ -1,24 +0,0 @@
1
- require 'sexp_processor'
2
-
3
- class CompositeSexpProcessor < SexpProcessor
4
-
5
- attr_reader :processors
6
-
7
- def initialize(*processors)
8
- super
9
- @processors = []
10
- end
11
-
12
- def <<(processor)
13
- raise ArgumentError, "Can only add sexp processors" unless
14
- SexpProcessor === processor
15
- @processors << processor
16
- end
17
-
18
- def process(exp)
19
- @processors.each do |processor|
20
- exp = processor.process(exp)
21
- end
22
- exp
23
- end
24
- end
@@ -1,62 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- # ABC metric
4
- #
5
- # Assignments, Branches, and Calls
6
- #
7
- # A simple way to measure the complexity of a function or method.
8
-
9
- require 'parse_tree'
10
-
11
- old_classes = []
12
- ObjectSpace.each_object(Module) do |klass|
13
- old_classes << klass
14
- end
15
-
16
- ARGV.each do |name|
17
- require name
18
- end
19
-
20
- new_classes = []
21
- ObjectSpace.each_object(Module) do |klass|
22
- new_classes << klass
23
- end
24
-
25
- score = {}
26
-
27
- new_classes -= old_classes
28
-
29
- new_classes.each do |klass|
30
- ParseTree.new.parse_tree(klass).each do |defn|
31
- a=b=c=0
32
- defn.shift
33
- name = defn.shift
34
- tokens = defn.flatten.find_all { |t| Symbol === t }
35
- tokens.each do |token|
36
- case token
37
- when :attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn then
38
- a += 1
39
- when :and, :case, :else, :if, :iter, :or, :rescue, :until, :when, :while then
40
- b += 1
41
- when :call, :fcall, :super, :vcall, :yield then
42
- c += 1
43
- when :args, :argscat, :array, :begin, :block, :bool, :cfunc, :colon2, :const, :cvar, :defined, :defn, :dregx, :dstr, :dvar, :dxstr, :ensure, :false, :fbody, :gvar, :hash, :ivar, :lit, :long, :lvar, :match2, :match3, :nil, :not, :nth_ref, :return, :scope, :self, :splat, :str, :to_ary, :true, :unknown, :value, :void, :zarray, :zarray, :zclass, :zsuper then
44
- # ignore
45
- else
46
- puts "unhandled token #{token.inspect}"
47
- end
48
- end
49
- key = ["#{klass}.#{name}", a, b, c]
50
- val = a+b+c
51
- score[key] = val
52
- end
53
- end
54
-
55
- puts "Method = assignments + branches + calls = total"
56
- puts
57
- count = 1
58
- score.sort_by { |k,v| v }.reverse.each do |key,val|
59
- name, a, b, c = *key
60
- printf "%3d) %-50s = %2d + %2d + %2d = %3d\n", count, name, a, b, c, val
61
- count += 1
62
- end
@@ -1,28 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- require 'pp'
4
- require 'parse_tree'
5
-
6
- old_classes = []
7
- ObjectSpace.each_object(Module) do |klass|
8
- old_classes << klass
9
- end
10
-
11
- ARGV.each do |name|
12
- if name == "-" then
13
- eval $stdin.read
14
- else
15
- require name
16
- end
17
- end
18
-
19
- new_classes = []
20
- ObjectSpace.each_object(Module) do |klass|
21
- new_classes << klass
22
- end
23
-
24
- new_classes -= old_classes
25
-
26
- new_classes.each do |klass|
27
- pp ParseTree.new.parse_tree(klass)
28
- end
@@ -1,7 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- Dir.glob("test_*.rb").each do |f|
4
- require f
5
- end
6
-
7
- require 'test/unit'
@@ -1,275 +0,0 @@
1
- #!/usr/local/bin/ruby -w
2
-
3
- require 'test/unit'
4
- require 'parse_tree'
5
- require 'something'
6
-
7
- class TestParseTree < Test::Unit::TestCase
8
-
9
- # TODO: need a test of interpolated strings
10
-
11
- @@missing = [nil]
12
- @@empty = [:defn, "empty",
13
- [:scope,
14
- [:args]]]
15
- @@stupid = [:defn, "stupid",
16
- [:scope,
17
- [:block,
18
- [:args],
19
- [:return, [:nil]]]]]
20
- @@simple = [:defn, "simple",
21
- [:scope,
22
- [:block,
23
- [:args, "arg1"],
24
- [:fcall, "print",
25
- [:array, [:lvar, "arg1"]]],
26
- [:fcall, "puts",
27
- [:array,
28
- [:call,
29
- [:call,
30
- [:lit, 4],
31
- "+",
32
- [:array, [:lit, 2]]],
33
- "to_s"]]]]]]
34
- @@global = [:defn, "global",
35
- [:scope,
36
- [:block,
37
- [:args],
38
- [:call,
39
- [:gvar, "$stderr"],
40
- "fputs",
41
- [:array, [:str, "blah"]]]]]]
42
- @@lasgn_call = [:defn, "lasgn_call",
43
- [:scope,
44
- [:block,
45
- [:args],
46
- [:lasgn, "c",
47
- [:call,
48
- [:lit, 2],
49
- "+",
50
- [:array, [:lit, 3]]]]]]]
51
- @@conditional1 = [:defn, "conditional1",
52
- [:scope,
53
- [:block,
54
- [:args, "arg1"],
55
- [:if,
56
- [:call,
57
- [:lvar, "arg1"],
58
- "==",
59
- [:array, [:lit, 0]]],
60
- [:return,
61
- [:lit, 1]], nil]]]]
62
- @@conditional2 = [:defn, "conditional2",
63
- [:scope,
64
- [:block,
65
- [:args, "arg1"],
66
- [:if,
67
- [:call,
68
- [:lvar, "arg1"],
69
- "==",
70
- [:array, [:lit, 0]]], nil,
71
- [:return,
72
- [:lit, 2]]]]]]
73
- @@conditional3 = [:defn, "conditional3",
74
- [:scope,
75
- [:block,
76
- [:args, "arg1"],
77
- [:if,
78
- [:call,
79
- [:lvar, "arg1"],
80
- "==",
81
- [:array, [:lit, 0]]],
82
- [:return,
83
- [:lit, 3]],
84
- [:return,
85
- [:lit, 4]]]]]]
86
- @@conditional4 = [:defn, "conditional4",
87
- [:scope,
88
- [:block,
89
- [:args, "arg1"],
90
- [:if,
91
- [:call,
92
- [:lvar, "arg1"],
93
- "==",
94
- [:array, [:lit, 0]]],
95
- [:return, [:lit, 2]],
96
- [:if,
97
- [:call,
98
- [:lvar, "arg1"],
99
- "<",
100
- [:array, [:lit, 0]]],
101
- [:return, [:lit, 3]],
102
- [:return, [:lit, 4]]]]]]]
103
- @@iteration_body = [:scope,
104
- [:block,
105
- [:args],
106
- [:lasgn, "array",
107
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
108
- [:iter,
109
- [:call,
110
- [:lvar, "array"], "each"],
111
- [:dasgn_curr, "x"],
112
- [:fcall, "puts", [:array, [:call, [:dvar, "x"], "to_s"]]]]]]
113
- @@iteration1 = [:defn, "iteration1", @@iteration_body]
114
- @@iteration2 = [:defn, "iteration2", @@iteration_body]
115
- @@iteration3 = [:defn, "iteration3",
116
- [:scope,
117
- [:block,
118
- [:args],
119
- [:lasgn, "array1",
120
- [:array, [:lit, 1], [:lit, 2], [:lit, 3]]],
121
- [:lasgn, "array2",
122
- [:array, [:lit, 4], [:lit, 5], [:lit, 6], [:lit, 7]]],
123
- [:iter,
124
- [:call,
125
- [:lvar, "array1"], "each"],
126
- [:dasgn_curr, "x"],
127
- [:iter,
128
- [:call,
129
- [:lvar, "array2"], "each"],
130
- [:dasgn_curr, "y"],
131
- [:block,
132
- [:fcall, "puts",
133
- [:array, [:call, [:dvar, "x"], "to_s"]]],
134
- [:fcall, "puts",
135
- [:array, [:call, [:dvar, "y"], "to_s"]]]]]]]]]
136
- @@iteration4 = [:defn,
137
- "iteration4",
138
- [:scope,
139
- [:block,
140
- [:args],
141
- [:iter,
142
- [:call, [:lit, 1], "upto", [:array, [:lit, 3]]],
143
- [:dasgn_curr, "n"],
144
- [:fcall, "puts", [:array, [:call, [:dvar, "n"], "to_s"]]]]]]]
145
- @@iteration5 = [:defn,
146
- "iteration5",
147
- [:scope,
148
- [:block,
149
- [:args],
150
- [:iter,
151
- [:call, [:lit, 3], "downto", [:array, [:lit, 1]]],
152
- [:dasgn_curr, "n"],
153
- [:fcall, "puts", [:array, [:call, [:dvar, "n"], "to_s"]]]]]]]
154
- @@iteration6 = [:defn,
155
- "iteration6",
156
- [:scope,
157
- [:block,
158
- [:args],
159
- [:iter,
160
- [:call, [:lit, 3], "downto", [:array, [:lit, 1]]],
161
- nil,
162
- [:fcall, "puts", [:array, [:str, "hello"]]]]]]]
163
- @@multi_args = [:defn, "multi_args",
164
- [:scope,
165
- [:block,
166
- [:args, "arg1", "arg2"],
167
- [:lasgn, "arg3",
168
- [:call,
169
- [:call,
170
- [:lvar, "arg1"],
171
- "*",
172
- [:array, [:lvar, "arg2"]]],
173
- "*",
174
- [:array, [:lit, 7]]]],
175
- [:fcall, "puts", [:array, [:call, [:lvar, "arg3"], "to_s"]]],
176
- [:return,
177
- [:str, "foo"]]]]]
178
- @@bools = [:defn, "bools",
179
- [:scope,
180
- [:block,
181
- [:args, "arg1"],
182
- [:if,
183
- [:call,
184
- [:lvar, "arg1"], "nil?"],
185
- [:return,
186
- [:false]],
187
- [:return,
188
- [:true]]]]]]
189
- @@case_stmt = [:defn, "case_stmt",
190
- [:scope,
191
- [:block,
192
- [:args],
193
- [:lasgn, "var", [:lit, 2]],
194
- [:lasgn, "result", [:str, ""]],
195
- [:case,
196
- [:lvar, "var"],
197
- [:when,
198
- [:array, [:lit, 1]],
199
- [:block,
200
- [:fcall, "puts", [:array, [:str, "something"]]],
201
- [:lasgn, "result", [:str, "red"]]]],
202
- [:when,
203
- [:array, [:lit, 2], [:lit, 3]],
204
- [:lasgn, "result", [:str, "yellow"]]],
205
- [:when, [:array, [:lit, 4]], nil],
206
- [:lasgn, "result", [:str, "green"]]],
207
- [:case,
208
- [:lvar, "result"],
209
- [:when, [:array, [:str, "red"]], [:lasgn, "var", [:lit, 1]]],
210
- [:when, [:array, [:str, "yellow"]], [:lasgn, "var", [:lit, 2]]],
211
- [:when, [:array, [:str, "green"]], [:lasgn, "var", [:lit, 3]]],
212
- nil],
213
- [:return, [:lvar, "result"]]]]]
214
- @@eric_is_stubborn = [:defn,
215
- "eric_is_stubborn",
216
- [:scope,
217
- [:block,
218
- [:args],
219
- [:lasgn, "var", [:lit, 42]],
220
- [:lasgn, "var2", [:call, [:lvar, "var"], "to_s"]],
221
- [:call, [:gvar, "$stderr"], "fputs", [:array, [:lvar, "var2"]]],
222
- [:return, [:lvar, "var2"]]]]]
223
- @@interpolated = [:defn,
224
- "interpolated",
225
- [:scope,
226
- [:block,
227
- [:args],
228
- [:lasgn, "var", [:lit, 14]],
229
- [:lasgn, "var2", [:dstr, "var is ", [:lvar, "var"], [:str, ". So there."]]]]]]
230
- @@unknown_args = [:defn, "unknown_args",
231
- [:scope,
232
- [:block,
233
- [:args, "arg1", "arg2"],
234
- [:return, [:lvar, "arg1"]]]]]
235
- @@determine_args = [:defn, "determine_args",
236
- [:scope,
237
- [:block,
238
- [:args],
239
- [:call,
240
- [:lit, 5],
241
- "==",
242
- [:array,
243
- [:fcall,
244
- "unknown_args",
245
- [:array, [:lit, 4], [:str, "known"]]]]]]]]
246
-
247
- @@__all = []
248
-
249
- def setup
250
- @thing = ParseTree.new
251
- end
252
-
253
- Something.instance_methods(false).sort.each do |meth|
254
- if class_variables.include?("@@#{meth}") then
255
- @@__all << eval("@@#{meth}")
256
- eval "def test_#{meth}; assert_equal @@#{meth}, @thing.parse_tree(Something, :#{meth}); end"
257
- else
258
- eval "def test_#{meth}; flunk \"You haven't added @@#{meth} yet\"; end"
259
- end
260
- end
261
-
262
- def test_missing
263
- assert_equal(@@missing,
264
- @thing.parse_tree(Something, :missing),
265
- "Must return -3 for missing methods")
266
- end
267
-
268
- def ztest_class
269
- assert_equal(@@__all,
270
- @thing.parse_tree(Something),
271
- "Must return a lot of shit")
272
- end
273
-
274
- end
275
-