[#899] (read-line) is buggy in REPL
This commit is contained in:
parent
13773d0104
commit
af754d013f
3 changed files with 13 additions and 1 deletions
|
|
@ -17,6 +17,8 @@
|
||||||
babashka.impl.clojure.main
|
babashka.impl.clojure.main
|
||||||
(:refer-clojure :exclude [with-bindings]))
|
(:refer-clojure :exclude [with-bindings]))
|
||||||
|
|
||||||
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
(defn demunge
|
(defn demunge
|
||||||
"Given a string representation of a fn class,
|
"Given a string representation of a fn class,
|
||||||
as in a stack trace element, returns a readable version."
|
as in a stack trace element, returns a readable version."
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,18 @@
|
||||||
(str ":" line ":" column))"]"))))
|
(str ":" line ":" column))"]"))))
|
||||||
(sio/flush))))
|
(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
|
(defn repl
|
||||||
"REPL with predefined hooks for attachable socket server."
|
"REPL with predefined hooks for attachable socket server."
|
||||||
([sci-ctx] (repl sci-ctx nil))
|
([sci-ctx] (repl sci-ctx nil))
|
||||||
([sci-ctx {:keys [:init :read :eval :need-prompt :prompt :flush :print :caught]}]
|
([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
|
(m/repl
|
||||||
:init (or init
|
:init (or init
|
||||||
(fn []
|
(fn []
|
||||||
|
|
@ -57,6 +64,7 @@
|
||||||
:read (or read
|
:read (or read
|
||||||
(fn [_request-prompt request-exit]
|
(fn [_request-prompt request-exit]
|
||||||
(let [v (parser/parse-next sci-ctx in)]
|
(let [v (parser/parse-next sci-ctx in)]
|
||||||
|
(skip-if-eol in)
|
||||||
(if (or (identical? :repl/quit v)
|
(if (or (identical? :repl/quit v)
|
||||||
(identical? :repl/exit v)
|
(identical? :repl/exit v)
|
||||||
(identical? parser/eof v))
|
(identical? parser/eof v))
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@
|
||||||
(assert-repl "1\n(dec *1)(+ *2 *2)" "2")
|
(assert-repl "1\n(dec *1)(+ *2 *2)" "2")
|
||||||
(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 "*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 nil)" "NullPointerException")
|
||||||
(assert-repl-error "(/ 1 0) (pst 1)" "Divide by zero\n\tclojure.lang.Numbers"))
|
(assert-repl-error "(/ 1 0) (pst 1)" "Divide by zero\n\tclojure.lang.Numbers"))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue