Sha256: 07ca8285f8ece9671af8b70426a16ad7659aa0589ba3f27ff3bbcbe06ed4e742

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

module Redcar
  class Clojure
    class ReplMirror < Redcar::REPL::ReplMirror

      def title
        "Clojure REPL"
      end

      def grammar_name
        "Clojure REPL"
      end

      def prompt
        "user=>"
      end

      def evaluator
        @evaluator ||= Evaluator.new(self)
      end

      def format_error(e)
        "ERROR: #{e.message}\n\n#{e.backtrace.join("\n")}"
      end

      class Evaluator
        attr_reader :wrapper

        def self.load_dependencies
          unless @loaded
            Clojure.load_dependencies
            import 'redcar.repl.Wrapper'
            @loaded = true
          end
        end

        def initialize(mirror)
          Evaluator.load_dependencies
          @mirror = mirror
          @wrapper ||= begin
            wrapper = Wrapper.new

            @thread = Thread.new do
              loop do
                output = wrapper.getResult
                output =~ /^(.*)\nuser=> /
                @result = $1
              end
            end

            wrapper
          end
        end

        def execute(expr)
          wrapper.sendToRepl(expr)
          true until @result
          str = @result
          @result = nil
          str
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
redcar-clojure-0.2 lib/clojure/repl_mirror.rb
redcar-clojure-0.1-java lib/clojure/repl_mirror.rb
redcar-0.11 plugins/clojure/lib/clojure/repl_mirror.rb
redcar-0.11.0dev plugins/clojure/lib/clojure/repl_mirror.rb
redcar-0.10 plugins/clojure/lib/clojure/repl_mirror.rb