Skip to content

Commit

Permalink
Allow racc cmdline to read from stdin if no path specified.
Browse files Browse the repository at this point in the history
This requires the use of -o <path> to specify where to write but
should allow for piping to racc:

    preprocess_cmd | racc -o lib/parser.rb
  • Loading branch information
zenspider committed Jan 5, 2024
1 parent 35e6850 commit b3e23a7
Showing 1 changed file with 10 additions and 7 deletions.
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

0 comments on commit b3e23a7

Please sign in to comment.