Welcome! Please see the About page for a little more info on how this works.

+1 vote
in ClojureScript by
edited by
 => (cljs.reader/read-string "(re-matches #\".*ClojureScript \\d+\\.\\d+\\.\\d+ (.*)$\")")

Error: Unsupported escape character: \d.
    at new cljs$core$ExceptionInfo (/js/cljs-runtime/cljs.core.js:37198:10)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (/js/cljs-runtime/cljs.core.js:37259:9)
    at Function.eval [as cljs$core$IFn$_invoke$arity$2] (/js/cljs-runtime/cljs.core.js:37255:26)
    at Function.eval [as cljs$core$IFn$_invoke$arity$variadic] (/js/cljs-runtime/cljs.tools.reader.impl.errors.js:52:25)
    at Function.eval [as cljs$core$IFn$_invoke$arity$variadic] (/js/cljs-runtime/cljs.tools.reader.impl.errors.js:92:47)
    at Object.cljs$tools$reader$impl$errors$throw_bad_escape_char [as throw_bad_escape_char] (/js/cljs-runtime/cljs.tools.reader.impl.errors.js:321:51)
    at Object.cljs$tools$reader$edn$escape_char [as escape_char] (/js/cljs-runtime/cljs.tools.reader.edn.js:470:38)
    at eval (/js/cljs-runtime/cljs.tools.reader.edn.js:485:39)
    at cljs$tools$reader$edn$read_string_STAR_ (/js/cljs-runtime/cljs.tools.reader.edn.js:488:3)

But same input in clojure :

=> (read-string "(re-matches #\".*ClojureScript \\d+\\.\\d+\\.\\d+ (.*)$\")")

(re-matches #".*ClojureScript \d+\.\d+\.\d+ (.*)$")

Also :

(cljs.reader/read-string "(re-matches #\"hello\")")

doesn't read with cljs.reader/read-string while it reads with clojure read-string

1 Answer

+3 votes
selected by
Best answer

cljs.reader is a pure EDN reader. Regexes (ie. #"") are not part of EDN so they fail to read. It also fails when using clojure.edn/read-string. You can use tools-reader directly if you want to read source code.

Thank Thomas! Is there anything to read clojure code in clojurescript?
Yes, see the org.clojure/tools.reader package and the cljs.tools.reader namespace. Always available when using ClojureScript since ClojureScript itself uses it.