Sha256: 78f9fc1bb1166a76686249d25c602a92ebc4f926efed952a8067b4dba980ede9

Contents?: true

Size: 872 Bytes

Versions: 1

Compression:

Stored size: 872 Bytes

Contents

# frozen_string_literal: true

require_relative '../loxby'
require_relative 'config'

class Lox
  # `Lox::Runner` is the interactive runner
  # which kickstarts the interpreter.
  # An instance is created when loxby is
  # initialized from the command line,
  # though it can be instantiated from
  # code as well.
  class Runner
    def initialize(out = $stdout, err = $stderr)
      # Exit cleanly. 130 is for interrupted scripts
      trap('INT') do
        puts
        exit Lox.config.exit_code.interrupt
      end

      @interpreter = Lox.new
      @out = out
      @err = err
    end

    def run(args)
      if args.size > 1
        @out.puts 'Usage: loxby [script]'
        exit Lox.config.exit_code.usage
      elsif args.size == 1
        @interpreter.run_file args[0]
      else
        @interpreter.run_prompt # Run interactively
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
loxby-0.0.3 lib/loxby/runner.rb