Class: Sol::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sol/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sol/cli.rb', line 9

def initialize

	@interpreter = Interpreter.new

	if file = ARGV.first

		@interpreter.eval File.read(file)

	else

		repl()

	end

end

Instance Method Details

#replObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sol/cli.rb', line 25

def repl

	Readline.completion_proc = proc {} # Disable tab

	puts "Sol #{VERSION} running on ruby #{RUBY_VERSION}"

	loop do

		begin

			line = Readline::readline('> ')

			Readline::HISTORY.push(line)
				   
			value = @interpreter.eval(line)

			puts "#{value.ruby_value.inspect}"

		rescue Interrupt

			puts "" # To fix the prompt not being printed on a newline

			puts "Use quit(), exit() or Ctrl-D to exit the repl"

		end

	end

end