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

Allow racc cmdline to read from stdin if no path specified. #259

Merged
merged 1 commit into from Feb 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions bin/racc
Expand Up @@ -30,7 +30,7 @@ def main
profiler = RaccProfiler.new(false)

parser = OptionParser.new
parser.banner = "Usage: #{File.basename($0)} [options] <input>"
parser.banner = "Usage: #{File.basename($0)} [options] [input]"
parser.on('-o', '--output-file=PATH',
'output file name [<input>.tab.rb]') {|name|
output = name
Expand Down Expand Up @@ -121,21 +121,24 @@ def main
$stderr.puts parser.help
exit 1
end
if ARGV.empty?
$stderr.puts 'no input'
exit 1
end
if ARGV.size > 1
$stderr.puts 'too many input'
exit 1
end
input = ARGV[0]

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
end

begin
$stderr.puts 'Parsing grammar file...' if verbose
result = profiler.section('parse') {
parser = Racc::GrammarFileParser.new(debug_flags)
parser.parse(File.read(input), File.basename(input))
content = input == "stdin" ? ARGF.read : File.read(input)
parser.parse(content, File.basename(input))
}
if check_only
$stderr.puts 'syntax ok'
Expand Down