diff --git a/lib/lrama/option_parser.rb b/lib/lrama/option_parser.rb index fdd41d27..60da58d7 100644 --- a/lib/lrama/option_parser.rb +++ b/lib/lrama/option_parser.rb @@ -143,19 +143,20 @@ def aliased_report_option(opt) locations scan parse bitsets grammar resource sets muscles tools m4-early m4 skeleton ielr cex ].freeze + SUPPORTED_TRACES = VALID_TRACES - NOT_SUPPORTED_TRACES def validate_trace(trace) h = {} return h if trace.empty? || trace == ['none'] - supported = VALID_TRACES - NOT_SUPPORTED_TRACES - %w[only-explicit-rules] + all_traces = SUPPORTED_TRACES - %w[only-explicit-rules] if trace == ['all'] - supported.each { |t| h[t.to_sym] = true } + all_traces.each { |t| h[t.gsub(/-/, '_').to_sym] = true } return h end trace.each do |t| - if supported.include?(t) - h[t.to_sym] = true + if SUPPORTED_TRACES.include?(t) + h[t.gsub(/-/, '_').to_sym] = true else raise "Invalid trace option \"#{t}\"." end diff --git a/spec/lrama/option_parser_spec.rb b/spec/lrama/option_parser_spec.rb index fb620ea8..22560dd7 100644 --- a/spec/lrama/option_parser_spec.rb +++ b/spec/lrama/option_parser_spec.rb @@ -170,9 +170,15 @@ end context "when valid options are passed" do + let(:valid_traces) do + %w[automaton closure rules only-explicit-rules actions time] + end + it "returns option hash" do - opts = option_parser.send(:validate_trace, ["automaton", "closure"]) - expect(opts).to eq({automaton: true, closure: true}) + opts = option_parser.send(:validate_trace, valid_traces) + expect(opts).to eq({ + only_explicit_rules: true, actions: true, automaton: true, closure: true, rules: true, time: true + }) end context "when all is passed" do