rewrite-clj

https://github.com/clj-commons/rewrite-clj
borkdude 2020-10-10T13:05:49.002Z

2020-10-10T13:17:40.009200Z

asking for clarficiation here -- "on top of rewrite-clj" is a requirement, right?

borkdude 2020-10-10T13:24:35.009500Z

not really no, just a means to an end

2020-10-10T13:32:25.012400Z

parcera doesn't have an existing layer that i know of, but round-tripping is an explicit goal so iiuc it does the preservation thing pretty well. i have used it for something where those things were important.

borkdude 2020-10-10T13:33:06.013300Z

I don't see the benefit of parcera vs rewrite-clj for this

2020-10-10T13:34:00.013700Z

not making any claims about what's better, just bringing up options.

2020-10-10T13:35:00.014400Z

on a possibly relatede note, there is this interesting paragraph in the instaparse readme: > I find the hiccup format to be pleasant and compact, especially when working with the parsed output in the REPL. The main advantage of the enlive format is that it allows you to use the very powerful enlive library to select and transform nodes in your tree. https://github.com/Engelberg/instaparse#output-format

2020-10-10T13:35:24.015300Z

the reason i mention that is the so-called enlive format and the select / transform stuff.

2020-10-10T13:35:36.015800Z

parcera currently outputs to hiccup.

borkdude 2020-10-10T13:35:37.016Z

does parcera support the enlive format?

2020-10-10T13:35:54.016600Z

it's a todo-ish thing, but iiuc, hiccup can be converted to enlive format (and i presume the reverse is possible too).

borkdude 2020-10-10T13:36:21.017500Z

someone in #off-topic suggested tools.reader could be patched to return ordered maps. I think I could support that in edamame, and just ignore whitespace/comments

2020-10-10T13:36:34.017800Z

cool

borkdude 2020-10-10T13:37:46.018600Z

the use case is config files for glam (package manager): glam itself and the user should both be able to write to the config file

borkdude 2020-10-10T13:38:07.019Z

but I don't want to depend on the funky default ordering of clojure maps to write back

2020-10-10T13:38:17.019300Z

yes, that make sense

2020-10-10T13:40:21.020700Z

not sure i followed whether you were or were not going to try to support comment preservation.

borkdude 2020-10-10T13:42:02.021Z

I'm willing to drop that requirement, if it saves me hours of work

borkdude 2020-10-10T13:42:33.021800Z

npm doesn't support it either

2020-10-10T13:42:51.022200Z

ah i see. i hope that if you do, you would eventually consider trying to support comments. i was going to say i really dislike not being able to put comments in package.json 😛

2020-10-10T13:43:08.022400Z

i think that's a json limitation iiuc

borkdude 2020-10-10T13:45:08.022800Z

yep, they usually solve it by "comment": "hello"

2020-10-10T13:45:38.023300Z

yeah, much discussion like this: https://stackoverflow.com/questions/244777/can-comments-be-used-in-json

2020-10-10T13:45:53.023800Z

that isn't really a solution imo

2020-10-10T13:46:07.024100Z

anyway, this is off of the main point 🙂

borkdude 2020-10-10T13:47:10.024900Z

One other solution I was considering: have one user.edn config and one machine.edn config and one config.edn which is the merged one of those two

borkdude 2020-10-10T13:47:18.025100Z

But I don't think that's nice either

borkdude 2020-10-10T13:47:42.025400Z

maybe I'll just have to bite the bullet and write the rewrite-cljc based lib

2020-10-10T13:48:03.026Z

i wonder if one could use discard forms for commenting...

2020-10-10T13:48:09.026400Z

i think i see this in random source from time to time

2020-10-10T13:48:31.027Z

i don't remember if rewrite-clj does discard stuff

2020-10-10T13:48:43.027300Z

it must

borkdude 2020-10-10T13:49:21.027900Z

(lib/assoc node :b 1)
;; =>
(map-node ... children with child :b replaced with (token-node 1))

borkdude 2020-10-10T13:49:53.028200Z

doesn't sound too difficult

borkdude 2020-10-10T13:50:05.028500Z

yes, rewrite-cljc supports discard forms

borkdude 2020-10-10T13:50:44.029200Z

ah, screw it, I'll start with the lib

2020-10-10T13:50:48.029500Z

lol

2020-10-10T13:50:51.029700Z

sorry

borkdude 2020-10-10T13:50:59.029900Z

PRs welcome.

2020-10-10T13:51:04.030100Z

ha ha ha

2020-10-10T13:51:24.030600Z

well i have submitted a few in the past, right?

borkdude 2020-10-10T13:51:56.031Z

any suggestions for a name? rewrite-cljc-core-ops?

borkdude 2020-10-10T13:52:07.031300Z

yes, you have, I'm grateful for your contribs :)

2020-10-10T13:52:52.031900Z

naming is hard...sorry no good ideas atm.

borkdude 2020-10-10T13:53:16.032400Z

the use case would be merging EDN files while preserving formatting. edn-something could also work

2020-10-10T13:53:40.032700Z

rearrange-clj

borkdude 2020-10-10T13:53:43.032900Z

rewrite-edn

2020-10-10T13:53:43.033Z

😜

2020-10-10T13:53:49.033200Z

ah i like that one

borkdude 2020-10-10T13:54:04.033400Z

ok

2020-10-10T13:54:33.033600Z

off to sleep -- good luck!

borkdude 2020-10-10T13:55:26.033900Z

thanks!

👋 1
borkdude 2020-10-10T13:55:49.034200Z

have a good night sleep

borkdude 2020-10-10T15:05:40.034800Z

@lee hmm, when I make a zipper of a map-node and then do z/root, I get back a forms node.

borkdude 2020-10-10T15:06:21.035Z

user=> (z/root (z/edn (p/parse-string "{:a 1}")))
<forms: {:a 1}>

borkdude 2020-10-10T15:13:12.035200Z

I guess it makes sense

borkdude 2020-10-10T15:18:24.035800Z

today I learned about node/coerce... I should probably include that in the clj-kondo hooks API. why hasn't anyone asked for this before :)

borkdude 2020-10-10T15:27:15.036Z

ok, POC: https://github.com/borkdude/rewrite-edn

borkdude 2020-10-10T18:48:30.036400Z

Fully qualify dep symbols in deps.edn: https://github.com/borkdude/rewrite-edn#examples

lread 2020-10-10T19:49:43.036700Z

Ya, I think so. The forms node is an implicit do.

lread 2020-10-10T19:50:15.037300Z

Cool, looking forward to studying this!

lread 2020-10-10T19:52:17.037400Z

automatic coercion of metadata to metadata nodes is what caused me some grief when working with sci.

borkdude 2020-10-10T19:52:59.037600Z

ok. but the hooks code will never see a metadata node

borkdude 2020-10-10T19:53:17.037800Z

because clj-kondo already has processed them before (in the fork of rewrite-clj)

borkdude 2020-10-10T19:53:56.038Z

hmm

borkdude 2020-10-10T19:54:02.038200Z

but coerce will indeed create one I guess

borkdude 2020-10-10T19:54:15.038400Z

which is not what we want... ok , one good reason to not add it maybe

lread 2020-10-10T22:25:27.038600Z

ya dunno really, just a thought for something to check