From 97d1a381e112e843ff014a05a083e42165b7bb01 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Thu, 13 Aug 2020 21:50:16 -0400 Subject: [Fixes #137] Improve reporting --- libexec/racc | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'libexec') diff --git a/libexec/racc b/libexec/racc index 0f0f642cd6..2edd6bb07b 100755 --- a/libexec/racc +++ b/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) -- cgit v1.2.3