3 ms·
Tree-sitter does run on the web. I got it working for my editor, but it did involve several days' worth of effort and getting into the weeds with emscripten. De
by gushogg-blake 3y ago
Tree-sitter does run on the web. I got it working for my editor, but it did involve several days' worth of effort and getting into the weeds with emscripten. Details here - https://gushogg-blake.com/p/emscripten-web-modules/ https://gushogg-blake.com/p/emscripten-web-modules/.
- lukan 3y agoCan you explain the motivation why you did not use lezer? I just discovered lezer and am tinkering with integrating it into my projects, but maybe tree-sitter would be a better fit? (Speed could be a determining factor, but working with wasm can also make things slower, if you often have to get data in and out)
- k8svet 3y agoLezer is 5 years old. It's quite clear which won out between Tree-Sitter and Lezer, and it's not Lezer.
- lukan 3y agoSorry, but it is not clear to me. Lezer obviously works in the real world, as codemirror is quite widespread (integrated in chrome dev tools for example). And since I use codemirror anyway, it might make sense to also use lezer, unless there are downsides I am not aware of.
- jitl 3y agoI think Lezer is great if there’s a parser for your language, or you only need to support a few languages and you have time to build grammars yourself. When you need to build a general tool that supports a ton of languages, that’s when Lezer doesn’t fit as well since there just aren’t a ton of existing grammars out there.
- lukan 3y agoI see. Well I am fine with just js and ts for now, but long term I need more language support. So I probably should choose tree sitter.
- deleted 3y ago[deleted]
- gushogg-blake 3y agoI didn't know about Lezer. I think I probably would have used it if I'd known - or at least tried it before Tree-sitter, as WASM obviously brings in extra complexity. Having used Lezer and CodeMirror a bit on a different project, they both seem like they are probably high quality and well thought out projects from a speed and reliability perspective, but I found the architecture and docs to be confusing and unergonomic. The main issue I have with the docs/architecture (for CM at least) is that they use a concept called "facets" without really explaining what it means, and to be honest it felt like a level of abstraction/indirection that my brain couldn't handle. The other issue with the docs is that they don't seem contextualised enough, somehow. They would list the functions/methods of an object but not really explain how it fit into the system as a whole. Maybe this is to do with not understanding facets, or CM's extension architecture, enough, or something, but it was definitely a recurring theme of my experience. I also found the CM API slightly confusing in that (almost) everything you do is via a function that takes some state object as input, as opposed to via calling methods on that object, but that's more of a style issue once you realise that you have to `import {doSomething} from "codemirror"` and `doSomething(state)` as opposed to `state.doSomething()`.
- lukan 3y agoThx. I will just try both I think. The other comment mentioned treesitter now provides native bindings, so it should be easy to try it out.