This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-23
Channels
- # announcements (5)
- # babashka (22)
- # beginners (240)
- # calva (51)
- # clj-commons (1)
- # cljsrn (9)
- # clojars (12)
- # clojure (81)
- # clojure-australia (2)
- # clojure-europe (40)
- # clojure-france (10)
- # clojure-italy (1)
- # clojure-nl (2)
- # clojure-uk (37)
- # clojurescript (59)
- # clojureverse-ops (2)
- # copenhagen-clojurians (1)
- # cursive (9)
- # datomic (18)
- # emacs (12)
- # fulcro (24)
- # graalvm (48)
- # hyperfiddle (5)
- # introduce-yourself (1)
- # jackdaw (1)
- # jobs (2)
- # juxt (8)
- # lsp (25)
- # malli (8)
- # missionary (1)
- # music (3)
- # off-topic (32)
- # polylith (16)
- # quil (4)
- # re-frame (52)
- # reitit (5)
- # reveal (3)
- # rewrite-clj (26)
- # rum (1)
- # sci (1)
- # shadow-cljs (14)
- # sql (2)
- # tools-build (40)
- # tools-deps (14)
- # vrac (2)
- # xtdb (63)
so the use case I’ve got for rewrite-edn is that I want to update a config file while preserving formatting, and config uses aero and integrant which use reader tags
I’m guessing that #ig/ref :bar
ending up as (read-string "#ig/ref :bar")
is meant for it to get evaluated in the environment
but in my case I really just need to leave it as is, so I’m thinking the best approach might be to have a function to serialize to string and handle this case there
Hi @yogthos. This is an interesting issue.
$ bb -e '(rewrite-clj.node/sexpr (rewrite-clj.parser/parse-string "#foo {:a 1}"))'
(read-string "#foo {:a 1}")
It seems rewrite-clj behaves like this and it just manifests in rewrite-edn as well. Perhaps the stringification of the node isn't very accuratewhereas:
$ bb -e '(str (rewrite-clj.parser/parse-string "#foo {:a 1}"))'
"#foo {:a 1}"
The issue here might be that there is no way to make this into a s-expr without making up some kind of thing
Ya I noticed that rewrite-clj’s sexpr
will sometimes return (read-string...)
https://github.com/clj-commons/rewrite-clj/blob/main/doc/01-user-guide.adoc#reader-macro-chars…
because the reader normally turns this into a s-expr but for this you need to actually execute the reader tag function
should rewrite-clj be able to get an :readers option which will actually execute the function?
like this for example:
$ bb -e '(rewrite-clj.node/sexpr (rewrite-clj.parser/parse-string "#foo {:a 1}") {:readers {(quote foo) identity}})'
(read-string "#foo {:a 1}")
So, being a bit slow , I’m not sure I understand yet. Are we talking about this?: code as text -> rewrite-clj node -> clojure form -> rewrite-clj node -> code as text?
Sexpr in rewrite-clj is… nuanced… can work… but there are real limitations. Is it possible to work from rewrite-clj nodes only, or is using rewrite-clj’s sexpr
necessary for this use case?
so yeah looks like I can just skip that step and everything works as intended, e.g:
(let [zloc (-> (slurp "system.edn") (rewrite-edn/parse-string))
child (rewrite-edn/parse-string "{:label "ig/ref", :value ":system/env"}")]
(str (rewrite-edn/assoc-in zloc [:router/core] child)))