lib/lrama/command.rb in lrama-0.1.0 vs lib/lrama/command.rb in lrama-0.2.0

- old
+ new

@@ -61,13 +61,14 @@ exit 1 end Report::Duration.enable if trace_opts[:time] + warning = Lrama::Warning.new y = File.read(grammar_file) grammar = Lrama::Parser.new(y).parse - states = Lrama::States.new(grammar, trace_state: (trace_opts[:automaton] || trace_opts[:closure])) + states = Lrama::States.new(grammar, warning, trace_state: (trace_opts[:automaton] || trace_opts[:closure])) states.compute context = Lrama::Context.new(states) if report_file reporter = Lrama::StatesReporter.new(states) @@ -85,24 +86,38 @@ header_file_path: header_file, context: context, grammar: grammar, ).render end + + if warning.has_error? + exit 1 + end end private def validate_report(report) - list = %w[states itemsets lookaheads solved counterexamples cex all none] - not_supported = %w[counterexamples cex all none] - h = {} + bison_list = %w[states itemsets lookaheads solved counterexamples cex all none] + others = %w[verbose] + list = bison_list + others + not_supported = %w[counterexamples cex none] + h = { grammar: true } report.each do |r| if list.include?(r) && !not_supported.include?(r) h[r.to_sym] = true else raise "Invalid report option \"#{r}\"." end + end + + if h[:all] + (bison_list - not_supported).each do |r| + h[r.to_sym] = true + end + + h.delete(:all) end return h end