diff --git a/project.clj b/project.clj index 2f1aaa7a..6783b7d9 100644 --- a/project.clj +++ b/project.clj @@ -10,7 +10,7 @@ :java-source-paths ["src-java"] :source-paths ["src"] :dependencies [[org.clojure/clojure "1.9.0"] - [borkdude/edamame "0.0.7"] + [borkdude/edamame "0.0.8-alpha.2"] [org.clojure/tools.reader "1.3.2"]] :aot [sci.impl.java] :profiles {:clojure-1.9.0 {:dependencies [[org.clojure/clojure "1.9.0"]]} diff --git a/src/sci/core.cljc b/src/sci/core.cljc index 6b6d8f44..44fe8af5 100644 --- a/src/sci/core.cljc +++ b/src/sci/core.cljc @@ -29,7 +29,9 @@ - `:preset`: a pretermined set of options. Currently only `:termination-safe` is supported, which will set `:realize-max` to - `100` and disallows the symbols `loop`, `recur` and `trampoline`." + `100` and disallows the symbols `loop`, `recur` and `trampoline`. + + - `:features`: when provided a non-empty set of keywords, sci will process reader conditionals using these features (e.g. #{:bb})." ([s] (eval-string s nil)) ([s opts] (i/eval-string s opts))) diff --git a/src/sci/impl/interpreter.cljc b/src/sci/impl/interpreter.cljc index 968e6b73..91f115f4 100644 --- a/src/sci/impl/interpreter.cljc +++ b/src/sci/impl/interpreter.cljc @@ -366,7 +366,8 @@ ([s] (eval-string s nil)) ([s opts] (let [init-ctx (opts->ctx opts) - edn-vals (p/parse-string-all s) + features (:features opts) + edn-vals (p/parse-string-all s features) ret (eval-edn-vals init-ctx edn-vals)] ret))) diff --git a/src/sci/impl/parser.cljc b/src/sci/impl/parser.cljc index c7e2bd0f..e7a1ffaa 100644 --- a/src/sci/impl/parser.cljc +++ b/src/sci/impl/parser.cljc @@ -24,8 +24,13 @@ (defn parse-string [s] (edamame/parse-string s opts)) -(defn parse-string-all [s] - (edamame/parse-string-all s opts)) +(defn parse-string-all + ([s] + (edamame/parse-string-all s opts)) + ([s features] + (edamame/parse-string-all s (assoc opts + :read-cond :allow + :features features)))) ;;;; Scratch diff --git a/test/sci/core_test.cljc b/test/sci/core_test.cljc index 7077ffa4..6e2cd596 100644 --- a/test/sci/core_test.cljc +++ b/test/sci/core_test.cljc @@ -449,6 +449,10 @@ (is (= [1 2] (eval* "(declare foo bar) (defn f [] [foo bar]) (def foo 1) (def bar 2) (f)"))) (is (= 1 (eval* "(def x 1) (declare x) x")))) +(deftest reader-conditionals + (is (= 6 (tu/eval* "(+ 1 2 #?(:bb 3 :clj 100))" {:features #{:bb}}))) + (is (= 103 (tu/eval* "(+ 1 2 #?(:bb 3 :clj 100))" {:features #{:clj}})))) + ;;;; Scratch (comment