1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env ruby -w
$LOAD_PATH.unshift(File.expand_path("../lib", __dir__))
require "lox"
def run_prompt(runner)
loop do
print "> "
line = gets
break if line.nil? || line.empty?
runner.run(line)
end
end
def run_file(runner, io)
runner.run(io.read)
end
if __FILE__ == $0
puts "Usage: #$0 [script]" or exit 64 if ARGV.length > 1
if ARGV.empty?
run_prompt(Lox::PromptRunner.new)
else
Lox::FileRunner.new.run(ARGF.read)
end
end