|
| 1 | +;; Copyright (c) Rich Hickey. All rights reserved. |
| 2 | +;; The use and distribution terms for this software are covered by the |
| 3 | +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) |
| 4 | +;; which can be found in the file epl-v10.html at the root of this distribution. |
| 5 | +;; By using this software in any fashion, you are agreeing to be bound by |
| 6 | +;; the terms of this license. |
| 7 | +;; You must not remove this notice, or any other, from this software. |
| 8 | + |
| 9 | +(ns clojure.edn |
| 10 | + "edn reading. |
| 11 | +
|
| 12 | + This namespace provides alias for cljs.reader/read and cljs.reader/read-string. |
| 13 | + Thus Clojure and ClojureScript source can reference these functions in the same way. |
| 14 | + In Clojure, read and read-string may cause evaluation, |
| 15 | + but clojure.edn/read and clojure.edn/read-string will not. |
| 16 | + In ClojureScript cljs.reader/read and cljs.reader/read-string will not cause evaluation, |
| 17 | + they only read edn." |
| 18 | + (:require [cljs.reader :as reader])) |
| 19 | + |
| 20 | +(defn read |
| 21 | + "Reads the first object from an cljs.tools.reader.reader-types/IPushbackReader. |
| 22 | + Returns the object read. If EOF, throws if eof-error? is true otherwise returns eof. |
| 23 | + If no reader is provided, *in* will be used. |
| 24 | +
|
| 25 | + Reads data in the edn format (subset of Clojure data): |
| 26 | + http://edn-format.org |
| 27 | +
|
| 28 | + cljs.tools.reader.edn/read doesn't depend on dynamic Vars, all configuration |
| 29 | + is done by passing an opt map. |
| 30 | +
|
| 31 | + opts is a map that can include the following keys: |
| 32 | + :eof - value to return on end-of-file. When not supplied, eof throws an exception. |
| 33 | + :readers - a map of tag symbols to data-reader functions to be considered before default-data-readers. |
| 34 | + When not supplied, only the default-data-readers will be used. |
| 35 | + :default - A function of two args, that will, if present and no reader is found for a tag, |
| 36 | + be called with the tag and the value." |
| 37 | + ([reader] |
| 38 | + (reader/read reader)) |
| 39 | + ([opts reader] |
| 40 | + (reader/read opts reader)) |
| 41 | + ([reader eof-error? eof opts] |
| 42 | + (reader/read reader eof-error? eof opts))) |
| 43 | + |
| 44 | +(defn read-string |
| 45 | + "Reads one object from the string s. |
| 46 | + Returns nil when s is nil or empty. |
| 47 | +
|
| 48 | + Reads data in the edn format (subset of Clojure data): |
| 49 | + http://edn-format.org |
| 50 | +
|
| 51 | + opts is a map as per cljs.tools.reader.edn/read" |
| 52 | + ([s] |
| 53 | + (reader/read-string s)) |
| 54 | + ([opts s] |
| 55 | + (reader/read-string opts s))) |
0 commit comments