Permalink
Browse files

+ Added bin/ruby_parse_extract_error to help with error submissions

[git-p4: depot-paths = "//src/ruby_parser/dev/": change = 7326]
  • Loading branch information...
1 parent feebfe8 commit 19b390ad69f6bf32de8c9e5df71d58c4e1c86163 @zenspider zenspider committed Apr 13, 2012
Showing with 63 additions and 0 deletions.
  1. +1 −0 Manifest.txt
  2. +62 −0 bin/ruby_parse_extract_error
View
1 Manifest.txt
@@ -4,6 +4,7 @@ Manifest.txt
README.txt
Rakefile
bin/ruby_parse
+bin/ruby_parse_extract_error
lib/gauntlet_rubyparser.rb
lib/ruby18_parser.rb
lib/ruby18_parser.y
View
62 bin/ruby_parse_extract_error
@@ -0,0 +1,62 @@
+#!/usr/bin/ruby -ws
+
+require 'rubygems'
+require 'ruby_parser'
+
+ARGV.push "-" if ARGV.empty?
+
+parser = Ruby18Parser.new
+
+class Racc::Parser
+ def extract_defs
+ ss = lexer.src
+ src = ss.string
+ pre_error = src[0...ss.pos]
+
+ defs = pre_error.grep(/^ *def/)
+
+ last_def_indent = defs.last[/^ */]
+
+ post_error = src[ss.pos..-1]
+ idx = post_error =~ /^#{last_def_indent}end.*/
+
+ raise "can't figure out where the bad code ends" unless idx
+
+ src = pre_error + post_error[0..idx+$&.length]
+
+ src.scan(/^(( *)def .*?^\2end)/m)
+ end
+
+ def retest_for_errors defs
+ d :retest => defs.size
+
+ parser = self.class.new
+
+ parser.process(defs.join("\n\n")) rescue nil
+ end
+end
+
+ARGV.each do |file|
+ ruby = file == "-" ? $stdin.read : File.read(file)
+
+ begin
+ parser.process(ruby, file)
+ rescue Racc::ParseError => e
+ defs = parser.extract_defs
+
+ abort "Can't reproduce error with just methods, punting..." if
+ parser.retest_for_errors defs
+
+ mandatory = defs.pop
+
+ (1..defs.size).each do |perm_size|
+ defs.combination(perm_size).each do |trial|
+ trial << mandatory
+ unless parser.retest_for_errors trial then
+ puts trial.join "\n"
+ abort "reduced repro found!"
+ end
+ end
+ end
+ end
+end

0 comments on commit 19b390a

Please sign in to comment.