Merge pull request #34 from jolt-lang/fix-edn-regression
Fix strict-map? regression in clojure.edn; apply EDN built-in tags
This commit is contained in:
commit
d0c605ac9d
3 changed files with 19 additions and 5 deletions
|
|
@ -10,10 +10,15 @@
|
||||||
;; maps/vectors/lists. (Lists stay lists — EDN never evaluates them as code.)
|
;; maps/vectors/lists. (Lists stay lists — EDN never evaluates them as code.)
|
||||||
(defn- edn->value [x]
|
(defn- edn->value [x]
|
||||||
(cond
|
(cond
|
||||||
(and (map? x) (= :jolt/set (get x :jolt/type))) (set (map edn->value (get x :value)))
|
;; Reader FORMS are detected by :jolt/type tag, never by map? — strict map?
|
||||||
;; Only untagged structs are real maps; symbols/chars/tagged literals are also
|
;; (correctly) excludes tagged structs, so the old (and (map? x) ...) guard
|
||||||
;; struct? (=> map?) but carry a :jolt/type and must pass through unchanged.
|
;; would skip them.
|
||||||
(and (map? x) (nil? (get x :jolt/type)))
|
(= :jolt/set (get x :jolt/type)) (set (map edn->value (get x :value)))
|
||||||
|
;; EDN built-in tagged elements (#uuid/#inst, plus registered readers):
|
||||||
|
;; apply the data reader to the read form (no evaluation involved).
|
||||||
|
(= :jolt/tagged (get x :jolt/type))
|
||||||
|
(__read-tagged (get x :tag) (edn->value (get x :form)))
|
||||||
|
(map? x)
|
||||||
(into {} (map (fn [e] [(edn->value (key e)) (edn->value (val e))]) x))
|
(into {} (map (fn [e] [(edn->value (key e)) (edn->value (val e))]) x))
|
||||||
(vector? x) (mapv edn->value x)
|
(vector? x) (mapv edn->value x)
|
||||||
(seq? x) (map edn->value x)
|
(seq? x) (map edn->value x)
|
||||||
|
|
|
||||||
|
|
@ -1112,6 +1112,15 @@
|
||||||
the-form))
|
the-form))
|
||||||
the-form)))
|
the-form)))
|
||||||
(ns-intern core "macroexpand-1" expand-1)
|
(ns-intern core "macroexpand-1" expand-1)
|
||||||
|
# Apply a registered data reader to an already-read form (EDN built-in tags
|
||||||
|
# #uuid/#inst and any registered reader). Throws on an unknown tag.
|
||||||
|
(ns-intern core "__read-tagged"
|
||||||
|
(fn [tag form]
|
||||||
|
(def data-readers (get (ctx :env) :data-readers))
|
||||||
|
(def reader-fn (if data-readers (get data-readers tag)))
|
||||||
|
(if reader-fn
|
||||||
|
(reader-fn form)
|
||||||
|
(error (string "No reader function for tag " tag)))))
|
||||||
# macroexpand: expand repeatedly until the head is no longer a macro (the
|
# macroexpand: expand repeatedly until the head is no longer a macro (the
|
||||||
# form's SUBFORMS are not expanded, matching Clojure).
|
# form's SUBFORMS are not expanded, matching Clojure).
|
||||||
(ns-intern core "macroexpand"
|
(ns-intern core "macroexpand"
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
# clojure.edn reads via clojure.core/read-string (opts/:eof + nil/blank) and
|
# clojure.edn reads via clojure.core/read-string (opts/:eof + nil/blank) and
|
||||||
# constructs set/nested values. Only #uuid remains (no real uuid type) —
|
# constructs set/nested values. Only #uuid remains (no real uuid type) —
|
||||||
# jolt-b7y. Guard the passing subset.
|
# jolt-b7y. Guard the passing subset.
|
||||||
["clojure/edn_test/read_string.cljc" 49 false]])
|
["clojure/edn_test/read_string.cljc" 50 false]])
|
||||||
|
|
||||||
(def root "test/clojure-stdlib")
|
(def root "test/clojure-stdlib")
|
||||||
(def per-file-timeout 6)
|
(def per-file-timeout 6)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue