summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-08-13 21:50:16 -0400
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-09-28 18:07:24 +0900
commit97d1a381e112e843ff014a05a083e42165b7bb01 (patch)
tree5c995202ecb3de5101ef45e9bc749537f7539faf /libexec
parent3da3c2747feb0c4a122182792150a49012bed1a6 (diff)
[Fixes #137] Improve reporting
Diffstat (limited to 'libexec')
-rwxr-xr-xlibexec/racc39
1 files changed, 30 insertions, 9 deletions
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)