Serializing and de-serializing Clojure code as EDN

I am trying to use standard serialization for Clojure code that will ignore spaces, comments, etc. I was thinking of using EDN for this.

According to what I read, the standard way to serialize s-expressions for EDN is that pr-strwhich seems to work well with most Clojure constructs. However, this does not seem to work so well for code containing regular expressions (using a hash string reader macro, for example #"\d+").

user=> (pr-str '#"\d")
"#\"\\d\""

user=> (edn/read-string (pr-str '#"\d"))

RuntimeException No dispatch macro for: "  Clojure.lang.Util.runtimeException (Util.java:221)

I am using Clojure 1.8.0.

Any suggestions?

Thank!

EDIT: Thanks for your answers and comments. The reason I wanted to use EDN for starters was because I want to handle untrusted code.

, ( Clojure ), , , Clojure, "", , . load-file, , read-string - .

+4
1

Clojure EDN, Clojure. pr-str Clojure, , String. RuntimeException escaped ", EDN #.

(clojure.core/read-string (pr-str #"\d")) ;=> #"\d"
0

Source: https://habr.com/ru/post/1670214/


All Articles