From 198a28b7faa9410b7246f7abe1533f7d3f18e3ab Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 30 Apr 2024 13:43:25 +0900 Subject: [PATCH 1/4] Abort instead of puts and exit --- bin/racc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/bin/racc b/bin/racc index 8a162777..d3d5695f 100755 --- a/bin/racc +++ b/bin/racc @@ -117,20 +117,16 @@ def main 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 for output.' - exit 1 + abort 'You must specify a path to read or use -o for output.' end begin @@ -201,8 +197,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 From e380a4ae6e39cbc84826690e2c4ff8eb8fa448ca Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 30 Apr 2024 13:45:02 +0900 Subject: [PATCH 2/4] Omit the default exit value --- bin/racc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/racc b/bin/racc index d3d5695f..2d202b50 100755 --- a/bin/racc +++ b/bin/racc @@ -92,7 +92,7 @@ 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", @@ -104,11 +104,11 @@ def main sprintf('c core version %s', 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 @@ -138,7 +138,7 @@ def main } if check_only $stderr.puts 'syntax ok' - exit 0 + exit end $stderr.puts 'Generating LALR states...' if verbose From e4d1f56de1b1b1d6bb8d106386e46e36861b9553 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 30 Apr 2024 13:45:33 +0900 Subject: [PATCH 3/4] Make `--help` success --- bin/racc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/racc b/bin/racc index 2d202b50..981ccb4a 100755 --- a/bin/racc +++ b/bin/racc @@ -112,7 +112,7 @@ def main } parser.on('--help', 'Prints this message and quit.') { puts parser.help - exit 1 + exit } begin parser.parse! From 251e4060387a91737a00b3220ded24dc5117d6ca Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 30 Apr 2024 13:55:51 +0900 Subject: [PATCH 4/4] Simplify `--runtime-version` option --- bin/racc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bin/racc b/bin/racc index 981ccb4a..a1b3c040 100755 --- a/bin/racc +++ b/bin/racc @@ -95,14 +95,13 @@ def main 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 }