Skip to content

Commit

Permalink
Merge pull request #139 from ydah/support-H-option
Browse files Browse the repository at this point in the history
Allow `-H` option to also generate a header file with the specified name
  • Loading branch information
yui-knk authored Oct 19, 2023
2 parents 61a5d51 + 018517b commit fc23a4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/lrama/option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def parse_by_option_parser(argv)
o.on('-t', 'reserved, do nothing') { }
o.separator ''
o.separator 'Output:'
o.on('-h', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v }
o.on('-H', '--header=[FILE]', 'also produce a header file named FILE') {|v| @options.header = true; @options.header_file = v }
o.on('-h=[FILE]', 'also produce a header file named FILE (deprecated)') {|v| @options.header = true; @options.header_file = v }
o.on('-d', 'also produce a header file') { @options.header = true }
o.on('-r', '--report=THINGS', Array, 'also produce details on the automaton') {|v| @report = v }
o.on('--report-file=FILE', 'also produce details on the automaton output to a file named FILE') {|v| @options.report_file = v }
Expand Down
16 changes: 13 additions & 3 deletions spec/lrama/option_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
-t reserved, do nothing
Output:
-h, --header=[FILE] also produce a header file named FILE
-H, --header=[FILE] also produce a header file named FILE
-h=[FILE] also produce a header file named FILE (deprecated)
-d also produce a header file
-r, --report=THINGS also produce details on the automaton
--report-file=FILE also produce details on the automaton output to a file named FILE
Expand Down Expand Up @@ -137,6 +138,15 @@
describe "@header_file" do
context "header file name is not passed" do
context "outfile option is passed" do
it "@header_file is set based on outfile" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["-H", "-o", "parse.c", "-", "test.y"])
options = option_parser.instance_variable_get(:@options)
expect(options.header_file).to eq "./parse.h"
end
end

context "deprecated outfile option is passed" do
it "@header_file is set based on outfile" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["-h", "-o", "parse.c", "-", "test.y"])
Expand All @@ -148,7 +158,7 @@
context "outfile option is not passed" do
it "@header_file is set based on outfile default value" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["-h", "-", "test.y"])
option_parser.send(:parse, ["-H", "-", "test.y"])
options = option_parser.instance_variable_get(:@options)
expect(options.header_file).to eq "./y.tab.h"
end
Expand All @@ -158,7 +168,7 @@
context "header file name is passed" do
it "@header_file is same with passed value" do
option_parser = Lrama::OptionParser.new
option_parser.send(:parse, ["-hparse.h", "-", "test.y"])
option_parser.send(:parse, ["-Hparse.h", "-", "test.y"])
options = option_parser.instance_variable_get(:@options)
expect(options.header_file).to eq "parse.h"
end
Expand Down

0 comments on commit fc23a4e

Please sign in to comment.