ParseTree 1.6.3 → 1.6.4
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 +8 -0
- data/Rakefile +1 -0
- data/lib/parse_tree.rb +5 -5
- data/test/pt_testcase.rb +88 -34
- data/test/test_parse_tree.rb +10 -10
- metadata +7 -7
data/History.txt
CHANGED
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ $: << "../../RubyInline/dev"
|
|
7
7
|
require './lib/parse_tree.rb'
|
8
8
|
|
9
9
|
Hoe.new("ParseTree", ParseTree::VERSION) do |p|
|
10
|
+
p.rubyforge_name = "parsetree"
|
10
11
|
p.summary = "Extract and enumerate ruby parse trees."
|
11
12
|
p.description = p.paragraphs_of("README.txt", 2).join("\n\n")
|
12
13
|
p.changes = p.paragraphs_of("History.txt", 1).join("\n\n")
|
data/lib/parse_tree.rb
CHANGED
@@ -25,7 +25,7 @@ require 'inline'
|
|
25
25
|
|
26
26
|
class ParseTree
|
27
27
|
|
28
|
-
VERSION = '1.6.
|
28
|
+
VERSION = '1.6.4'
|
29
29
|
|
30
30
|
##
|
31
31
|
# Front end translation method.
|
@@ -250,7 +250,7 @@ class ParseTree
|
|
250
250
|
|
251
251
|
builder.prefix %{
|
252
252
|
#define nd_3rd u3.node
|
253
|
-
static
|
253
|
+
static unsigned case_level = 0;
|
254
254
|
}
|
255
255
|
|
256
256
|
builder.prefix %{
|
@@ -378,7 +378,7 @@ again_no_block:
|
|
378
378
|
break;
|
379
379
|
|
380
380
|
case NODE_CASE:
|
381
|
-
|
381
|
+
case_level++;
|
382
382
|
if (node->nd_head != NULL) {
|
383
383
|
add_to_parse_tree(current, node->nd_head, newlines, locals); /* expr */
|
384
384
|
} else {
|
@@ -396,11 +396,11 @@ again_no_block:
|
|
396
396
|
rb_ary_push(current, Qnil); /* no else */
|
397
397
|
}
|
398
398
|
}
|
399
|
-
|
399
|
+
case_level--;
|
400
400
|
break;
|
401
401
|
|
402
402
|
case NODE_WHEN:
|
403
|
-
if (
|
403
|
+
if (!case_level) { /* when without case, ie, no expr in case */
|
404
404
|
rb_ary_pop(ary); /* reset what current is pointing at */
|
405
405
|
node = NEW_CASE(0, node);
|
406
406
|
goto again;
|
data/test/pt_testcase.rb
CHANGED
@@ -6,21 +6,19 @@ class Examples
|
|
6
6
|
attr_reader :reader
|
7
7
|
attr_writer :writer
|
8
8
|
|
9
|
-
def a_method;
|
9
|
+
def a_method(x); x+1; end
|
10
10
|
alias an_alias a_method
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
x + 1
|
15
|
-
end
|
12
|
+
define_method(:unsplatted) do |x|
|
13
|
+
x + 1
|
16
14
|
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
define_method :splatted do |*args|
|
17
|
+
y = args.first
|
18
|
+
y + 42
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
dmethod_maker if RUBY_VERSION < "1.9"
|
21
|
+
define_method :dmethod_added, instance_method(:a_method) if RUBY_VERSION < "1.9"
|
24
22
|
end
|
25
23
|
|
26
24
|
class ParseTreeTestCase < Test::Unit::TestCase
|
@@ -64,7 +62,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
64
62
|
"Ruby" => "class X\n alias :y :x\nend",
|
65
63
|
"ParseTree" => [:class, :X, nil,
|
66
64
|
[:scope, [:alias, [:lit, :y], [:lit, :x]]]],
|
67
|
-
"Ruby2Ruby" => "class X\n alias_method :y, :x\nend",
|
65
|
+
"Ruby2Ruby" => "class X\n alias_method :y, :x\nend",
|
68
66
|
},
|
69
67
|
|
70
68
|
"and" => {
|
@@ -132,23 +130,35 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
132
130
|
},
|
133
131
|
|
134
132
|
"bmethod" => {
|
135
|
-
"Ruby" => [Examples, :
|
133
|
+
"Ruby" => [Examples, :unsplatted],
|
136
134
|
"ParseTree" => [:defn,
|
137
|
-
:
|
135
|
+
:unsplatted,
|
138
136
|
[:bmethod,
|
139
137
|
[:dasgn_curr, :x],
|
140
138
|
[:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]],
|
141
|
-
"Ruby2Ruby" => "def
|
139
|
+
"Ruby2Ruby" => "def unsplatted(x)\n (x + 1)\nend"
|
140
|
+
},
|
141
|
+
|
142
|
+
"bmethod_splat" => {
|
143
|
+
"Ruby" => [Examples, :splatted],
|
144
|
+
"ParseTree" => [:defn, :splatted,
|
145
|
+
[:bmethod,
|
146
|
+
[:masgn, [:dasgn_curr, :args]],
|
147
|
+
[:block,
|
148
|
+
[:dasgn_curr, :y],
|
149
|
+
[:dasgn_curr, :y, [:call, [:dvar, :args], :first]],
|
150
|
+
[:call, [:dvar, :y], :+, [:array, [:lit, 42]]]]]],
|
151
|
+
"Ruby2Ruby" => "def splatted(*args)\n y = args.first\n (y + 42)\nend",
|
142
152
|
},
|
143
153
|
|
144
154
|
"break" => {
|
145
|
-
"Ruby" => "loop do\n if true
|
155
|
+
"Ruby" => "loop do\n break if true\nend",
|
146
156
|
"ParseTree" => [:iter,
|
147
157
|
[:fcall, :loop], nil, [:if, [:true], [:break], nil]],
|
148
158
|
},
|
149
159
|
|
150
160
|
"break_arg" => {
|
151
|
-
"Ruby" => "loop do\n if true
|
161
|
+
"Ruby" => "loop do\n break 42 if true\nend",
|
152
162
|
"ParseTree" => [:iter,
|
153
163
|
[:fcall, :loop], nil,
|
154
164
|
[:if, [:true], [:break, [:lit, 42]], nil]],
|
@@ -197,6 +207,33 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
197
207
|
nil]]
|
198
208
|
},
|
199
209
|
|
210
|
+
"case_nested" => {
|
211
|
+
"Ruby" => "var1 = 1\nvar2 = 2\nresult = nil\ncase var1\nwhen 1 then\n case var2\n when 1 then\n result = 1\n when 2 then\n result = 2\n else\n result = 3\n end\nwhen 2 then\n case var2\n when 1 then\n result = 4\n when 2 then\n result = 5\n else\n result = 6\n end\nelse\n result = 7\nend\n",
|
212
|
+
"ParseTree" => [:block,
|
213
|
+
[:lasgn, :var1, [:lit, 1]],
|
214
|
+
[:lasgn, :var2, [:lit, 2]],
|
215
|
+
[:lasgn, :result, [:nil]],
|
216
|
+
[:case,
|
217
|
+
[:lvar, :var1],
|
218
|
+
[:when, [:array, [:lit, 1]],
|
219
|
+
[:case,
|
220
|
+
[:lvar, :var2],
|
221
|
+
[:when, [:array, [:lit, 1]],
|
222
|
+
[:lasgn, :result, [:lit, 1]]],
|
223
|
+
[:when, [:array, [:lit, 2]],
|
224
|
+
[:lasgn, :result, [:lit, 2]]],
|
225
|
+
[:lasgn, :result, [:lit, 3]]]],
|
226
|
+
[:when, [:array, [:lit, 2]],
|
227
|
+
[:case,
|
228
|
+
[:lvar, :var2],
|
229
|
+
[:when, [:array, [:lit, 1]],
|
230
|
+
[:lasgn, :result, [:lit, 4]]],
|
231
|
+
[:when, [:array, [:lit, 2]],
|
232
|
+
[:lasgn, :result, [:lit, 5]]],
|
233
|
+
[:lasgn, :result, [:lit, 6]]]],
|
234
|
+
[:lasgn, :result, [:lit, 7]]]]
|
235
|
+
},
|
236
|
+
|
200
237
|
"case_no_expr" => { # TODO: nested
|
201
238
|
"Ruby" => "case\nwhen 1 then\n :a\nwhen 2 then\n :b\nelse\n :c\nend",
|
202
239
|
"ParseTree" => [:case, nil,
|
@@ -263,16 +300,16 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
263
300
|
"ParseTree" => [:colon3, :X],
|
264
301
|
},
|
265
302
|
|
266
|
-
"conditional1" => {
|
267
|
-
"Ruby" => "if (42 == 0)
|
303
|
+
"conditional1" => { # TODO: rename
|
304
|
+
"Ruby" => "return 1 if (42 == 0)",
|
268
305
|
"ParseTree" => [:if,
|
269
306
|
[:call, [:lit, 42], :==, [:array, [:lit, 0]]],
|
270
307
|
[:return, [:lit, 1]],
|
271
308
|
nil],
|
272
309
|
},
|
273
310
|
|
274
|
-
"conditional2" => {
|
275
|
-
"Ruby" => "unless (42 == 0)
|
311
|
+
"conditional2" => { # TODO: remove
|
312
|
+
"Ruby" => "return 2 unless (42 == 0)",
|
276
313
|
"ParseTree" => [:if,
|
277
314
|
[:call, [:lit, 42], :==, [:array, [:lit, 0]]],
|
278
315
|
nil,
|
@@ -299,7 +336,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
299
336
|
},
|
300
337
|
|
301
338
|
"conditional5" => {
|
302
|
-
"Ruby" => "
|
339
|
+
"Ruby" => "return if false unless true",
|
303
340
|
"ParseTree" => [:if, [:true], nil, [:if, [:false], [:return], nil]],
|
304
341
|
},
|
305
342
|
|
@@ -338,6 +375,18 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
338
375
|
[:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]]],
|
339
376
|
},
|
340
377
|
|
378
|
+
"dasgn_curr" => {
|
379
|
+
"Ruby" => "data.each do |x, y|\n a = 1\n b = a\n b = a = x\nend",
|
380
|
+
"ParseTree" => [:iter,
|
381
|
+
[:call, [:vcall, :data], :each],
|
382
|
+
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]],
|
383
|
+
[:block,
|
384
|
+
[:dasgn_curr, :a, [:dasgn_curr, :b]],
|
385
|
+
[:dasgn_curr, :a, [:lit, 1]],
|
386
|
+
[:dasgn_curr, :b, [:dvar, :a]],
|
387
|
+
[:dasgn_curr, :b, [:dasgn_curr, :a, [:dvar, :x]]]]],
|
388
|
+
},
|
389
|
+
|
341
390
|
"defined" => {
|
342
391
|
"Ruby" => "defined? $x",
|
343
392
|
"ParseTree" => [:defined, [:gvar, :$x]],
|
@@ -380,6 +429,15 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
380
429
|
"ParseTree" => [:defn, :|, [:scope, [:block, [:args, :o], [:nil]]]],
|
381
430
|
},
|
382
431
|
|
432
|
+
"defn_rescue" => {
|
433
|
+
"Ruby" => "def blah\n 42\n rescue\n 24\nend",
|
434
|
+
"ParseTree" => [:defn, :blah,
|
435
|
+
[:scope, [:block, [:args],
|
436
|
+
[:rescue,
|
437
|
+
[:lit, 42],
|
438
|
+
[:resbody, nil, [:lit, 24]]]]]],
|
439
|
+
},
|
440
|
+
|
383
441
|
"defn_zarray" => { # tests memory allocation for returns
|
384
442
|
"Ruby" => "def zarray\n a = []\n return a\nend",
|
385
443
|
"ParseTree" => [:defn, :zarray,
|
@@ -402,15 +460,11 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
402
460
|
"ParseTree" => [:defn,
|
403
461
|
:dmethod_added,
|
404
462
|
[:dmethod,
|
405
|
-
:
|
463
|
+
:a_method,
|
406
464
|
[:scope,
|
407
465
|
[:block,
|
408
|
-
[:args],
|
409
|
-
[:
|
410
|
-
[:fcall, :define_method,
|
411
|
-
[:array, [:lit, :bmethod_added]]],
|
412
|
-
[:dasgn_curr, :x],
|
413
|
-
[:call, [:dvar, :x], :+, [:array, [:lit, 1]]]]]]]],
|
466
|
+
[:args, :x],
|
467
|
+
[:call, [:lvar, :x], :+, [:array, [:lit, 1]]]]]]],
|
414
468
|
"Ruby2Ruby" => "def dmethod_added(x)\n (x + 1)\nend"
|
415
469
|
},
|
416
470
|
|
@@ -494,9 +548,9 @@ end",
|
|
494
548
|
[:fbody,
|
495
549
|
[:scope,
|
496
550
|
[:block,
|
497
|
-
[:args],
|
498
|
-
[:call, [:
|
499
|
-
"Ruby2Ruby" => "def an_alias\n (
|
551
|
+
[:args, :x],
|
552
|
+
[:call, [:lvar, :x], :+, [:array, [:lit, 1]]]]]]],
|
553
|
+
"Ruby2Ruby" => "def an_alias(x)\n (x + 1)\nend"
|
500
554
|
},
|
501
555
|
|
502
556
|
"fcall" => {
|
@@ -716,7 +770,7 @@ end",
|
|
716
770
|
[:array, [:vcall, :c], [:vcall, :d]]],
|
717
771
|
},
|
718
772
|
"match" => {
|
719
|
-
"Ruby" => "if /x/
|
773
|
+
"Ruby" => "1 if /x/",
|
720
774
|
"ParseTree" => [:if, [:match, [:lit, /x/]], [:lit, 1], nil],
|
721
775
|
},
|
722
776
|
|
@@ -738,7 +792,7 @@ end",
|
|
738
792
|
},
|
739
793
|
|
740
794
|
"next" => {
|
741
|
-
"Ruby" => "loop do\n if false
|
795
|
+
"Ruby" => "loop do\n next if false\nend",
|
742
796
|
"ParseTree" => [:iter,
|
743
797
|
[:fcall, :loop],
|
744
798
|
nil,
|
@@ -829,7 +883,7 @@ end",
|
|
829
883
|
},
|
830
884
|
|
831
885
|
"redo" => {
|
832
|
-
"Ruby" => "loop do\n if false
|
886
|
+
"Ruby" => "loop do\n redo if false\nend",
|
833
887
|
"ParseTree" => [:iter,
|
834
888
|
[:fcall, :loop], nil, [:if, [:false], [:redo], nil]],
|
835
889
|
},
|
data/test/test_parse_tree.rb
CHANGED
@@ -147,20 +147,20 @@ class TestParseTree < ParseTreeTestCase
|
|
147
147
|
:unknown_args,
|
148
148
|
[:array, [:lit, 4], [:str, "known"]]]]]]]]
|
149
149
|
|
150
|
-
|
150
|
+
|
151
151
|
@@attrasgn = [:defn,
|
152
152
|
:attrasgn,
|
153
153
|
[:scope,
|
154
154
|
[:block,
|
155
155
|
[:args],
|
156
156
|
[:attrasgn, [:lit, 42], :method=, [:array, [:vcall, :y]]],
|
157
|
-
[:attrasgn,
|
157
|
+
[:attrasgn,
|
158
158
|
[:self],
|
159
|
-
:type=,
|
159
|
+
:type=,
|
160
160
|
[:array, [:call, [:vcall, :other], :type]]]]]]
|
161
|
-
|
161
|
+
|
162
162
|
@@__all = [:class, :Something, [:const, :Object]]
|
163
|
-
|
163
|
+
|
164
164
|
Something.instance_methods(false).sort.each do |meth|
|
165
165
|
if class_variables.include?("@@#{meth}") then
|
166
166
|
@@__all << eval("@@#{meth}")
|
@@ -171,6 +171,7 @@ class TestParseTree < ParseTreeTestCase
|
|
171
171
|
end
|
172
172
|
|
173
173
|
Something.singleton_methods.sort.each do |meth|
|
174
|
+
next if meth =~ /yaml/ # rubygems introduced a bug
|
174
175
|
if class_variables.include?("@@self_#{meth}") then
|
175
176
|
@@__all << eval("@@self_#{meth}")
|
176
177
|
eval "def test_self_#{meth}; assert_equal @@self_#{meth}, @processor.parse_tree_for_method(Something, :#{meth}, true); end"
|
@@ -181,14 +182,13 @@ class TestParseTree < ParseTreeTestCase
|
|
181
182
|
|
182
183
|
def test_missing
|
183
184
|
assert_equal(@@missing,
|
184
|
-
|
185
|
-
|
185
|
+
@processor.parse_tree_for_method(Something, :missing),
|
186
|
+
"Must return -3 for missing methods")
|
186
187
|
end
|
187
188
|
|
188
189
|
def test_whole_class
|
189
190
|
assert_equal([@@__all],
|
190
|
-
|
191
|
-
|
191
|
+
@processor.parse_tree(Something),
|
192
|
+
"Must return a lot of shit")
|
192
193
|
end
|
193
194
|
end
|
194
|
-
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
2
|
+
rubygems_version: 0.9.0.9
|
3
3
|
specification_version: 1
|
4
4
|
name: ParseTree
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.6.
|
7
|
-
date:
|
6
|
+
version: 1.6.4
|
7
|
+
date: 2007-01-15 00:00:00 -08:00
|
8
8
|
summary: Extract and enumerate ruby parse trees.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -69,20 +69,20 @@ requirements: []
|
|
69
69
|
|
70
70
|
dependencies:
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
72
|
+
name: RubyInline
|
73
73
|
version_requirement:
|
74
74
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 3.2.0
|
79
79
|
version:
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
|
-
name:
|
81
|
+
name: hoe
|
82
82
|
version_requirement:
|
83
83
|
version_requirements: !ruby/object:Gem::Version::Requirement
|
84
84
|
requirements:
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
version: 1.1.7
|
88
88
|
version:
|