lib/lrama/command.rb in lrama-0.6.9 vs lib/lrama/command.rb in lrama-0.6.10
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module Lrama
class Command
LRAMA_LIB = File.realpath(File.join(File.dirname(__FILE__)))
STDLIB_FILE_PATH = File.join(LRAMA_LIB, 'grammar', 'stdlib.y')
@@ -12,11 +14,10 @@
abort message
end
Report::Duration.enable if options.trace_opts[:time]
- warning = Lrama::Warning.new
text = options.y.read
options.y.close if options.y != STDIN
begin
grammar = Lrama::Parser.new(text, options.grammar_file, options.debug).parse
unless grammar.no_stdlib
@@ -29,31 +30,24 @@
raise e if options.debug
message = e.message
message = message.gsub(/.+/, "\e[1m\\&\e[m") if Exception.to_tty?
abort message
end
- states = Lrama::States.new(grammar, warning, trace_state: (options.trace_opts[:automaton] || options.trace_opts[:closure]))
+ states = Lrama::States.new(grammar, trace_state: (options.trace_opts[:automaton] || options.trace_opts[:closure]))
states.compute
context = Lrama::Context.new(states)
if options.report_file
reporter = Lrama::StatesReporter.new(states)
File.open(options.report_file, "w+") do |f|
reporter.report(f, **options.report_opts)
end
end
- if options.trace_opts && options.trace_opts[:rules]
- puts "Grammar rules:"
- puts grammar.rules
- end
+ reporter = Lrama::TraceReporter.new(grammar)
+ reporter.report(**options.trace_opts)
- if options.trace_opts && options.trace_opts[:actions]
- puts "Grammar rules with actions:"
- grammar.rules.each { |rule| puts rule.with_actions }
- end
-
File.open(options.outfile, "w+") do |f|
Lrama::Output.new(
out: f,
output_file_path: options.outfile,
template_name: options.skeleton,
@@ -63,11 +57,11 @@
grammar: grammar,
error_recovery: options.error_recovery,
).render
end
- if warning.has_error?
- exit false
- end
+ logger = Lrama::Logger.new
+ exit false unless Lrama::GrammarValidator.new(grammar, states, logger).valid?
+ Lrama::Diagnostics.new(grammar, states, logger).run(options.diagnostic)
end
end
end