Fork me on GitHub
#rewrite-clj
<
2020-08-11
>
sogaiu12:08:10

@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).

lread12:08:03

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.

sogaiu13:08:47

@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 😅

borkdude13:08:53

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

lread13:08:26

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

borkdude13:08:30

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

borkdude13:08:39

but that could be an option

borkdude13:08:00

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

borkdude13:08:40

the metadata thing could also be an option

lread13:08:19

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.

borkdude13:08:45

which is a good start :)

lread13:08:49

Ya I think so too. 🙂

sogaiu13:08:06

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

sogaiu13:08:08

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

borkdude13:08:34

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

sogaiu13:08:58

i didn't know until i started testing heavily 🙂

sogaiu13:08:04

you can do some really odd things

borkdude13:08:09

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

borkdude13:08:21

(foo (foo 1))

sogaiu13:08:34

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

sogaiu13:08:20

just wanted to throw it out for general consideration

sogaiu13:08:31

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

borkdude13:08:48

wow... nice

sogaiu13:08:07

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

sogaiu13:08:13

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

sogaiu13:08:27

(i also ported it to janet 😉 )

sogaiu13:08:38

actually, i ported a fair bit of parcera to janet

lread13:08:55

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

lread13:08:30

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

borkdude13:08:29

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

sogaiu13:08:50

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

lread13:08:25

Thanks, I’ll add edamame to the list!

borkdude13:08:35

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

borkdude13:08:22

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

lread13:08:35

hmmmm indeed!

borkdude13:08:55

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

borkdude13:08:17

so the choice for rewrite-clj is still valid today

lread13:08:38

I should make sure I have explicit tests for that

lread13:08:10

To ensure behavior is preserved moving forward

borkdude13:08:45

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

borkdude13:08:55

like (defrecord InvalidNode [...])

sogaiu13:08:32

the "keep on parsing" idea sounds vaguely familiar

borkdude13:08:43

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

sogaiu13:08:13

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

sogaiu13:08:39

hmm, clojurians-log is unavailable atm

borkdude13:08:46

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

lread13:08:38

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

sogaiu13:08:52

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

lread13:08:13

g’night!