Skip to content
Newer
Older
100644 387 lines (339 sloc) 12.8 KB
547ff85 @Bronsa added namespace docstring
Bronsa authored
1 (ns ^{:doc "An EDN reader in clojure"
2 :author "Bronsa"}
3 clojure.tools.reader.edn
1d05a02 @Bronsa decouple from clojure's vars (*read-eval*, *default-data-reader-fn*, …
Bronsa authored
4 (:refer-clojure :exclude [read read-line read-string char default-data-readers])
a6aae86 @Bronsa require :refer -> use :only for clojure 1.3 compatibility
Bronsa authored
5 (:use clojure.tools.reader.reader-types
1d05a02 @Bronsa decouple from clojure's vars (*read-eval*, *default-data-reader-fn*, …
Bronsa authored
6 [clojure.tools.reader.impl utils commons]
7 [clojure.tools.reader :only [default-data-readers]])
8 (:import (clojure.lang PersistentHashSet IMeta RT PersistentVector)))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
9
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c99eeb6 @Bronsa move common sharable implementation to its own namespace
Bronsa authored
11 ;; helpers
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
12 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
14 (declare read macros dispatch-macros)
15
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
16 (defn- macro-terminating? [ch]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
17 (and (not (identical? \# ch))
18 (not (identical? \' ch))
19 (not (identical? \: ch))
20 (macros ch)))
21
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
22 (defn- not-constituent? [ch]
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
23 (or (identical? \@ ch)
24 (identical? \` ch)
25 (identical? \~ ch)))
26
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
27 (defn- ^String read-token
02fb2f5 @Bronsa fix reading \@ \~ and `
Bronsa authored
28 ([rdr initch]
29 (read-token rdr initch true))
30 ([rdr initch validate-leading?]
31 (cond
32 (not initch)
33 (reader-error rdr "EOF while reading")
34
35 (and validate-leading?
36 (not-constituent? initch))
37 (reader-error rdr "Invalid leading character: " initch)
38
39 :else
40 (loop [sb (doto (StringBuilder.) (.append initch))
41 ch (peek-char rdr)]
42 (if (or (whitespace? ch)
43 (macro-terminating? ch)
44 (nil? ch))
45 (str sb)
46 (if (not-constituent? ch)
47 (reader-error rdr "Invalid constituent character: " ch)
48 (recur (doto sb (.append (read-char rdr))) (peek-char rdr))))))))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
49
50 (declare read-tagged)
51
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
52 (defn- read-dispatch
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
53 [rdr _ opts]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
54 (if-let [ch (read-char rdr)]
55 (if-let [dm (dispatch-macros ch)]
459f45a @Bronsa pass opts where missing
Bronsa authored
56 (dm rdr ch opts)
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
57 (if-let [obj (read-tagged (doto rdr (unread ch)) ch opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
58 obj
59 (reader-error rdr "No dispatch macro for " ch)))
60 (reader-error rdr "EOF while reading character")))
61
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
62 (defn- read-unmatched-delimiter
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
63 [rdr ch opts]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
64 (reader-error rdr "Unmatched delimiter " ch))
65
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67 ;; readers
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
70 (defn- read-unicode-char
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
71 ([^String token offset length base]
72 (let [l (+ offset length)]
73 (when-not (== (count token) l)
74 (throw (IllegalArgumentException. (str "Invalid unicode character: \\" token))))
75 (loop [i offset uc 0]
76 (if (== i l)
77 (char uc)
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
78 (let [d (Character/digit (char (nth token i)) (int base))]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
79 (if (== d -1)
80 (throw (IllegalArgumentException. (str "Invalid digit: " (nth token i))))
81 (recur (inc i) (long (+ d (* uc base))))))))))
82
83 ([rdr initch base length exact?]
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
84 (loop [i 1 uc (Character/digit (char initch) (int base))]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
85 (if (== uc -1)
86 (throw (IllegalArgumentException. (str "Invalid digit: " initch)))
87 (if-not (== i length)
88 (let [ch (peek-char rdr)]
89 (if (or (whitespace? ch)
90 (macros ch)
91 (nil? ch))
92 (if exact?
93 (throw (IllegalArgumentException.
94 (str "Invalid character length: " i ", should be: " length)))
95 (char uc))
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
96 (let [d (Character/digit (char ch) (int base))]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
97 (read-char rdr)
98 (if (== d -1)
99 (throw (IllegalArgumentException. (str "Invalid digit: " ch)))
100 (recur (inc i) (long (+ d (* uc base))))))))
101 (char uc))))))
102
9c3fead @Bronsa style fix
Bronsa authored
103 (def ^:private ^:const upper-limit (int \uD7ff))
104 (def ^:private ^:const lower-limit (int \uE000))
105
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
106 (defn- read-char*
9c3fead @Bronsa style fix
Bronsa authored
107 [rdr backslash opts]
108 (let [ch (read-char rdr)]
109 (if-not (nil? ch)
110 (let [token (read-token rdr ch false)
111 token-len (count token)]
112 (cond
113
114 (== 1 token-len) (Character/valueOf (nth token 0))
115
116 (= token "newline") \newline
117 (= token "space") \space
118 (= token "tab") \tab
119 (= token "backspace") \backspace
120 (= token "formfeed") \formfeed
121 (= token "return") \return
122
123 (.startsWith token "u")
124 (let [c (read-unicode-char token 1 4 16)
125 ic (int c)]
126 (if (and (> ic upper-limit)
127 (< ic lower-limit))
128 (reader-error rdr "Invalid character constant: \\u" (Integer/toString ic 16))
129 c))
130
131 (.startsWith token "x")
132 (read-unicode-char token 1 2 16)
133
134 (.startsWith token "o")
135 (let [len (dec token-len)]
136 (if (> len 3)
137 (reader-error rdr "Invalid octal escape sequence length: " len)
138 (let [uc (read-unicode-char token 1 len 8)]
139 (if (> (int uc) 0377)
140 (reader-error rdr "Octal escape sequence must be in range [0, 377]")
141 uc))))
142
143 :else (reader-error rdr "Unsupported character: \\" token)))
144 (reader-error rdr "EOF while reading character"))))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
145
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
146 (defn- ^PersistentVector read-delimited
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
147 [delim rdr opts]
1d05a02 @Bronsa decouple from clojure's vars (*read-eval*, *default-data-reader-fn*, …
Bronsa authored
148 (let [first-line (when (indexing-reader? rdr)
149 (get-line-number rdr))
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
150 delim (char delim)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
151 (loop [a (transient [])]
152 (let [ch (read-past whitespace? rdr)]
153 (when-not ch
154 (reader-error rdr "EOF while reading"
155 (if first-line
156 (str ", starting at line" first-line))))
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
157 (if (identical? delim (char ch))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
158 (persistent! a)
159 (if-let [macrofn (macros ch)]
459f45a @Bronsa pass opts where missing
Bronsa authored
160 (let [mret (macrofn rdr ch opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
161 (recur (if-not (identical? mret rdr) (conj! a mret) a)))
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
162 (let [o (read (doto rdr (unread ch)) true nil opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
163 (recur (if-not (identical? o rdr) (conj! a o) a)))))))))
164
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
165 (defn- read-list
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
166 [rdr _ opts]
167 (let [the-list (read-delimited \) rdr opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
168 (if (empty? the-list)
169 '()
29d0dce @Bronsa remove line/column info from EDN reader
Bronsa authored
170 (clojure.lang.PersistentList/create the-list))))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
171
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
172 (defn- read-vector
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
173 [rdr _ opts]
174 (read-delimited \] rdr opts))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
175
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
176 (defn- read-map
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
177 [rdr _ opts]
178 (let [l (to-array (read-delimited \} rdr opts))]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
179 (when (== 1 (bit-and (alength l) 1))
180 (reader-error rdr "Map literal must contain an even number of forms"))
29d0dce @Bronsa remove line/column info from EDN reader
Bronsa authored
181 (RT/map l)))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
182
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
183 (defn- read-number
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
184 [reader initch opts]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
185 (loop [sb (doto (StringBuilder.) (.append initch))
186 ch (read-char reader)]
187 (if (or (whitespace? ch) (macros ch) (nil? ch))
188 (let [s (str sb)]
189 (unread reader ch)
190 (or (match-number s)
191 (reader-error reader "Invalid number format [" s "]")))
192 (recur (doto sb (.append ch)) (read-char reader)))))
193
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
194 (defn- escape-char [sb rdr]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
195 (let [ch (read-char rdr)]
196 (case ch
197 \t "\t"
198 \r "\r"
199 \n "\n"
200 \\ "\\"
201 \" "\""
202 \b "\b"
203 \f "\f"
204 \u (let [ch (read-char rdr)]
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
205 (if (== -1 (Character/digit (char ch) 16))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
206 (reader-error rdr "Invalid unicode escape: \\u" ch)
207 (read-unicode-char rdr ch 16 4 true)))
208 \x (let [ch (read-char rdr)]
67c2978 @Bronsa removed primitive hinting in favour of casting functions for clojure …
Bronsa authored
209 (if (== -1 (Character/digit (char ch) 16))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
210 (reader-error rdr "Invalid unicode escape: \\x" ch)
211 (read-unicode-char rdr ch 16 2 true)))
212 (if (numeric? ch)
213 (let [ch (read-unicode-char rdr ch 8 3 false)]
214 (if (> (int ch) 0337)
215 (reader-error rdr "Octal escape sequence must be in range [0, 377]")
216 ch))
217 (reader-error rdr "Unsupported escape character: \\" ch)))))
218
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
219 (defn- read-string*
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
220 [reader _ opts]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
221 (loop [sb (StringBuilder.)
222 ch (read-char reader)]
223 (case ch
224 nil (reader-error reader "EOF while reading string")
225 \\ (recur (doto sb (.append (escape-char sb reader)))
226 (read-char reader))
227 \" (str sb)
228 (recur (doto sb (.append ch)) (read-char reader)))))
229
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
230 (defn- read-symbol
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
231 [rdr initch]
232 (when-let [token (read-token rdr initch)]
29d0dce @Bronsa remove line/column info from EDN reader
Bronsa authored
233 (case token
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
234
29d0dce @Bronsa remove line/column info from EDN reader
Bronsa authored
235 ;; special symbols
236 "nil" nil
237 "true" true
238 "false" false
239 "/" '/
240 "NaN" Double/NaN
241 "-Infinity" Double/NEGATIVE_INFINITY
242 ("Infinity" "+Infinity") Double/POSITIVE_INFINITY
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
243
29d0dce @Bronsa remove line/column info from EDN reader
Bronsa authored
244 (or (when-let [p (parse-symbol token)]
245 (symbol (p 0) (p 1)))
246 (reader-error rdr "Invalid token: " token)))))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
247
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
248 (defn- read-keyword
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
249 [reader initch opts]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
250 (let [ch (read-char reader)]
251 (if-not (whitespace? ch)
252 (let [token (read-token reader ch)
253 s (parse-symbol token)]
254 (if (and s (== -1 (.indexOf token "::")))
255 (let [^String ns (s 0)
256 ^String name (s 1)]
257 (if (identical? \: (nth token 0))
258 (reader-error reader "Invalid token: :" token) ;; no ::keyword in edn
259 (keyword ns name)))
260 (reader-error reader "Invalid token: :" token)))
261 (reader-error reader "Invalid token: :"))))
262
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
263 (defn- wrapping-reader
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
264 [sym]
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
265 (fn [rdr _ opts]
459f45a @Bronsa pass opts where missing
Bronsa authored
266 (list sym (read rdr true nil opts))))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
267
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
268 (defn- read-meta
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
269 [rdr _ opts]
459f45a @Bronsa pass opts where missing
Bronsa authored
270 (let [m (desugar-meta (read rdr true nil opts))]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
271 (when-not (map? m)
272 (reader-error rdr "Metadata must be Symbol, Keyword, String or Map"))
459f45a @Bronsa pass opts where missing
Bronsa authored
273 (let [o (read rdr true nil opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
274 (if (instance? IMeta o)
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
275 (with-meta o (merge (meta o) m))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
276 (reader-error rdr "Metadata can only be applied to IMetas")))))
277
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
278 (defn- read-set
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
279 [rdr _ opts]
280 (PersistentHashSet/createWithCheck (read-delimited \} rdr opts)))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
281
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
282 (defn- read-discard
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
283 [rdr _ opts]
284 (read rdr true nil opts)
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
285 rdr)
286
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
287 (defn- macros [ch]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
288 (case ch
289 \" read-string*
290 \: read-keyword
291 \; read-comment
292 \^ read-meta
293 \( read-list
294 \) read-unmatched-delimiter
295 \[ read-vector
296 \] read-unmatched-delimiter
297 \{ read-map
298 \} read-unmatched-delimiter
299 \\ read-char*
300 \# read-dispatch
301 nil))
302
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
303 (defn- dispatch-macros [ch]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
304 (case ch
305 \^ read-meta ;deprecated
306 \{ read-set
307 \< (throwing-reader "Unreadable form")
308 \! read-comment
309 \_ read-discard
310 nil))
311
f8b7c37 @Bronsa made implementation functions private
Bronsa authored
312 (defn- read-tagged [rdr initch opts]
459f45a @Bronsa pass opts where missing
Bronsa authored
313 (let [tag (read rdr true nil opts)
314 object (read rdr true nil opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
315 (if-not (symbol? tag)
316 (reader-error rdr "Reader tag must be a symbol"))
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
317 (if-let [f (or (get (:readers opts) tag)
e797fde @Bronsa fixed read-tagged in EDN reader, moved away default-data-reader-fn fr…
Bronsa authored
318 (default-data-readers tag))]
319 (f object)
320 (if-let [d (:default opts)]
321 (d tag object)
322 (reader-error rdr "No reader function for tag " (name tag))))))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
323
324 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
325 ;; Public API
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
326 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
327
328 (defn read
329 "Reads the first object from an IPushbackReader or a java.io.PushbackReader.
1541a4b @Bronsa Added comprehensive docstrings
Bronsa authored
330 Returns the object read. If EOF, throws if eof-error? is true otherwise returns eof.
331 If no reader is provided, *in* will be used.
332
333 Reads data in the edn format (subset of Clojure data):
334 http://edn-format.org
335
336 clojure.tools.reader.edn/read doesn't depend on dynamic Vars, all configuration
337 is done by passing an opt map.
338
339 opts is a map that can include the following keys:
340 :eof - value to return on end-of-file. When not supplied, eof throws an exception.
341 :readers - a map of tag symbols to data-reader functions to be considered before default-data-readers.
342 When not supplied, only the default-data-readers will be used.
343 :default - A function of two args, that will, if present and no reader is found for a tag,
344 be called with the tag and the value."
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
345 ([] (read *in*))
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
346 ([reader] (read {} reader))
347 ([{:keys [eof] :as opts} reader]
348 (let [eof-error? (not (contains? opts :eof))]
349 (read reader eof-error? eof opts)))
350 ([reader eof-error? eof opts]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
351 (try
352 (let [ch (read-char reader)]
353 (cond
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
354 (whitespace? ch) (read opts reader)
355 (nil? ch) (if eof-error? (reader-error reader "EOF") eof)
459f45a @Bronsa pass opts where missing
Bronsa authored
356 (number-literal? reader ch) (read-number reader ch opts)
357 (comment-prefix? ch) (read opts (read-comment reader ch opts))
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
358 :else (let [f (macros ch)]
359 (if f
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
360 (let [res (f reader ch opts)]
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
361 (if (identical? res reader)
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
362 (read opts reader)
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
363 res))
364 (read-symbol reader ch)))))
365 (catch Exception e
1d05a02 @Bronsa decouple from clojure's vars (*read-eval*, *default-data-reader-fn*, …
Bronsa authored
366 (if (ex-info? e)
e33881a @Bronsa clojure.tools.reader.edn: add an edn-only reader implementation
Bronsa authored
367 (throw e)
368 (throw (ex-info (.getMessage e)
369 (merge {:type :reader-exception}
370 (if (indexing-reader? reader)
371 {:line (get-line-number reader)
372 :column (get-column-number reader)}))
373 e)))))))
374
375 (defn read-string
1541a4b @Bronsa Added comprehensive docstrings
Bronsa authored
376 "Reads one object from the string s.
377 Returns nil when s is nil or empty.
378
379 Reads data in the edn format (subset of Clojure data):
380 http://edn-format.org
381
382 opts is a map as per clojure.tools.reader.edn/read"
1d05a02 @Bronsa decouple from clojure's vars (*read-eval*, *default-data-reader-fn*, …
Bronsa authored
383 ([s] (read-string {:eof nil} s))
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
384 ([opts s]
1211d85 @Bronsa fix docstring position
Bronsa authored
385 (when (and s (not (identical? s "")))
9766ae0 @Bronsa Update both readers to clojure HEAD
Bronsa authored
386 (read opts (string-push-back-reader s)))))
Something went wrong with that request. Please try again.