rewrite-clj

https://github.com/clj-commons/rewrite-clj
2020-08-11T12:06:10.104500Z

@lee btw, i've recently started to wonder a bit whether the way metadata is done currently in rewrite-clj* could be better in some cases compared to what some of us mentioned some time back (about the idea of the metadata node not wrapping the stuff that the metadata applies to).

lread 2020-08-11T12:42:03.105700Z

Hi @sogaiu! Do you mean this discussion? https://github.com/lread/rewrite-cljc-playground/issues/2 I’m interested to hear about your new ideas.

2020-08-11T13:05:47.113600Z

@lee yes, that's the discussion -- thanks for the reminder! here are 3 alternative approaches as i understand things: 1) metadata wraps the things it applies to (rewrite-clj* and parcea do this i think) 2) metadata is treated as a completely separate entity 3) borkdude's idea -- lol, i guess that looks similar to what i did before in tree-sitter-clojure i had just tried implementing 2) today and got to thinking that it can make things awkward if you want to figure out what the metadata applies to (e.g. what if there are comments or discard forms in between the metadata and what it is supposed to apply to). that's what got me thinking that there was something to option 1), but now that i've reviewed things, i guess i still like option 3 afterall 😅

borkdude 2020-08-11T13:06:28.113800Z

me too ;)

borkdude 2020-08-11T13:08:53.116500Z

but I can understand that this will be a major breaking change. however, since it's a new library that may be a better time to introduce a breaking change than any other

lread 2020-08-11T13:09:26.117300Z

@sogaiu, I think it is great that you are exploring ideas and I thank you for sharing them!

borkdude 2020-08-11T13:09:30.117400Z

the other major change I made to rewrite-clj is to skip over whitespace, #_ and ;; comments

borkdude 2020-08-11T13:09:39.117600Z

but that could be an option

borkdude 2020-08-11T13:10:00.118100Z

if these two things were in a rewrite-clj* lib, I could at some point go back to a shared library

borkdude 2020-08-11T13:10:40.119400Z

the metadata thing could also be an option

lread 2020-08-11T13:12:19.120700Z

One of my primary goals with rewrite-cljc has been to maintain as much API compatibility as I reasonably can with rewrite-clj and rewrite-cljs.

borkdude 2020-08-11T13:12:45.120900Z

which is a good start :)

lread 2020-08-11T13:14:49.122100Z

Ya I think so too. 🙂

2020-08-11T13:15:06.122500Z

on a somewhat related note, i've been thinking that discard, tag, and metadata seem to have some kind of structural similarity

borkdude 2020-08-11T13:15:23.122700Z

yes

2020-08-11T13:16:08.123600Z

whatever approach is chosen for one might be worth considering for the others

borkdude 2020-08-11T13:16:34.124Z

I guess you can also have multiple readers:

user=> (set! *data-readers* {'foo identity})
{foo #object[clojure.core$identity 0x303a5119 "clojure.core$identity@303a5119"]}
user=> #foo #foo 1
1
Never knew that, but cool

2020-08-11T13:16:58.124400Z

i didn't know until i started testing heavily 🙂

2020-08-11T13:17:04.124700Z

you can do some really odd things

borkdude 2020-08-11T13:17:09.124900Z

I'm not sure if storing the data reader as a child makes sense though, it's more similar to a function call

borkdude 2020-08-11T13:17:21.125300Z

(foo (foo 1))

2020-08-11T13:17:34.125600Z

i'm not sure either, which is why i wrote it as "might be worth considering" 🙂

borkdude 2020-08-11T13:18:05.125900Z

ok

2020-08-11T13:18:20.126200Z

just wanted to throw it out for general consideration

2020-08-11T13:18:31.126600Z

btw, i ported parcera's grammar to tree-sitter today

borkdude 2020-08-11T13:18:48.126800Z

wow... nice

2020-08-11T13:19:07.127400Z

it seems like a much cleaner break-down than what i came up with

2020-08-11T13:19:13.127600Z

so i may switch to it after more testing (that is, using it as a basis for a grammar in tree-sitter)

2020-08-11T13:19:27.127900Z

(i also ported it to janet 😉 )

2020-08-11T13:19:38.128200Z

actually, i ported a fair bit of parcera to janet

lread 2020-08-11T13:20:55.129500Z

Cool! I listed parcera as an interesting alternative to rewrite-cljc in rewrite-cljc docs.

lread 2020-08-11T13:21:30.130400Z

It currently is the only thing in the list, are there others?

borkdude 2020-08-11T13:22:29.131200Z

edamame also plays in this area, it's not whitespace preserving, parses directly to sexprs, but like rewrite-clj it has location metadata on each thing

2020-08-11T13:22:50.131500Z

those are the 3 that come to mind atm (at least things that are relatively current)

lread 2020-08-11T13:25:25.133Z

Thanks, I’ll add edamame to the list!

borkdude 2020-08-11T13:26:35.134100Z

I recently added an option to edamame that allows you to preserve location metadata of non-metadata-carrying objects like numbers, by wrapping them. It only occurs to me now that using that new feature I could have maybe used it in clj-kondo for linting... hmmmm

borkdude 2020-08-11T13:27:22.134900Z

not that I will go down that path, but if I would write it from scratch, that could've been an option

lread 2020-08-11T13:27:35.135Z

hmmmm indeed!

borkdude 2020-08-11T13:29:55.136Z

oh yes, now I remember why rewrite-clj is better here: it allows you to keep on processing even if a map is not formatted correctly. e.g.:

{:a}

(inc "foo")
Although the first map is not parseable, you will still get a warning for the second thing

borkdude 2020-08-11T13:30:17.136500Z

so the choice for rewrite-clj is still valid today

lread 2020-08-11T13:31:38.137500Z

I should make sure I have explicit tests for that

lread 2020-08-11T13:32:10.138Z

To ensure behavior is preserved moving forward

borkdude 2020-08-11T13:34:45.138400Z

I guess edamame could have a mode where it would just kept on parsing even if the current thing was invalid

borkdude 2020-08-11T13:34:55.138700Z

like (defrecord InvalidNode [...])

2020-08-11T13:35:32.139Z

the "keep on parsing" idea sounds vaguely familiar

borkdude 2020-08-11T13:36:43.139400Z

Is this irony/sarcasm or not? I can't tell from the absence of facial expressions or emoticons

2020-08-11T13:37:13.139800Z

this is not sarcasm -- merely recollection that is incomplete 🙂

2020-08-11T13:37:39.140200Z

hmm, clojurians-log is unavailable atm

borkdude 2020-08-11T13:40:46.140600Z

I thought you maybe meant that tree-sitter does keep on parsing :)

lread 2020-08-11T13:42:38.142300Z

ya @sogaiu, I remember you playing with a fork of rewrite-clj that could keep on parsing in the face of invalid clojure...

2020-08-11T13:47:52.142900Z

ah bed time for me -- good to chat with y'all 🙂

lread 2020-08-11T13:50:13.143200Z

g’night!

borkdude 2020-08-11T13:51:00.143400Z

g'night!