cljs.repl/repl-read
function | since v0.0-2719 | Edit |
(repl-read request-prompt request-exit)
(repl-read request-prompt request-exit opts)
Source docstring:
Default :read hook for repl. Reads from *in* which must either be an
instance of LineNumberingPushbackReader or duplicate its behavior of both
supporting .unread and collapsing all of CR, LF, and CRLF into a single
\newline. repl-read:
- skips whitespace, then
- returns request-prompt on start of line, or
- returns request-exit on end of stream, or
- reads an object from the input stream, then
- skips the next input character if it's end of line, then
- returns the object.
(defn repl-read
([request-prompt request-exit]
(repl-read request-prompt request-exit *repl-opts*))
([request-prompt request-exit opts]
(let [current-in *in*
bind-in? (true? (:source-map-inline opts))]
(binding [*in* (if bind-in?
((:reader opts))
*in*)]
(or ({:line-start request-prompt :stream-end request-exit}
(skip-whitespace *in*))
(let [input (reader/read {:read-cond :allow :features #{:cljs}} *in*)]
(readers/unread current-in (readers/read-char *in*))
(skip-if-eol (if bind-in? current-in *in*))
input))))))