Sha256: b538d9a3cb74d22404623ca8b6e9fc248282fbd589445b68b8a3598b14f67ec7

Contents?: true

Size: 681 Bytes

Versions: 2

Compression:

Stored size: 681 Bytes

Contents

require_relative 'rbl_readline'
require 'rubylisp/environment'
require 'rubylisp/parser'

module RubyLisp
  module REPL
    module_function

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rbl-0.0.7 lib/rubylisp/repl.rb
rbl-0.0.6 lib/rubylisp/repl.rb