ParseTree 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,12 @@
1
+ === 3.0.3 / 2009-01-20
2
+
3
+ * 4 bug fixes:
4
+
5
+ * Added gauntlet_parsetree.rb. Bug finding/fixing much faster & easier now.
6
+ * Fixed alias tests for r2r. Added masgn and heredoc tests.
7
+ * Fixed conflicting flags (-u vs -r).
8
+ * Unwrap RHS from array IF it is only a splat node.
9
+
1
10
  === 3.0.2 / 2008-11-04
2
11
 
3
12
  * 1 minor enhancement:
data/Manifest.txt CHANGED
@@ -8,6 +8,7 @@ bin/parse_tree_audit
8
8
  bin/parse_tree_deps
9
9
  bin/parse_tree_show
10
10
  demo/printer.rb
11
+ lib/gauntlet_parsetree.rb
11
12
  lib/parse_tree.rb
12
13
  lib/parse_tree_extensions.rb
13
14
  lib/unified_ruby.rb
data/bin/parse_tree_show CHANGED
@@ -13,7 +13,7 @@ $s ||= false
13
13
  $U ||= false
14
14
  $n = $n.intern if $n
15
15
 
16
- $u ||= ! $U
16
+ $u ||= ! ($U || $r)
17
17
 
18
18
  if $h then
19
19
  puts "usage: #{File.basename $0} [options] [file...]"
@@ -0,0 +1,121 @@
1
+ #!/usr/bin/ruby -ws
2
+
3
+ $f ||= false
4
+
5
+ $:.unshift "../../ruby_parser/dev/lib"
6
+ $:.unshift "../../ParseTree/dev/lib"
7
+
8
+ require 'rubygems'
9
+ require 'parse_tree'
10
+ require 'ruby_parser'
11
+
12
+ require 'gauntlet'
13
+
14
+ class ParseTreeGauntlet < Gauntlet
15
+ def initialize
16
+ super
17
+
18
+ self.data = Hash.new { |h,k| h[k] = {} }
19
+ old_data = load_yaml data_file
20
+ self.data.merge! old_data
21
+ end
22
+
23
+ def should_skip? name
24
+ if $f then
25
+ if Hash === data[name] then
26
+ ! data[name].empty?
27
+ else
28
+ data[name]
29
+ end
30
+ else
31
+ data[name] == true # yes, == true on purpose
32
+ end
33
+ end
34
+
35
+ def diff_pp o1, o2
36
+ require 'pp'
37
+
38
+ File.open("/tmp/a.#{$$}", "w") do |f|
39
+ PP.pp o1, f
40
+ end
41
+
42
+ File.open("/tmp/b.#{$$}", "w") do |f|
43
+ PP.pp o2, f
44
+ end
45
+
46
+ `diff -u /tmp/a.#{$$} /tmp/b.#{$$}`
47
+ ensure
48
+ File.unlink "/tmp/a.#{$$}" rescue nil
49
+ File.unlink "/tmp/b.#{$$}" rescue nil
50
+ end
51
+
52
+ def broke name, file, msg
53
+ warn "bad"
54
+ self.data[name][file] = msg
55
+ self.dirty = true
56
+ end
57
+
58
+ def process path, name
59
+ begin
60
+ $stderr.print " #{path}: "
61
+ rp = RubyParser.new
62
+ pt = ParseTree.new
63
+
64
+ old_ruby = File.read(path)
65
+
66
+ begin
67
+ pt_sexp = pt.process old_ruby
68
+ rescue SyntaxError => e
69
+ warn "unparsable pt"
70
+ self.data[name][path] = :unparsable_pt
71
+ self.dirty = true
72
+ return
73
+ end
74
+
75
+ begin
76
+ rp_sexp = rp.process old_ruby
77
+ rescue Racc::ParseError => e
78
+ broke name, path, e.message
79
+ return
80
+ end
81
+
82
+ if rp_sexp != pt_sexp then
83
+ broke name, path, diff_pp(rp_sexp, pt_sexp)
84
+ return
85
+ end
86
+
87
+ self.data[name][path] = true
88
+ self.dirty = true
89
+
90
+ warn "good"
91
+ rescue Interrupt
92
+ puts "User cancelled"
93
+ exit 1
94
+ rescue Exception => e
95
+ broke name, path, " UNKNOWN ERROR: #{e}: #{e.message.strip}"
96
+ end
97
+ end
98
+
99
+ def run name
100
+ warn name
101
+ Dir["**/*.rb"].sort.each do |path|
102
+ next if path =~ /gemspec.rb/ # HACK
103
+ result = data[name][path]
104
+ next if result == true || Symbol === result
105
+ process path, name
106
+ end
107
+
108
+ if (self.data[name].empty? or
109
+ self.data[name].values.all? { |v| v == true }) then
110
+ warn " ALL GOOD!"
111
+ self.data[name] = true
112
+ self.dirty = true
113
+ end
114
+ end
115
+ end
116
+
117
+ filter = ARGV.shift
118
+ filter = Regexp.new filter if filter
119
+
120
+ gauntlet = ParseTreeGauntlet.new
121
+ gauntlet.run_the_gauntlet filter
data/lib/parse_tree.rb CHANGED
@@ -43,7 +43,7 @@ end
43
43
 
44
44
  class RawParseTree
45
45
 
46
- VERSION = '3.0.2'
46
+ VERSION = '3.0.3'
47
47
 
48
48
  ##
49
49
  # Front end translation method.
data/lib/unified_ruby.rb CHANGED
@@ -236,6 +236,10 @@ module UnifiedRuby
236
236
  lhs << lhs_splat
237
237
  end
238
238
 
