Fork me on GitHub
#rewrite-clj
<
2020-10-10
>
sogaiu13:10:40

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

borkdude13:10:35

not really no, just a means to an end

sogaiu13:10:25

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.

borkdude13:10:06

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

sogaiu13:10:00

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

sogaiu13:10:00

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

sogaiu13:10:24

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

sogaiu13:10:36

parcera currently outputs to hiccup.

borkdude13:10:37

does parcera support the enlive format?

sogaiu13:10:54

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

borkdude13:10:21

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

borkdude13:10:46

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

borkdude13:10:07

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

sogaiu13:10:17

yes, that make sense

sogaiu13:10:21

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

borkdude13:10:02

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

borkdude13:10:33

npm doesn't support it either

sogaiu13:10:51

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 😛

sogaiu13:10:08

i think that's a json limitation iiuc

borkdude13:10:08

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

sogaiu13:10:53

that isn't really a solution imo

sogaiu13:10:07

anyway, this is off of the main point 🙂

borkdude13:10:10

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

borkdude13:10:18

But I don't think that's nice either

borkdude13:10:42

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

sogaiu13:10:03

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

sogaiu13:10:09

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

sogaiu13:10:31

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

borkdude13:10:21

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

borkdude13:10:53

doesn't sound too difficult

borkdude13:10:05

yes, rewrite-cljc supports discard forms

borkdude13:10:44

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

borkdude13:10:59

PRs welcome.

sogaiu13:10:24

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

borkdude13:10:56

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

borkdude13:10:07

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

sogaiu13:10:52

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

borkdude13:10:16

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

sogaiu13:10:40

rearrange-clj

borkdude13:10:43

rewrite-edn

sogaiu13:10:49

ah i like that one

sogaiu13:10:33

off to sleep -- good luck!

borkdude13:10:26

thanks!

👋 3
borkdude13:10:49

have a good night sleep

borkdude15:10:40

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

borkdude15:10:21

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

borkdude15:10:12

I guess it makes sense

lread19:10:43

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

borkdude15:10:24

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 :)

lread19:10:17

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

borkdude19:10:59

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

borkdude19:10:17

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

borkdude19:10:02

but coerce will indeed create one I guess

borkdude19:10:15

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

lread22:10:27

ya dunno really, just a thought for something to check

lread19:10:15

Cool, looking forward to studying this!