Module: RubyLisp::REPL

Defined in:
lib/rubylisp/repl.rb

Class Method Summary collapse

Class Method Details

.startObject



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

def start
  env = Environment.new(namespace: 'user').stdlib.repl

  while buf = _readline("#{env.namespace}> ")
    begin
      input = buf.nil? ? '' : buf.strip
      puts input.empty? ? '' : Parser.parse(input, env)
    rescue => e
      # If an error happens, print it like Ruby would and continue accepting
      # REPL input.
      puts e.backtrace
            .join("\n\t")
            .sub("\n\t", ": #{e}#{e.class ? " (#{e.class})" : ''}\n\t")
    end
  end
end