Skip to content

Commit

Permalink
read signature consistent with c.c/read, correctly handle :eof as per…
Browse files Browse the repository at this point in the history
… CLJ-1685
  • Loading branch information
Bronsa committed Apr 8, 2015
1 parent d7d3bc1 commit eb5153c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/clojure/clojure/tools/reader.clj
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,13 @@
Returns the object read. If EOF, throws if eof-error? is true.
Otherwise returns sentinel. If no stream is providen, *in* will be used.
Opts is a persistent map with valid keys:
:read-cond - :allow to process reader conditionals, or
:preserve to keep all branches
:features - persistent set of feature keywords for reader conditionals
:eof - on eof, return value unless :eofthrow, then throw.
if not specified, will throw
***WARNING***
Note that read can execute code (controlled by *read-eval*),
and as such should be used only with trusted sources.
Expand All @@ -871,9 +878,10 @@
Note that the function signature of clojure.tools.reader/read and
clojure.tools.reader.edn/read is not the same for eof-handling"
{:arglists '([] [reader] [opts reader] [reader eof-error? eof-value])}
([] (read *in*))
([reader] (read reader true nil nil {} (LinkedList.)))
([reader {eof :eof :as opts}] (read reader (not (nil? eof)) eof nil opts (LinkedList.)))
([{eof :eof :as opts :or {eof :eofthrow}} reader] (read reader (= eof :eofthrow) eof nil opts (LinkedList.)))
([reader eof-error? sentinel] (read reader eof-error? sentinel nil {} (LinkedList.)))
([reader eof-error? sentinel opts pending-forms] (read reader eof-error? sentinel nil opts pending-forms))
([reader eof-error? sentinel return-on opts pending-forms]
Expand Down Expand Up @@ -931,11 +939,10 @@
Note that the function signature of clojure.tools.reader/read-string and
clojure.tools.reader.edn/read-string is not the same for eof-handling"
([s]
(when (and s (not (identical? s "")))
(read (string-push-back-reader s) true nil)))
(read-string {} s))
([opts s]
(when (and s (not (identical? s ""))))
(read (string-push-back-reader s) opts)))
(when (and s (not (identical? s "")))
(read opts (string-push-back-reader s)))))

(defmacro syntax-quote
"Macro equivalent to the syntax-quote reader macro (`)."
Expand Down

0 comments on commit eb5153c

Please sign in to comment.