Fork me on GitHub
#rewrite-clj
<
2022-09-14
>
Noah Bogart00:09:00

I’m thinking about writing a pattern matching library for rewrite-clj nodes. Is this something others would use?

lread00:09:08

Interesting! So find me all the things that match <some pattern>. And maybe also optionally replace? Have you worked out what <some pattern> might look like?

❤️ 1
lread00:09:53

Like a regex for nodes?

👍 1
Noah Bogart00:09:41

My inspiration is Rubocop’s https://docs.rubocop.org/rubocop-ast/node_pattern.html, so I’m going to explore a Clojure-styled version

lread00:09:19

My mind drifted to https://github.com/lambdaisland/regal and its high level syntax, not sure if that would be of any interest.

lread00:09:11

It might be helpful to your efforts if I finally got around to implementing those https://github.com/clj-commons/rewrite-clj/issues/114.

👍 1
lread00:09:12

What will you be using this for? Do you know yet?

Noah Bogart00:09:25

Regal is a good thought, I forgot about that. I’ll check it out

Noah Bogart00:09:17

I’ve been doing more work on clj-kondo, which has got me thinking a lot about the nature of writing lints, and I have some limited experience with rubocop and the rubocop ecosystem so I'm curious what clj-kondo’s lints would look like if built using this kind of system instead of how it's currently done (strictly one pass, lint as you go, etc)

Noah Bogart00:09:10

If by a long shot what I build ends up helping clj-kondo, then great. Otherwise, I’m just looking to sate my curiosity and have some fun

Noah Bogart00:09:12

And maybe build something others could use! But do the interesting and fun part first, which is build a sexp pattern matching library lol

lread01:09:14

Cool! If you want to bounce ideas or need some enhancements to rewrite-clj, don't be shy!

delaguardo07:09:37

there are few libs out there. meander is the most stable i think. if you feel it is a bit too much for the task then i have a small one called matchete

Noah Bogart11:09:48

Have a link for machete?

delaguardo11:09:12

https://github.com/xapix-io/matchete it is incomplete though but enough to give you an overview of how such patterns might look like

👍 1
Noah Bogart15:09:59

This library is cool, and is pretty close to what I was imagining! I'll play around with it and see what I can do. Thanks so much for mentioning it

Noah Bogart15:09:24

meander is cool too, but it's a little heavy for my taste. I was hoping to build/use something that's super specific to my particular idea

borkdude08:09:36

clj-kondo traverses the rewrite-clj only once for almost all linters for performance