You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
472 B
30 lines
472 B
#!/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
|