[#284] Add read-string
This commit is contained in:
parent
91a273034a
commit
aa4139931e
4 changed files with 22 additions and 8 deletions
|
|
@ -1,8 +1,10 @@
|
|||
(ns babashka.impl.clojure.core
|
||||
{:no-doc true}
|
||||
(:refer-clojure :exclude [future])
|
||||
(:refer-clojure :exclude [future read read-string])
|
||||
(:require [borkdude.graal.locking :as locking]
|
||||
[sci.impl.namespaces :refer [copy-core-var]]))
|
||||
[clojure.tools.reader.reader-types :as r]
|
||||
[sci.impl.namespaces :refer [copy-core-var]]
|
||||
[sci.impl.parser :as parser]))
|
||||
|
||||
(defn locking* [form bindings v f & args]
|
||||
(apply @#'locking/locking form bindings v f args))
|
||||
|
|
@ -16,6 +18,12 @@
|
|||
(prn (str "Elapsed time: " (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs"))
|
||||
ret#))
|
||||
|
||||
(defn read-string
|
||||
([sci-ctx s]
|
||||
(let [reader (r/indexing-push-back-reader (r/push-back-reader s))]
|
||||
(parser/parse-next sci-ctx reader)))
|
||||
#_([opts s] (clojure.lang.RT/readString s opts)))
|
||||
|
||||
(def core-extras
|
||||
{'file-seq (copy-core-var file-seq)
|
||||
'agent agent
|
||||
|
|
@ -27,6 +35,7 @@
|
|||
'locking (with-meta locking* {:sci/macro true})
|
||||
'shutdown-agents shutdown-agents
|
||||
'slurp (copy-core-var slurp)
|
||||
'read-string (with-meta read-string {:sci.impl/op :needs-ctx})
|
||||
'spit (copy-core-var spit)
|
||||
'time (with-meta time* {:sci/macro true})
|
||||
'Throwable->map Throwable->map
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@
|
|||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[clojure.tools.reader.reader-types :as r]
|
||||
[sci.impl.interpreter :refer [eval-form]]
|
||||
[sci.impl.parser :as parser]
|
||||
[sci.impl.vars :as vars]
|
||||
[sci.core :as sci]
|
||||
[sci.impl.io :as sio]))
|
||||
[sci.impl.interpreter :refer [eval-form]]
|
||||
[sci.impl.io :as sio]
|
||||
[sci.impl.parser :as parser]
|
||||
[sci.impl.vars :as vars]))
|
||||
|
||||
(defn repl-caught
|
||||
"Default :caught hook for repl"
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
[clojure.string :as str]
|
||||
[sci.addons :as addons]
|
||||
[sci.core :as sci]
|
||||
[sci.impl.interpreter :refer [eval-string*]]
|
||||
[sci.impl.interpreter :refer [eval-string* eval-form]]
|
||||
[sci.impl.opts :as sci-opts]
|
||||
[sci.impl.unrestrict :refer [*unrestricted*]]
|
||||
[sci.impl.vars :as vars])
|
||||
|
|
@ -211,7 +211,7 @@ Everything after that is bound to *command-line-args*."))
|
|||
(eval-string* sci-ctx s))))
|
||||
|
||||
(defn eval* [sci-ctx form]
|
||||
(eval-string* sci-ctx (pr-str form)))
|
||||
(eval-form sci-ctx form))
|
||||
|
||||
(defn start-socket-repl! [address ctx]
|
||||
(socket-repl/start-repl! address ctx)
|
||||
|
|
|
|||
|
|
@ -346,6 +346,11 @@
|
|||
(testing "writer"
|
||||
(is (string? (bb nil "(let [sw (java.io.StringWriter.)] (clojure.pprint/pprint (range 10) sw) (str sw))")))))
|
||||
|
||||
(deftest read-string-test
|
||||
(testing "namespaced keyword via alias"
|
||||
(is (= :clojure.string/foo
|
||||
(bb nil "(ns foo (:require [clojure.string :as str])) (read-string \"::str/foo\")")))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
(comment
|
||||
|
|
|
|||
Loading…
Reference in a new issue