tree-sitter

tree-sitter fun
2020-10-29T08:13:19.016100Z

here's a demo of emacs-tree-sitter highlighting part of clojure.core

2020-10-29T08:14:24.016600Z

here is the corresponding highlights.scm: https://gist.github.com/sogaiu/a2a51cd58e5276a4676f3195897bf7c9

2020-10-29T08:18:55.021100Z

highlights.scm has definitions for highlighting the following: * keywords * strings * numbers * booleans and nil * comments * discard expressions * the ^ for metadata * dynamic variables (ear-muffed things) * symbols starting with & (like &form, &env, &) * gensym-ish things (symbols ending with #) * some macro calls (just the head) * some built-in function calls (just the head) * other function calls (just the head) * some interop-ish things (i.e. symbol in head position that starts with .) * symbols that contain dots (e.g. clojure.lang.Numbers) * things that are quoted or syntax quoted may have their highlighting affected

pez 2020-10-29T08:27:13.021300Z

Sweet!

pez 2020-10-29T08:29:09.022400Z

I don’t see discards in the gist, though you mention them here. What gives?

2020-10-29T08:35:44.025500Z

thanks for taking a look! yes, you are right that there are no discards in the image. such sharp eyes! sorry about that. i think the image may be missing gensym stuff and possibly other stuff too. i'll make a few more images 🙂

2020-10-29T08:39:29.026200Z

this is what discard expressions look like if you give them the highest priority (i.e. you put a rule for it at the top of the highlights.scm file)

2020-10-29T08:40:05.027100Z

i don't really find that to my taste, so i tend to go for the following sort of arrangement

2020-10-29T08:40:19.027400Z

here discard expressions have a lower priority

2020-10-29T08:43:30.028400Z

the following demos gensym-ish symbol highlighting along with syntax-quoted forms having somewhat different coloring

2020-10-29T08:45:30.029600Z

in the very first image, if you look closely, you may be able to see that there is actually a difference between macro calls (boldish pinkish) and "built-in" functions (e.g. cast is not bold and is sort of redish)

2020-10-29T08:48:04.031700Z

i think the bold light blue in the first image is roughly non-built-in calls -- where "non-built-in" basically means highlights.scm hasn't been taught about such symbols. the point is to be able to distinguish between: * macro / special form calls (only the known ones) * built-in function calls (only the known ones) * other calls

pez 2020-10-29T09:31:54.032Z

Nice!

pez 2020-10-29T09:32:56.033100Z

I wasn’t referring to the image really. It was the gist. But I only read it very quickly. (Super happy with having some images to look at for more examples, though).

2020-10-29T09:33:36.033300Z

oh my bad.

2020-10-29T09:34:05.033600Z

here is the line in the gist regarding discard expressions: https://gist.github.com/sogaiu/a2a51cd58e5276a4676f3195897bf7c9#file-highlights-scm-L11

2020-10-29T14:02:11.034100Z

i made an attempt at getting things to work with nvim-treesitter: https://github.com/sogaiu/nvim-treesitter/tree/clojure

2020-10-29T14:04:02.034500Z

@aleh_atsman it's a bit rough, but how does this look?

1