Live data from Hacker News

Tree-sitter: an incremental parsing system for programming tools

github.com

31–40 of 138 posts

Re: Tree-sitter: an incremental parsing system for programming tools

#31

Is the use case for this mainly IDEs or is it intended to replace traditional lexer and parser generators too?

We are also using this to power a lot of the program analysis features on github.com. We use it to generate the symbol list for Code Navigation, as an example, and are starting to look at extracting more semantic information about some languages using tree-sitter parse trees as intermediaries.

Re: Tree-sitter: an incremental parsing system for programming tools

#33

Tree-sitter is unfathomable to me. This is the grammar for Ruby: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/... I find it absolutely amazing that a grammar for something as complicated as Ruby can be so concise. Less than a thousand lines. The corresponding Bison grammar is 13k lines. And I think the tree-sitter one is scannerless so also includes the lexer?! How do they do it?

This is more a function of Ruby than of tree-sitter. The tree-sitter grammars for other languages are hopefully less inscrutable. For Ruby, we basically just ported whitequark's parser [1] over to tree-sitter's grammar DSL and scanner API. [1] https://github.com/whitequark/parser

I didn't mean the tree-sitter grammar was not understandable - it's very understandable - I just can't work out how to managed to find such a concise way to express grammars. Even compared to Whitequark it's 1/3 the size. What's the unique thing you do that makes it so concise?

It also seems somehow to be completely declarative? How have you managed to transform Ruby parsing to be context-free? For example where's the set of what's currently a local variable so you can distinguish from method calls?

Re: Tree-sitter: an incremental parsing system for programming tools

#35

Here's what it looks like to call it from Rust: https://github.com/tree-sitter/tree-sitter/tree/master/lib/b... Seems like this would make it much easier to bootstrap a performant language-server. Very cool; maybe that will be my next project.

We also have several of the language grammars published as crates: https://crates.io/search?q=tree-sitter (And doing the same for other grammars is a fairly painless process.)

So if you're writing a tool for a single language (like a language server), it should be as easy as adding tree-sitter and tree-sitter-blah to your cargo manifest.

Re: Tree-sitter: an incremental parsing system for programming tools

#36
post #34

Hey, Tree-sitter author here. Thanks for posting! Let me know if you have questions about the project.

Are there any plans to support modifying the grammar on the fly or without recompiling?

One day, I would love to generalize the web-based playground so that you could edit the grammars. But it's complicated, because we use C as our output language, so you would always need to recompile the C after changing the grammar.

So, I would say that it's not on our near-term roadmap.

Re: Tree-sitter: an incremental parsing system for programming tools

#37
post #34

Hey, Tree-sitter author here. Thanks for posting! Let me know if you have questions about the project.

Are there any plans to support modifying the grammar on the fly or without recompiling?

I don't think you can do this without recompiling, since the grammars get translated into C code before use. But the built-in command line tools (‘tree-sitter parse’, etc) all support a mode where they will detect local changes to a checked-out grammar definition, and recompile on the fly if needed. (This happens each time the CLI program is started up; it doesn't happen during a long-running process.)

Re: Tree-sitter: an incremental parsing system for programming tools

#38

Earlier quoted context omitted.

This is more a function of Ruby than of tree-sitter. The tree-sitter grammars for other languages are hopefully less inscrutable. For Ruby, we basically just ported whitequark's parser [1] over to tree-sitter's grammar DSL and scanner API. [1] https://github.com/whitequark/parser

I didn't mean the tree-sitter grammar was not understandable - it's very understandable - I just can't work out how to managed to find such a concise way to express grammars. Even compared to Whitequark it's 1/3 the size. What's the unique thing you do that makes it so concise? It also seems somehow to be completely declarative? How have you managed to transform Ruby parsing to be context-free? For example where's th…

Ahh my mistake! :-)

To be fair, we're cheating a little bit because the Ruby grammar relies so heavily on an external scannar, which is just under 1,000 lines of C++: https://github.com/tree-sitter/tree-sitter-ruby/blob/master/...

Re: Tree-sitter: an incremental parsing system for programming tools

#40

Hey, Tree-sitter author here. Thanks for posting! Let me know if you have questions about the project.

I've done two grammars for my own use in the last few months (well, one isn't quite complete yet) and it's been quite an enjoyable (learning) experience. Thanks for sharing this tool!
Post reply on HN