Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor command line options #265

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions bin/racc
Original file line number Diff line number Diff line change
Expand Up @@ -92,45 +92,40 @@ def main
#}
parser.on('--version', 'Prints version and quit.') {
puts "racc version #{Racc::Version}"
exit 0
exit
}
parser.on('--runtime-version', 'Prints runtime version and quit.') {
printf "racc runtime version %s; %s\n",
printf "racc runtime version %s; %s core version %s\n",
Racc::Parser::Racc_Runtime_Version,
Racc::Parser.racc_runtime_type,
if Racc::Parser.racc_runtime_type == 'ruby'
sprintf('ruby core version %s',
Racc::Parser::Racc_Runtime_Core_Version_R)
Racc::Parser::Racc_Runtime_Core_Version_R
else
sprintf('c core version %s',
Racc::Parser::Racc_Runtime_Core_Version_C)
Racc::Parser::Racc_Runtime_Core_Version_C
end
exit 0
exit
}
parser.on('--copyright', 'Prints copyright and quit.') {
puts Racc::Copyright
exit 0
exit
}
parser.on('--help', 'Prints this message and quit.') {
puts parser.help
exit 1
exit
}
begin
parser.parse!
rescue OptionParser::ParseError => err
$stderr.puts err.message
$stderr.puts parser.help
exit 1
abort [err.message, parser.help].join("\n")
end
if ARGV.size > 1
$stderr.puts 'too many input'
exit 1
abort 'too many input'
end

input = ARGV[0] || "stdin"

if input == "stdin" && !output then
$stderr.puts 'You must specify a path to read or use -o <path> for output.'
exit 1
abort 'You must specify a path to read or use -o <path> for output.'
end

begin
Expand All @@ -142,7 +137,7 @@ def main
}
if check_only
$stderr.puts 'syntax ok'
exit 0
exit
end

$stderr.puts 'Generating LALR states...' if verbose
Expand Down Expand Up @@ -201,8 +196,7 @@ def main
rescue Racc::Error, Errno::ENOENT, Errno::EPERM => err
raise if $DEBUG or debug_flags.any?
lineno = err.message.slice(/\A\d+:/).to_s
$stderr.puts "#{File.basename $0}: #{input}:#{lineno} #{err.message.strip}"
exit 1
abort "#{File.basename $0}: #{input}:#{lineno} #{err.message.strip}"
end
end

Expand Down