Class: Lisp::REPL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeREPL

Returns a new instance of REPL.



8
9
10
11
12
13
14
15
16
# File 'lib/lisp/repl.rb', line 8

def initialize
  @io = Coolline.new do |config|
    config.transform_proc = proc do
      CodeRay.scan(config.line, :clojure).term
    end
  end

  reset_input!
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#ioObject (readonly)

Returns the value of attribute io.



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

def io
  @io
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lisp/repl.rb', line 18

def run
  trap("SIGINT") { throw :exit }

  puts "ctrl-c to exit"

  catch(:exit) do
    loop do
      begin
        @input += io.readline prompt

        if open_count == close_count
          puts Lisp.eval input

          reset_input!
        end
      rescue Exception => e
        puts e.message

        reset_input!
      end
    end
  end
end