mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Fixes #137] Improve reporting
This commit is contained in:
parent
3da3c2747f
commit
97d1a381e1
4 changed files with 77 additions and 25 deletions
39
libexec/racc
39
libexec/racc
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env ruby
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
#
|
||||
# Copyright (c) 1999-2006 Minero Aoki
|
||||
#
|
||||
|
|
@ -184,8 +184,12 @@ def main
|
|||
log_useless states.grammar
|
||||
log_conflict states
|
||||
else
|
||||
report_useless states.grammar
|
||||
report_conflict states
|
||||
has_useless = report_useless states.grammar
|
||||
has_conflicts = report_conflict states
|
||||
if has_useless || has_conflicts
|
||||
preamble = make_logfile ? 'C' : 'Turn on logging with "-v" and c'
|
||||
$stderr.puts %Q{#{preamble}heck ".output" file for details}
|
||||
end
|
||||
end
|
||||
|
||||
profiler.report
|
||||
|
|
@ -201,13 +205,29 @@ def make_filename(path, suffix)
|
|||
path.sub(/(?:\..*?)?\z/, suffix)
|
||||
end
|
||||
|
||||
LIST_LIMIT = 10
|
||||
def report_list(enum, label)
|
||||
c = enum.count
|
||||
if c > 0
|
||||
$stderr.puts "#{c} #{label}:"
|
||||
enum.first(LIST_LIMIT).each do |item|
|
||||
$stderr.puts " #{yield item}"
|
||||
end
|
||||
$stderr.puts " ..." if c > LIST_LIMIT
|
||||
end
|
||||
end
|
||||
|
||||
# @return [Boolean] if anything was reported
|
||||
def report_conflict(states)
|
||||
if states.should_report_srconflict?
|
||||
reported = true
|
||||
$stderr.puts "#{states.n_srconflicts} shift/reduce conflicts"
|
||||
end
|
||||
if states.rrconflict_exist?
|
||||
reported = true
|
||||
$stderr.puts "#{states.n_rrconflicts} reduce/reduce conflicts"
|
||||
end
|
||||
reported
|
||||
end
|
||||
|
||||
def log_conflict(states)
|
||||
|
|
@ -222,16 +242,17 @@ def log_conflict(states)
|
|||
}
|
||||
end
|
||||
|
||||
# @return [Boolean] if anything was reported
|
||||
def report_useless(grammar)
|
||||
if grammar.useless_nonterminal_exist?
|
||||
$stderr.puts "#{grammar.n_useless_nonterminals} useless nonterminals"
|
||||
end
|
||||
if grammar.useless_rule_exist?
|
||||
$stderr.puts "#{grammar.n_useless_rules} useless rules"
|
||||
end
|
||||
reported = report_list(grammar.each_useless_nonterminal, 'useless nonterminals', &:to_s)
|
||||
|
||||
reported ||= report_list(grammar.each_useless_rule, 'useless rules') { |r| "##{r.ident} (#{r.target})" }
|
||||
|
||||
if grammar.start.useless?
|
||||
$stderr.puts 'fatal: start symbol does not derive any sentence'
|
||||
reported = true
|
||||
end
|
||||
reported
|
||||
end
|
||||
|
||||
def log_useless(grammar)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue