Sha256: c6382c680f7812fd4a83317829d83fec028bbffa12f71ed9b0e394e9d46661f3

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

#!/usr/bin/env ruby
# The Rouge REPL/interpreter.
$: << "#{File.dirname(__FILE__)}/../lib"
require 'rouge'
require 'optparse'

options = {:backtrace => true}

option_parser = OptionParser.new do |opts|
  opts.banner = "rouge [switch] [filename]"

  opts.on('-v', '--version', 'Print version number') do
    puts "Rouge #{Rouge::VERSION}"
    exit 0
  end

  opts.on('-e STR', '--eval STR', 'Evaluate the contents of STR') do |str|
    Rouge.boot!
    Rouge::Context.new(Rouge[:user]).readeval(str)
    exit 0
  end

  opts.on('--time-startup', 'Report boot up time') do
    Rouge.boot!
    puts Time.now - Rouge.start
    exit 0
  end

  opts.on('--[no-]backtrace', 'Enable/disable backtracing in REPL') do |bool|
    options[:backtrace] = bool
  end
end

begin
  option_parser.parse!
rescue OptionParser::MissingArgument => e
  puts "rouge: #{e}"
end

if ARGV.length == 1
  file = ARGV[0]

  if File.file?(file)
    code = File.read(file)
  else
    STDERR.puts "rouge: No such file -- #{file}"
    exit 1
  end

  # Permit shebangs at the top of the document.
  if code[0..1] == "#!"
    code = code[code.index("\n") + 1..-1]
  end

  Rouge.boot!
  Rouge::Context.new(Rouge[:user]).readeval(code)

  exit 0
elsif ARGV.length > 1
  STDERR.puts option_parser.help
  exit 1
end

Rouge.repl(options)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rouge-lang-0.0.7 bin/rouge