Skip to content

Commit

Permalink
Merge pull request #265 from nobu/options
Browse files Browse the repository at this point in the history
Refactor command line options
  • Loading branch information
nobu committed Apr 30, 2024
2 parents 7a3bd89 + 251e406 commit 0c0f585
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions bin/racc
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

0 comments on commit 0c0f585

Please sign in to comment.