Skip to content

Commit

Permalink
Allow only-explicit-rules as a valid option
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Jan 11, 2025
1 parent 5a4901b commit 004e4d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 004e4d2

Please sign in to comment.