239
+ # unwrap RHS from array IF it is only a splat node
240
+ rhs = rhs.last if rhs && # TODO: rhs.structure =~ s(:array, s(:splat))
241
+ rhs.size == 2 && rhs.structure.flatten.first(2) == [:array, :splat]
242
+
239
243
  s(t, lhs, rhs).compact
240
244
  end
241
245
 
data/test/pt_testcase.rb CHANGED
@@ -213,8 +213,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
213
213
  "RawParseTree" => [:class, :X, nil,
214
214
  [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
215
215
  "ParseTree" => s(:class, :X, nil,
216
- s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))),
217
- "Ruby2Ruby" => "class X\n alias_method :y, :x\nend")
216
+ s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))))
218
217
 
219
218
  add_tests("alias_ugh",
220
219
  "Ruby" => "class X\n alias y x\nend",
@@ -222,7 +221,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
222
221
  [:scope, [:alias, [:lit, :y], [:lit, :x]]]],
223
222
  "ParseTree" => s(:class, :X, nil,
224
223
  s(:scope, s(:alias, s(:lit, :y), s(:lit, :x)))),
225
- "Ruby2Ruby" => "class X\n alias_method :y, :x\nend")
224
+ "Ruby2Ruby" => "class X\n alias :y :x\nend")
226
225
 
227
226
  add_tests("and",
228
227
  "Ruby" => "(a and b)",
@@ -3093,7 +3092,7 @@ class ParseTreeTestCase < Test::Unit::TestCase
3093
3092
  s(:lit, 2),
3094
3093
  s(:lit, 3))))))
3095
3094
 
3096
- add_tests("masgn_splat",
3095
+ add_tests("masgn_splat_lhs",
3097
3096
  "Ruby" => "a, b, *c = d, e, f, g",
3098
3097
  "RawParseTree" => [:masgn,
3099
3098
  [:array, [:lasgn, :a], [:lasgn, :b]],
@@ -3112,6 +3111,35 @@ class ParseTreeTestCase < Test::Unit::TestCase
3112
3111
  s(:call, nil, :f, s(:arglist)),
3113
3112
  s(:call, nil, :g, s(:arglist)))))
3114
3113
 
3114
+ add_tests("masgn_splat_rhs_1",
3115
+ "Ruby" => "a, b = *c",
3116
+ "RawParseTree" => [:masgn,
3117
+ [:array, [:lasgn, :a], [:lasgn, :b]],
3118
+ nil,
3119
+ [:splat, [:vcall, :c]]],
3120
+ "ParseTree" => s(:masgn,
3121
+ s(:array,
3122
+ s(:lasgn, :a),
3123
+ s(:lasgn, :b)),
3124
+ s(:splat, s(:call, nil, :c, s(:arglist)))))
3125
+
3126
+ add_tests("masgn_splat_rhs_n",
3127
+ "Ruby" => "a, b = c, d, *e",
3128
+ "RawParseTree" => [:masgn,
3129
+ [:array, [:lasgn, :a], [:lasgn, :b]],
3130
+ nil,
3131
+ [:argscat,
3132
+ [:array, [:vcall, :c], [:vcall, :d]],
3133
+ [:vcall, :e]]],
3134
+ "ParseTree" => s(:masgn,
3135
+ s(:array,
3136
+ s(:lasgn, :a),
3137
+ s(:lasgn, :b)),
3138
+ s(:array,
3139
+ s(:call, nil, :c, s(:arglist)),
3140
+ s(:call, nil, :d, s(:arglist)),
3141
+ s(:splat, s(:call, nil, :e, s(:arglist))))))
3142
+
3115
3143
  add_tests("masgn_splat_no_name_to_ary",
3116
3144
  "Ruby" => "a, b, * = c",
3117
3145
  "RawParseTree" => [:masgn,
@@ -3901,6 +3929,12 @@ class ParseTreeTestCase < Test::Unit::TestCase
3901
3929
  s(:arglist, s(:str, " second\n")))))),
3902
3930
  "Ruby2Ruby" => "a = (a + ((\" first\\n\" + b) + \" second\\n\"))")
3903
3931
 
3932
+ add_tests("str_heredoc_empty", # yes... tarded
3933
+ "Ruby" => "<<'EOM'\nEOM",
3934
+ "RawParseTree" => [:str, ""],
3935
+ "ParseTree" => s(:str, ""),
3936
+ "Ruby2Ruby" => '""')
3937
+
3904
3938
  add_tests("str_heredoc_indent",
3905
3939
  "Ruby" => "<<-EOM\n blah\nblah\n\n EOM",
3906
3940
  "RawParseTree" => [:str, " blah\nblah\n\n"],
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ParseTree
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-04 00:00:00 -08:00
12
+ date: 2009-01-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 1.8.0
43
+ version: 1.8.2
44
44
  version:
45
45
  description: "ParseTree is a C extension (using RubyInline) that extracts the parse tree for an entire class or a specific method and returns it as a s-expression (aka sexp) using ruby's arrays, strings, symbols, and integers. As an example: def conditional1(arg1) if arg1 == 0 then return 1 end return 0 end becomes: [:defn, :conditional1, [:scope, [:block, [:args, :arg1], [:if, [:call, [:lvar, :arg1], :==, [:array, [:lit, 0]]], [:return, [:lit, 1]], nil], [:return, [:lit, 0]]]]]"
46
46
  email:
@@ -67,6 +67,7 @@ files:
67
67
  - bin/parse_tree_deps
68
68
  - bin/parse_tree_show
69
69
  - demo/printer.rb
70
+ - lib/gauntlet_parsetree.rb
70
71
  - lib/parse_tree.rb
71
72
  - lib/parse_tree_extensions.rb
72
73
  - lib/unified_ruby.rb