Skip to content

Commit 7d8b3c2

Browse files
committed
Allow racc cmdline to read from stdin if no path specified.
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
1 parent e17daed commit 7d8b3c2

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

bin/racc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main
3030
profiler = RaccProfiler.new(false)
3131

3232
parser = OptionParser.new
33-
parser.banner = "Usage: #{File.basename($0)} [options] <input>"
33+
parser.banner = "Usage: #{File.basename($0)} [options] [input]"
3434
parser.on('-o', '--output-file=PATH',
3535
'output file name [<input>.tab.rb]') {|name|
3636
output = name
@@ -121,21 +121,24 @@ def main
121121
$stderr.puts parser.help
122122
exit 1
123123
end
124-
if ARGV.empty?
125-
$stderr.puts 'no input'
126-
exit 1
127-
end
128124
if ARGV.size > 1
129125
$stderr.puts 'too many input'
130126
exit 1
131127
end
132-
input = ARGV[0]
128+
129+
input = ARGV[0] || "stdin"
130+
131+
if input == "stdin" && !output then
132+
$stderr.puts 'You must specify a path to read or use -o <path> for output.'
133+
exit 1
134+
end
133135

134136
begin
135137
$stderr.puts 'Parsing grammar file...' if verbose
136138
result = profiler.section('parse') {
137139
parser = Racc::GrammarFileParser.new(debug_flags)
138-
parser.parse(File.read(input), File.basename(input))
140+
content = input == "stdin" ? ARGF.read : File.read(input)
141+
parser.parse(content, File.basename(input))
139142
}
140143
if check_only
141144
$stderr.puts 'syntax ok'

0 commit comments

Comments
 (0)