ParseTree 1.7.0 → 1.7.1
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 +217 -202
- data/lib/parse_tree.rb +54 -10
- data/test/pt_testcase.rb +42 -12
- data/test/test_parse_tree.rb +22 -0
- metadata +11 -8
data/History.txt
CHANGED
@@ -1,202 +1,217 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
1
|
+
=== 1.7.1 / 2007-06-05
|
2
|
+
|
3
|
+
* 3 minor enhancements:
|
4
|
+
* Added begin/rescue/ensure test.
|
5
|
+
* Added block_pass_args_and_splat.
|
6
|
+
* Allow methods to be pulled from unparsed files.
|
7
|
+
* 1 bug fix:
|
8
|
+
* Compatibility fixed across 1.8.
|
9
|
+
|
10
|
+
=== 1.7.0 / 2007-02-13
|
11
|
+
|
12
|
+
* 2 major enhancements:
|
13
|
+
* rewrite extracted and intended to be run before (or in front of) process.
|
14
|
+
* rewrite is now recursive as well, so children rewritings should be
|
15
|
+
done independently of their parents. This should make complex
|
16
|
+
rewriting layers much cleaner and allow me to eventually collect
|
17
|
+
and publish a single "standard" rewriting layer.
|
18
|
+
* 1 minor enhancement:
|
19
|
+
* Iters are now {} if short and one line. YAY!
|
20
|
+
* 1 bug fix:
|
21
|
+
* Added test cases brought out by ruby2ruby/heckle.
|
22
|
+
|
23
|
+
=== 1.6.4 / 2007-01-15
|
24
|
+
|
25
|
+
* 1 minor enhancement:
|
26
|
+
* Switched short if/unless to 1 line expressions.
|
27
|
+
* 2 bug fixes:
|
28
|
+
* Fixed the nested case/when bug. YAY!
|
29
|
+
* Added dasgn_curr and defn_rescue test cases.
|
30
|
+
|
31
|
+
=== 1.6.3 / 2006-12-20
|
32
|
+
|
33
|
+
* 1 bug fix:
|
34
|
+
* ParseTree::translate was trying to translate inherited class methods.
|
35
|
+
|
36
|
+
=== 1.6.2 / 2006-12-19
|
37
|
+
|
38
|
+
* 2 minor enhancements:
|
39
|
+
* ParseTree::translate can now take :"self.method".
|
40
|
+
* Improved PT tests for [], []=
|
41
|
+
* 1 bug fixes:
|
42
|
+
* Fixed a bug in ParseTree where cases w/o exprs were malformed.
|
43
|
+
|
44
|
+
=== 1.6.1 / 2006-11-11
|
45
|
+
|
46
|
+
* 2 minor enhancements:
|
47
|
+
* Have been going insane on the tests, expect more soon.
|
48
|
+
* Cleaned up using named nodes, now do: args = exp.scope.block.args(:delete).
|
49
|
+
* 2 bug fixes:
|
50
|
+
* Fixed #parse_tree to return superclass in :const node.
|
51
|
+
* Fixed while/until with no bodies (now nil).
|
52
|
+
|
53
|
+
=== 1.6.0 / 2006-10-11
|
54
|
+
|
55
|
+
* 2 major enhancements:
|
56
|
+
* PTTC just got a major enema. 2k lines o' diff.
|
57
|
+
* All in all, removed 829 lines of code and made it a lot more solid.
|
58
|
+
* 6 minor enhancements:
|
59
|
+
* Added sort rake task.
|
60
|
+
* Added a basic front-end method to ParseTree: translate, takes
|
61
|
+
string or Class and optional method name.
|
62
|
+
* Class now has nil for unspecified superclass. No way to tell if it
|
63
|
+
is being reopened.
|
64
|
+
* SexpProcessor's unsupported array now defaults to all the internal nodes.
|
65
|
+
* Added Unique from ruby2c project.
|
66
|
+
* something.rb got slimmed down to near nothing. About to be retired.
|
67
|
+
* 3 bug fixes:
|
68
|
+
* Added changeset to Hoe spec.
|
69
|
+
* Fixed up description to use paragraphs_of.
|
70
|
+
* Fixed op_asgn1, alias, undef, dsym, match.
|
71
|
+
|
72
|
+
=== 1.5.0 / 2006-09-24
|
73
|
+
|
74
|
+
* 5 minor enhancements:
|
75
|
+
* Added parse_tree_audit.
|
76
|
+
* Added reporting of unsupported nodes that have processors.
|
77
|
+
* YAY! class method support! generated as :"self.blah"
|
78
|
+
* Add parse_tree_for_string.
|
79
|
+
* Converted Rakefile+gemspec to Hoe-based Rakefile.
|
80
|
+
* 6 bug fixes:
|
81
|
+
* Did some preliminary work on 1.9 compatibility.
|
82
|
+
* Fixed tests for some changes/clarifications.
|
83
|
+
* Fixed resbody: should have nil exceptions list when no exception rescued.
|
84
|
+
* Fixed op_asgn1 and op_asgn2.
|
85
|
+
* Fixed incompatibility with new inline changes.
|
86
|
+
* Fixed VALUE decl in parse_tree.rb
|
87
|
+
|
88
|
+
=== 1.4.1 / 2006-04-10
|
89
|
+
|
90
|
+
* 4 minor enhancements:
|
91
|
+
* parse_tree_show -f output is much cleaner now.
|
92
|
+
* ParseTree does a much more elegant job of handling different versions.
|
93
|
+
* ParseTree now has all node names in ParseTree::NODE_NAMES.
|
94
|
+
* ParseTree now raises exceptions instead of freakin'.
|
95
|
+
* 3 bug fixes:
|
96
|
+
* Used multiruby to test against 1.8.2-4, 1.8 cvs, and 1.9 cvs.
|
97
|
+
* Fixed incompatibilites introduced in ruby 1.8.4.
|
98
|
+
* Fixed some incompatibilites introduced in ruby 1.9.x.
|
99
|
+
|
100
|
+
=== 1.4.0 / 2005-10-15
|
101
|
+
|
102
|
+
* 5 minor enhancements
|
103
|
+
* Improved Makefile's install rule, uninstall, and added FILTER to all.
|
104
|
+
* Fixed minor issues w/ Makefile.
|
105
|
+
* Added -I=loadpath to parse_tree_abc.
|
106
|
+
* Added *args support for methods.
|
107
|
+
* Split out sexp to its own file.
|
108
|
+
* 2 bug fixes
|
109
|
+
* Fixed weird bug in parse_tree_deps where sort was failing on deps.
|
110
|
+
* ! Fixed fatal bug in parse_tree.rb caused by safe_level fix in ruby 1.8.3.
|
111
|
+
|
112
|
+
=== 1.3.8 / 2005-09-27
|
113
|
+
|
114
|
+
* 1 bug fix:
|
115
|
+
* Our private version of struct METHOD went out of sync w/ latest ruby.
|
116
|
+
* Only use this if you are on 1.8.3+.
|
117
|
+
|
118
|
+
=== 1.3.7 / 2005-07-13
|
119
|
+
|
120
|
+
* 3 bug fixes:
|
121
|
+
* Fixed rubygem requires for non-gem systems.
|
122
|
+
* Renamed on to on_error_in to make more clear.
|
123
|
+
* Moved exceptions to their own tree to make catching cleaner.
|
124
|
+
|
125
|
+
=== 1.3.6 / 2005-05-19
|
126
|
+
|
127
|
+
* 2 minor enhancements:
|
128
|
+
* Improved debugging capability when $DEBUG.
|
129
|
+
* Allowed for selective debugging output by node type.
|
130
|
+
* 3 bug fixes:
|
131
|
+
* Minor fixes to Makefile and parse_tree_show.
|
132
|
+
* Improved error messages in parse_tree when newlines are included.
|
133
|
+
* Improved method coverage for parse_tree.
|
134
|
+
|
135
|
+
=== 1.3.5 / 2005-04-19
|
136
|
+
|
137
|
+
* 2 minor enhancement
|
138
|
+
* Added dynamic exception handling on a per node-type basis (BIG).
|
139
|
+
* Added -c=classname to parse_tree_show to help w/ core classes.
|
140
|
+
* 1 bug fix
|
141
|
+
* Fixed dependency specification error in gemspec.
|
142
|
+
|
143
|
+
=== 1.3.4 / 2005-02-09
|
144
|
+
|
145
|
+
* 2 bug fixes
|
146
|
+
* bug:1459: Cleaned up and corrected superclass naming code.
|
147
|
+
* bug:1458: Fixed while to support post-conditional while/until nodes.
|
148
|
+
|
149
|
+
=== 1.3.3 / 2005-02-01
|
150
|
+
|
151
|
+
* 3 minor enhancement
|
152
|
+
* Cleaned up parse_tree_abc output
|
153
|
+
* Patched up null class names (delegate classes are weird!)
|
154
|
+
* Added UnknownNodeError and switched SyntaxError over to it.
|
155
|
+
* 2 bug fixes
|
156
|
+
* Fixed BEGIN node handling to recurse instead of going flat.
|
157
|
+
* FINALLY fixed the weird compiler errors seen on some versions of
|
158
|
+
gcc 3.4.x related to type punned pointers.
|
159
|
+
|
160
|
+
=== 1.3.2 / 2005-01-04
|
161
|
+
|
162
|
+
* 1 minor enhancement
|
163
|
+
* Added total line to end of ABC metric report.
|
164
|
+
* 1 bug fix
|
165
|
+
* Updates for ruby 1.8.2 parse tree changes.
|
166
|
+
|
167
|
+
=== 1.3.1 / 2004-12-09
|
168
|
+
|
169
|
+
* 1 minor enhancement
|
170
|
+
* Added rewrite_<type> processing.
|
171
|
+
* 2 bug fixes
|
172
|
+
* Renamed SexpProcessor's #exclude to #unsupported.
|
173
|
+
* Fixed a bus error when an attrasgn uses self.
|
174
|
+
* Added support for cfunc now that we found a repro.
|
175
|
+
|
176
|
+
=== 1.3.0 / 2004-12-06
|
177
|
+
|
178
|
+
* 3 minor enhancements
|
179
|
+
* Finished supporting pretty much all nodes (that we can figger out).
|
180
|
+
* If $DEBUG, or true passed to new, then we now output the :newline nodes.
|
181
|
+
* We output much better extra debugging info if $DEBUG.
|
182
|
+
* 1 bug fixes
|
183
|
+
* Fixed README for new output style.
|
184
|
+
|
185
|
+
=== 1.2.0 / 2004-11-29
|
186
|
+
|
187
|
+
* 9 minor enhancements
|
188
|
+
* ParseTree now returns symbols for all data except in :str and :lit.
|
189
|
+
* This WILL break existing code! (as if any exists)
|
190
|
+
* ParseTree.parse_tree now takes a list of classes, no optional method.
|
191
|
+
* ParseTree.parse_tree_for_method(klass, method) added.
|
192
|
+
* ParseTree.parse_tree now returns a list of :class/:module nodes.
|
193
|
+
* Added -f to parse_tree_show for uber fast demos.
|
194
|
+
* Added -q to parse_tree_show to NOT use pp so it is mucho faster.
|
195
|
+
* running with $DEBUG will trace the methods and nodes as processed.
|
196
|
+
* Added rdoc to everything.
|
197
|
+
* Gemified
|
198
|
+
* 4 bug fixes
|
199
|
+
* Bus error in iter/for nodes where arg list is empty now fixed.
|
200
|
+
* Bus error when handling 'def method(*)' is now fixed.
|
201
|
+
* Unnamed classes and superclasses (ugh) are now handled.
|
202
|
+
* parse_tree_abc now enumerates actual types rather than every token.
|
203
|
+
|
204
|
+
=== 1.1.0 / 2004-11-12
|
205
|
+
|
206
|
+
* 2 minor enhancement
|
207
|
+
* Added SexpProcessor and CompositeSexpProcessor
|
208
|
+
* Allowed show.rb to read from standard input.
|
209
|
+
* 3 bug fixes
|
210
|
+
* Fixed makefile issues for BSD's make - so dumb.
|
211
|
+
* Added super as a call in abc.rb's metrics
|
212
|
+
* Commented out a compiler flag to work with GCC 2.95.
|
213
|
+
|
214
|
+
=== 1.0.0 / 2004-11-06
|
215
|
+
|
216
|
+
* 1 major enhancement
|
217
|
+
* Birthday!
|
data/lib/parse_tree.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
#!/usr/local/bin/ruby -w
|
2
2
|
|
3
|
+
abort "*** Sorry, ParseTree doesn't work with ruby #{RUBY_VERSION}" if
|
4
|
+
RUBY_VERSION >= "1.9"
|
5
|
+
|
3
6
|
begin require 'rubygems'; rescue LoadError; end
|
4
7
|
|
5
8
|
require 'inline'
|
@@ -25,7 +28,7 @@ require 'inline'
|
|
25
28
|
|
26
29
|
class ParseTree
|
27
30
|
|
28
|
-
VERSION = '1.7.
|
31
|
+
VERSION = '1.7.1'
|
29
32
|
|
30
33
|
##
|
31
34
|
# Front end translation method.
|
@@ -33,8 +36,16 @@ class ParseTree
|
|
33
36
|
def self.translate(klass_or_str, method=nil)
|
34
37
|
pt = self.new(false)
|
35
38
|
case klass_or_str
|
36
|
-
when String
|
37
|
-
pt.parse_tree_for_string(klass_or_str).first
|
39
|
+
when String then
|
40
|
+
sexp = pt.parse_tree_for_string(klass_or_str).first
|
41
|
+
if method then
|
42
|
+
# class, scope, block, *methods
|
43
|
+
sexp.last.last[1..-1].find do |defn|
|
44
|
+
defn[1] == method
|
45
|
+
end
|
46
|
+
else
|
47
|
+
sexp
|
48
|
+
end
|
38
49
|
else
|
39
50
|
unless method.nil? then
|
40
51
|
if method.to_s =~ /^self\./ then
|
@@ -253,6 +264,15 @@ class ParseTree
|
|
253
264
|
static unsigned case_level = 0;
|
254
265
|
}
|
255
266
|
|
267
|
+
builder.prefix %{
|
268
|
+
static VALUE wrap_into_node(const char * name, VALUE val) {
|
269
|
+
VALUE n = rb_ary_new();
|
270
|
+
rb_ary_push(n, ID2SYM(rb_intern(name)));
|
271
|
+
rb_ary_push(n, val);
|
272
|
+
return n;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
256
276
|
builder.prefix %{
|
257
277
|
struct METHOD {
|
258
278
|
VALUE klass, rklass;
|
@@ -299,7 +319,7 @@ static void add_to_parse_tree(VALUE ary,
|
|
299
319
|
static VALUE node_names = Qnil;
|
300
320
|
|
301
321
|
if (NIL_P(node_names)) {
|
302
|
-
node_names = rb_const_get_at(
|
322
|
+
node_names = rb_const_get_at(rb_path2class("ParseTree"),rb_intern("NODE_NAMES"));
|
303
323
|
}
|
304
324
|
|
305
325
|
if (!node) return;
|
@@ -334,10 +354,14 @@ again_no_block:
|
|
334
354
|
}
|
335
355
|
contnode = node->nd_next;
|
336
356
|
|
337
|
-
//
|
357
|
+
// FIX: this will break the moment there is a block w/in a block
|
338
358
|
old_ary = ary;
|
339
359
|
ary = current;
|
340
360
|
node = node->nd_head;
|
361
|
+
if (nd_type(node) == NODE_DASGN_CURR
|
362
|
+
&& (!node->nd_value || nd_type(node->nd_value) == NODE_DASGN_CURR)) {
|
363
|
+
goto finish;
|
364
|
+
}
|
341
365
|
goto again;
|
342
366
|
break;
|
343
367
|
|
@@ -548,7 +572,13 @@ again_no_block:
|
|
548
572
|
|
549
573
|
case NODE_OP_ASGN1:
|
550
574
|
add_to_parse_tree(current, node->nd_recv, newlines, locals);
|
575
|
+
#{if_version :>, "1.8.4", "#if 0"}
|
576
|
+
#{if_version :<=, "1.8.4", "#if 1"}
|
577
|
+
add_to_parse_tree(current, node->nd_args->nd_next, newlines, locals);
|
578
|
+
rb_ary_pop(rb_ary_entry(current, -1)); // no idea why I need this
|
579
|
+
#else
|
551
580
|
add_to_parse_tree(current, node->nd_args->nd_2nd, newlines, locals);
|
581
|
+
#endif
|
552
582
|
switch (node->nd_mid) {
|
553
583
|
case 0:
|
554
584
|
rb_ary_push(current, ID2SYM(rb_intern("||")));
|
@@ -609,16 +639,33 @@ again_no_block:
|
|
609
639
|
break;
|
610
640
|
|
611
641
|
case NODE_VALIAS: // u1 u2 (alias $global $global2)
|
642
|
+
#{if_version :>, "1.8.4", "#if 0"}
|
643
|
+
#{if_version :<=, "1.8.4", "#if 1"}
|
644
|
+
rb_ary_push(current, ID2SYM(node->u2.id));
|
645
|
+
rb_ary_push(current, ID2SYM(node->u1.id));
|
646
|
+
#else
|
612
647
|
rb_ary_push(current, ID2SYM(node->u1.id));
|
613
648
|
rb_ary_push(current, ID2SYM(node->u2.id));
|
649
|
+
#endif
|
614
650
|
break;
|
615
651
|
case NODE_ALIAS: // u1 u2 (alias :blah :blah2)
|
652
|
+
#{if_version :>, "1.8.4", "#if 0"}
|
653
|
+
#{if_version :<=, "1.8.4", "#if 1"}
|
654
|
+
rb_ary_push(current, wrap_into_node("lit", ID2SYM(node->u2.id)));
|
655
|
+
rb_ary_push(current, wrap_into_node("lit", ID2SYM(node->u1.id)));
|
656
|
+
#else
|
616
657
|
add_to_parse_tree(current, node->nd_1st, newlines, locals);
|
617
658
|
add_to_parse_tree(current, node->nd_2nd, newlines, locals);
|
659
|
+
#endif
|
618
660
|
break;
|
619
661
|
|
620
662
|
case NODE_UNDEF: // u2 (undef name, ...)
|
663
|
+
#{if_version :>, "1.8.4", "#if 0"}
|
664
|
+
#{if_version :<=, "1.8.4", "#if 1"}
|
665
|
+
rb_ary_push(current, wrap_into_node("lit", ID2SYM(node->u2.id)));
|
666
|
+
#else
|
621
667
|
add_to_parse_tree(current, node->nd_value, newlines, locals);
|
668
|
+
#endif
|
622
669
|
break;
|
623
670
|
|
624
671
|
case NODE_COLON3: // u2 (::OUTER_CONST)
|
@@ -765,10 +812,7 @@ again_no_block:
|
|
765
812
|
|
766
813
|
case NODE_MATCH: // u1 -> [:lit, u1]
|
767
814
|
{
|
768
|
-
|
769
|
-
rb_ary_push(n, ID2SYM(rb_intern("lit")));
|
770
|
-
rb_ary_push(n, node->nd_lit);
|
771
|
-
rb_ary_push(current, n);
|
815
|
+
rb_ary_push(current, wrap_into_node("lit", node->nd_lit));
|
772
816
|
}
|
773
817
|
break;
|
774
818
|
|
@@ -866,7 +910,7 @@ again_no_block:
|
|
866
910
|
break;
|
867
911
|
}
|
868
912
|
|
869
|
-
|
913
|
+
finish:
|
870
914
|
if (contnode) {
|
871
915
|
node = contnode;
|
872
916
|
contnode = NULL;
|
data/test/pt_testcase.rb
CHANGED
@@ -124,6 +124,15 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
124
124
|
"ParseTree" => [:begin, [:call, [:lit, 1], :+, [:array, [:lit, 1]]]],
|
125
125
|
},
|
126
126
|
|
127
|
+
"begin_rescue_ensure" => {
|
128
|
+
"Ruby" => "begin\n rescue\n # do nothing\n ensure\n nil\nend",
|
129
|
+
"ParseTree" => [:begin,
|
130
|
+
[:ensure,
|
131
|
+
[:rescue,
|
132
|
+
[:resbody, nil]],
|
133
|
+
[:nil]]]
|
134
|
+
},
|
135
|
+
|
127
136
|
"block_pass" => {
|
128
137
|
"Ruby" => "a(&b)",
|
129
138
|
"ParseTree" => [:block_pass, [:vcall, :b], [:fcall, :a]],
|
@@ -152,6 +161,19 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
152
161
|
[:fcall, :other, [:splat, [:lvar, :args]]]]]]],
|
153
162
|
},
|
154
163
|
|
164
|
+
"block_pass_args_and_splat" => {
|
165
|
+
"Ruby" => "def blah(*args, &block)\n other(42, *args, &block)\nend",
|
166
|
+
"ParseTree" => [:defn, :blah,
|
167
|
+
[:scope,
|
168
|
+
[:block,
|
169
|
+
[:args, "*args".intern],
|
170
|
+
[:block_arg, :block],
|
171
|
+
[:block_pass,
|
172
|
+
[:lvar, :block],
|
173
|
+
[:fcall, :other,
|
174
|
+
[:argscat, [:array, [:lit, 42]], [:lvar, :args]]]]]]],
|
175
|
+
},
|
176
|
+
|
155
177
|
"bmethod" => {
|
156
178
|
"Ruby" => [Examples, :unsplatted],
|
157
179
|
"ParseTree" => [:defn,
|
@@ -168,7 +190,6 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
168
190
|
[:bmethod,
|
169
191
|
[:masgn, [:dasgn_curr, :args]],
|
170
192
|
[:block,
|
171
|
-
[:dasgn_curr, :y],
|
172
193
|
[:dasgn_curr, :y, [:call, [:dvar, :args], :first]],
|
173
194
|
[:call, [:dvar, :y], :+, [:array, [:lit, 42]]]]]],
|
174
195
|
"Ruby2Ruby" => "def splatted(*args)\n y = args.first\n (y + 42)\nend",
|
@@ -404,7 +425,6 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
404
425
|
[:call, [:vcall, :data], :each],
|
405
426
|
[:masgn, [:array, [:dasgn_curr, :x], [:dasgn_curr, :y]]],
|
406
427
|
[:block,
|
407
|
-
[:dasgn_curr, :a, [:dasgn_curr, :b]],
|
408
428
|
[:dasgn_curr, :a, [:lit, 1]],
|
409
429
|
[:dasgn_curr, :b, [:dvar, :a]],
|
410
430
|
[:dasgn_curr, :b, [:dasgn_curr, :a, [:dvar, :x]]]]],
|
@@ -453,12 +473,17 @@ class ParseTreeTestCase < Test::Unit::TestCase
|
|
453
473
|
},
|
454
474
|
|
455
475
|
"defn_rescue" => {
|
456
|
-
"Ruby" => "def
|
457
|
-
"ParseTree" => [:defn, :
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
476
|
+
"Ruby" => "def eql?(resource)\n (self.uuid == resource.uuid) rescue false\nend",
|
477
|
+
"ParseTree" => [:defn, :eql?,
|
478
|
+
[:scope,
|
479
|
+
[:block,
|
480
|
+
[:args, :resource],
|
481
|
+
[:rescue,
|
482
|
+
[:call,
|
483
|
+
[:call, [:self], :uuid],
|
484
|
+
:==,
|
485
|
+
[:array, [:call, [:lvar, :resource], :uuid]]],
|
486
|
+
[:resbody, nil, [:false]]]]]],
|
462
487
|
},
|
463
488
|
|
464
489
|
"defn_zarray" => { # tests memory allocation for returns
|
@@ -936,17 +961,20 @@ end",
|
|
936
961
|
},
|
937
962
|
|
938
963
|
"rescue_block_body" => {
|
939
|
-
"Ruby" => "begin\n blah\nrescue\n
|
940
|
-
"ParseTree" => [:begin,
|
964
|
+
"Ruby" => "begin\n blah\nrescue\n 42\nend",
|
965
|
+
"ParseTree" => [:begin,
|
966
|
+
[:rescue,
|
967
|
+
[:vcall, :blah],
|
968
|
+
[:resbody, nil, [:lit, 42]]]],
|
941
969
|
},
|
942
970
|
|
943
971
|
"rescue_block_nada" => {
|
944
|
-
"Ruby" => "begin\n blah\nrescue\n # do nothing\nend
|
972
|
+
"Ruby" => "begin\n blah\nrescue\n # do nothing\nend",
|
945
973
|
"ParseTree" => [:begin, [:rescue, [:vcall, :blah], [:resbody, nil]]]
|
946
974
|
},
|
947
975
|
|
948
976
|
"rescue_exceptions" => {
|
949
|
-
"Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend
|
977
|
+
"Ruby" => "begin\n blah\nrescue RuntimeError => r\n # do nothing\nend",
|
950
978
|
"ParseTree" => [:begin,
|
951
979
|
[:rescue,
|
952
980
|
[:vcall, :blah],
|
@@ -1178,7 +1206,9 @@ end",
|
|
1178
1206
|
_, input, extra_input = *input if Array === input and input.first == :defx
|
1179
1207
|
|
1180
1208
|
debug = input.deep_clone
|
1209
|
+
$-w = nil if node == "match"
|
1181
1210
|
assert_equal expected, processor.process(input), "failed on input: #{debug.inspect}"
|
1211
|
+
$-w = true if node == "match"
|
1182
1212
|
extra_input.each do |input| processor.process(input) end
|
1183
1213
|
extra = processor.extra_methods rescue []
|
1184
1214
|
assert_equal extra_expected, extra
|
data/test/test_parse_tree.rb
CHANGED
@@ -45,6 +45,28 @@ class TestParseTree < ParseTreeTestCase
|
|
45
45
|
assert_equal expected, tree
|
46
46
|
end
|
47
47
|
|
48
|
+
def test_class_translate_string
|
49
|
+
str = "class A; def a; end; end"
|
50
|
+
|
51
|
+
sexp = ParseTree.translate str
|
52
|
+
|
53
|
+
expected = [:class, :A, nil,
|
54
|
+
[:scope,
|
55
|
+
[:defn, :a, [:scope, [:block, [:args], [:nil]]]]]]
|
56
|
+
|
57
|
+
assert_equal expected, sexp
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_class_translate_string_method
|
61
|
+
str = "class A; def a; end; def b; end; end"
|
62
|
+
|
63
|
+
sexp = ParseTree.translate str, :a
|
64
|
+
|
65
|
+
expected = [:defn, :a, [:scope, [:block, [:args], [:nil]]]]
|
66
|
+
|
67
|
+
assert_equal expected, sexp
|
68
|
+
end
|
69
|
+
|
48
70
|
def test_parse_tree_for_string
|
49
71
|
actual = @processor.parse_tree_for_string '1 + nil', '(string)', 1, false
|
50
72
|
expected = [[:call, [:lit, 1], :+, [:array, [:nil]]]]
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: ParseTree
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.7.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.7.1
|
7
|
+
date: 2007-06-05 00:00:00 -07:00
|
8
8
|
summary: Extract and enumerate ruby parse trees.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -54,10 +54,13 @@ files:
|
|
54
54
|
- validate.sh
|
55
55
|
test_files:
|
56
56
|
- test/test_all.rb
|
57
|
-
rdoc_options:
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
rdoc_options:
|
58
|
+
- --main
|
59
|
+
- README.txt
|
60
|
+
extra_rdoc_files:
|
61
|
+
- History.txt
|
62
|
+
- Manifest.txt
|
63
|
+
- README.txt
|
61
64
|
executables:
|
62
65
|
- parse_tree_abc
|
63
66
|
- parse_tree_audit
|
@@ -84,5 +87,5 @@ dependencies:
|
|
84
87
|
requirements:
|
85
88
|
- - ">="
|
86
89
|
- !ruby/object:Gem::Version
|
87
|
-
version: 1.2.
|
90
|
+
version: 1.2.1
|
88
91
|
version:
|