diff --git a/src/babashka/impl/clojure/main.clj b/src/babashka/impl/clojure/main.clj index 1e8ac7a4..aea9726e 100644 --- a/src/babashka/impl/clojure/main.clj +++ b/src/babashka/impl/clojure/main.clj @@ -17,6 +17,8 @@ babashka.impl.clojure.main (:refer-clojure :exclude [with-bindings])) +(set! *warn-on-reflection* true) + (defn demunge "Given a string representation of a fn class, as in a stack trace element, returns a readable version." diff --git a/src/babashka/impl/repl.clj b/src/babashka/impl/repl.clj index 73b2267f..1ae3cebb 100644 --- a/src/babashka/impl/repl.clj +++ b/src/babashka/impl/repl.clj @@ -38,11 +38,18 @@ (str ":" line ":" column))"]")))) (sio/flush)))) +(defn skip-if-eol + "Inspired by skip-if-eol from clojure.main." + [s] + (let [c (r/read-char s)] + (when-not (= c \newline) + (r/unread s c)))) + (defn repl "REPL with predefined hooks for attachable socket server." ([sci-ctx] (repl sci-ctx nil)) ([sci-ctx {:keys [:init :read :eval :need-prompt :prompt :flush :print :caught]}] - (let [in (r/indexing-push-back-reader (r/push-back-reader @sci/in))] + (let [in @sci/in #_(r/indexing-push-back-reader (r/push-back-reader @sci/in))] (m/repl :init (or init (fn [] @@ -57,6 +64,7 @@ :read (or read (fn [_request-prompt request-exit] (let [v (parser/parse-next sci-ctx in)] + (skip-if-eol in) (if (or (identical? :repl/quit v) (identical? :repl/exit v) (identical? parser/eof v)) diff --git a/test/babashka/impl/repl_test.clj b/test/babashka/impl/repl_test.clj index a1bd730b..c82b12ca 100644 --- a/test/babashka/impl/repl_test.clj +++ b/test/babashka/impl/repl_test.clj @@ -47,6 +47,8 @@ (assert-repl "1\n(dec *1)(+ *2 *2)" "2") (assert-repl "1\n(dec *1)(+ *2 *2)" "2") (assert-repl "*command-line-args*" "[\"a\" \"b\" \"c\"]") + (assert-repl "(read-line)hello" "hello") + (assert-repl "(read-line)\nhello" "hello") (assert-repl-error "(+ 1 nil)" "NullPointerException") (assert-repl-error "(/ 1 0) (pst 1)" "Divide by zero\n\tclojure.lang.Numbers"))