tree-sitter

tree-sitter fun
2020-09-02T10:01:49.007100Z

i've overhauled the grammar -- the older version that was used in a few experimental places exists at tag v0.0.1. in my testing the newer version (which is available around tag v0.0.2) handles some more edge cases and can actually be tweaked to explicitly have whitespace and comments retained as nodes relatively easily (so with some extra work, round-tripping types of functionality might be possible). emacs-tree-sitter is looking like it's come along quite nicely and i am thinking to try this latest version of the grammar with it. other editors that might be able to use it directly include: recent versions of atom and the master branch of neovim. vscode seems to have decided not to provide built-in support for tree-sitter, but it should be possible to use the grammar there as well, though it seems likely the potential benefits would be less than for the already mentioned other editors.

2020-09-02T10:20:09.008200Z

i've also successfully used the grammar from python using tree-sitter's python bindings. the motivation for this was partly to assess the feasibility of using the hypothesis testing library.

pez 2020-09-02T10:29:07.009300Z

How built-in does the support for tree-stter become in Emacs, compared to vscode?

pez 2020-09-02T10:30:05.009800Z

I wonder if there is a way to make the vscode team challenge their current decision, btw.

2020-09-02T10:51:32.017900Z

the way the emacs support for tree-sitter is currently implemented is via "dynamic modules". at present many distributions don't ship emacs with dynamic module support built in, but that might change over time (it could be that if one is an emacs user, the barrier to getting this working is not too bad -- i helped someone with this on macos recently) if you have an appropriate emacs, it's possible to get tree-sitter working fairly easily (by emacs user standards i suppose -- i.e. elpa or straight or via source) my impression is that the emacs-tree-sitter project is being seen as a good thing by the emacs developers and i believe at least one of them helped a bit with some experimentation regarding highlighting.

2020-09-02T10:54:37.020200Z

i have mostly been using the highlighting aspect for non-clojure languages via emacs-tree-sitter, but i have written some code that leverages the parse tree for other purposes (e.g. selecting the current top-level form -- the code is generic and has worked for a few different languages for which there is tree-sitter support).

2020-09-02T11:00:44.024200Z

at present, although there is a barrier to entry for using tree-sitter with emacs (compared to ordinary packages), if you get it working once, it looks like you can make use of it in a variety of ways. this is in contrast to vscode -- i wrote two vscode extensions using tree-sitter grammars, but i included the tree-sitter bits in both extensions. my current impression is that it's possible to use tree-sitter stuff in vscode, but each extension may end up having to ship their own grammars. iiuc, that's different from what atom, neovim, and emacs seem to be doing.

pez 2020-09-02T11:05:38.024900Z

I see. Makes sense.