Class: Kolom::REPL

Inherits:
Object
  • Object
show all
Defined in:
lib/kolom/repl.rb

Instance Method Summary collapse

Constructor Details

#initializeREPL

Returns a new instance of REPL.



6
7
8
9
# File 'lib/kolom/repl.rb', line 6

def initialize
  @interpreter = Interpreter.new
  @history = []
end

Instance Method Details

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kolom/repl.rb', line 11

def start
  loop do
    line = Readline.readline("কলম> ", true)
    break if line.nil? || line.strip == 'বাহির'
    
    begin
      result, output = @interpreter.evaluate(line)
      puts output unless output.empty?
      puts "=> #{result.inspect}" unless result.nil?
    rescue => e
      puts "Error: #{e.message}"
      puts e.backtrace.join("\n")
    end
    
    @history << line
    Readline::HISTORY.push(line)
  end
  
  puts "ধন্যবাদ!"
end