reader: feature set #{:jolt :default}, clause-order matching (RFC 0002)
jolt no longer satisfies :clj in reader conditionals. The shortcut was a measured net liability: :clj branches carry JVM interop and JVM-specific test expectations jolt fails, and they shadowed :default branches jolt passes. A/B over the suite: clj,default = 4967 assertions / 4324 pass / 119 errors; jolt,default = 5069 / 4470 / 81 (+146 pass, -38 errors, +8 clean files). Baselines raised to 4470/86. Matching is now by CLAUSE order like Clojure — the first clause whose key is in the feature set wins (#?(:default 5 :clj 6) is 5 everywhere); the old code scanned for :clj first, then :default, regardless of position. Foreign clj-targeted libraries are a property of the LOADING CONTEXT, not the platform: reader-features-set! opts a load into a compatibility set, and the SCI bootstrap/runtime tests load SCI under ["jolt" "clj" "default"] (its .cljc selects implementations via :clj with no :jolt branches). JOLT_FEATURES remains the process-wide override. RFC 0002 records the decision with the measured data; spec 02-reader S18 is now normative (clause order, documented feature set, per-context override). Reader tests updated to the portable set + an opt-in round-trip.
This commit is contained in:
parent
2224e40afc
commit
fdfd086df6
8 changed files with 164 additions and 33 deletions
|
|
@ -123,18 +123,23 @@
|
|||
(let [[form2 _] (parse-next rest-str)]
|
||||
(assert (deep= [3 4] form2) "second form is vector")))
|
||||
|
||||
# Reader conditional — resolves :clj branch at read time
|
||||
(assert (= 1 (parse-string "#?(:clj 1 :cljs 2)"))
|
||||
"#?(:clj) picks :clj branch")
|
||||
# Reader conditional — feature set is #{:jolt :default} (spec 02-reader S18,
|
||||
# RFC 0002); matching is by clause order. reader-features-set! lets a loading
|
||||
# context opt a clj-targeted library into :clj compat (restored below).
|
||||
(assert (= 3 (parse-string "#?(:clj 1 :jolt 3 :cljs 2)"))
|
||||
"#?(...) picks :jolt branch")
|
||||
(assert (= nil (parse-string "#?(:cljs 999)"))
|
||||
"#?(:cljs) returns nil on CLJ")
|
||||
(assert (= 42 (parse-string "#?(:clj 42)"))
|
||||
"#?(:clj) with single branch")
|
||||
(assert (deep= (sym "clj-only") (parse-string "#?(:clj clj-only :cljs cljs-only)"))
|
||||
"#?(:clj) picks :clj symbol")
|
||||
# Nested inside a list — :clj branch is evaluated at read time
|
||||
(assert (deep= @[(sym "+") 1 3] (parse-string "(+ 1 #?(:clj 3 :cljs 4))"))
|
||||
"#? inside list picks :clj")
|
||||
"unmatched conditional reads as nothing")
|
||||
(assert (= 7 (parse-string "#?(:clj 1 :default 7)"))
|
||||
":default reached when :clj not in feature set")
|
||||
(assert (= 5 (parse-string "#?(:default 5 :jolt 6)"))
|
||||
"clause order wins, not key priority")
|
||||
(assert (deep= @[(sym "+") 1 3] (parse-string "(+ 1 #?(:jolt 3 :cljs 4))"))
|
||||
"#? inside list picks :jolt")
|
||||
(let [prev (reader-features-set! ["jolt" "clj" "default"])]
|
||||
(assert (= 1 (parse-string "#?(:clj 1 :cljs 2)"))
|
||||
"clj-compat opt-in picks :clj")
|
||||
(reader-features-set! (keys prev)))
|
||||
|
||||
# Characters — the reader now produces char values {:jolt/type :jolt/char :ch N}
|
||||
(let [form (parse-string "\\newline")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue