Skip to content

Commit

Permalink
Merge pull request #259 from zenspider/zenspider/stdin
Browse files Browse the repository at this point in the history
Allow racc cmdline to read from stdin if no path specified.
  • Loading branch information
tenderlove authored Feb 25, 2024
2 parents db0014f + 7d8b3c2 commit d52fb64
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions bin/racc
Original file line number Diff line number Diff line change
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

0 comments on commit d52fb64

Please sign in to comment.