TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Tree-sitter: new incremental parsing system for programming tools (2018) [video]

131 pointsby ggurgoneover 5 years ago

9 comments

georgewfraserover 5 years ago
The most obvious application of tree-sitter is editors. I wrote a VSCode extension to replace the built-in syntax coloring with tree-sitter-based coloring: <a href="https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=georgewfraser.vscode-tree-sitter" rel="nofollow">https:&#x2F;&#x2F;marketplace.visualstudio.com&#x2F;items?itemName=georgewf...</a><p>I actually think it would make more sense for the various VSCode language extensions to just bake in tree-sitter for their language. I have had a PR open to do this with golang for a while: <a href="https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;vscode-go&#x2F;pull&#x2F;2555" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;microsoft&#x2F;vscode-go&#x2F;pull&#x2F;2555</a>
评论 #21676111 未加载
评论 #21679795 未加载
minxomatover 5 years ago
Important recent development in tree sitter was the new query language. Like TextMate or Sublime Grammars, ts in atom did use CSS selectors, but now it has a much more powerful s-expression query language which is useful for more than just syntax highlighting, e.g. static analysis. An application of that is Github&#x27;s semantic, a haskell tool for code navigation and call graph analysis.<p>Demo and explanation: <a href="https:&#x2F;&#x2F;github.com&#x2F;tree-sitter&#x2F;tree-sitter&#x2F;pull&#x2F;444" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;tree-sitter&#x2F;tree-sitter&#x2F;pull&#x2F;444</a>
adadgarover 5 years ago
Neovim is aiming to integrate this in the next major release, v0.5: <a href="https:&#x2F;&#x2F;github.com&#x2F;neovim&#x2F;neovim&#x2F;pull&#x2F;11113" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;neovim&#x2F;neovim&#x2F;pull&#x2F;11113</a>
lewisl9029over 5 years ago
I&#x27;ve been following tree sitter for a while, as I find the tech super cool and can&#x27;t wait to see more practical applications.<p>One thing (among many others) that I&#x27;ve found really promising about Dark is its editor. See the hands-on video on their homepage for a demo: <a href="https:&#x2F;&#x2F;darklang.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;darklang.com&#x2F;</a><p>It mostly feels like you&#x27;re just typing text like in any regular text editor, but your inputs are actually manipulating the AST directly, and the editor itself ensures that your inputs can never result in an invalid program (i.e. there&#x27;s no such thing as making a syntax error in Dark). It&#x27;s inspired by tooling in the lisp world like Paredit and Parinfer, but Dark itself doesn&#x27;t have to _look_ like a lisp because the structure of the AST is maintained by the editor itself instead of by users manually inserting and removing parens. It&#x27;s an ingenious way to get most of the productivity benefits of a lisp-style syntax and all the structural editing tooling that comes with it, without intimidating new-comers with the super foreign looking parens infested syntax lisps are infamous for.<p>The other day I was actually briefly looking into whether or not it could be possible to replicate something like this in Atom using tree-sitter for some mainstream language like JS, but ended up getting blocked by the fact that Atom doesn&#x27;t seem to offer an API for plugins to block&#x2F;replace user input. This is probably for the best, given all the horrible ways this could be abused, but it does mean if I wanted to explore the idea further I&#x27;d probably have to either fork Atom to experiment with the idea or build something up from scratch, which is a pretty daunting undertaking given how deceptively complex modern editors can get these days.<p>But maybe I&#x27;m missing a different way to accomplish this in Atom with its existing APIs? Or does anyone know if VSCode&#x27;s extension APIs can support this use case? I realize I&#x27;ve probably barely scratched the surface given how little time I&#x27;ve spent on it so far.
评论 #21675969 未加载
评论 #21675578 未加载
dmortinover 5 years ago
Will tree sitter also stimulate creation of free tools which work on the AST?<p>E.g. it&#x27;s a mystery to me why we don&#x27;t have free refactoring tools like the ones in IntelliJ. Like some free library which could extract methods, rename variables, etc. by modyfing the AST. It does not seem too hard.<p>Is it because the current AST parsers are not fast enough or is there some other reason?
评论 #21676456 未加载
评论 #21676437 未加载
dmitriidover 5 years ago
So... You write your grammars in Javascript. Which is then serialized to JSON but a parser defined in Rust, so that it can be compiled to C?..<p>That’s... a very roundabout way of doing things.<p><a href="http:&#x2F;&#x2F;tree-sitter.github.io&#x2F;tree-sitter&#x2F;implementation" rel="nofollow">http:&#x2F;&#x2F;tree-sitter.github.io&#x2F;tree-sitter&#x2F;implementation</a>
评论 #21676852 未加载
评论 #21679343 未加载
rrampageover 5 years ago
The project page is at <a href="https:&#x2F;&#x2F;tree-sitter.github.io&#x2F;tree-sitter&#x2F;" rel="nofollow">https:&#x2F;&#x2F;tree-sitter.github.io&#x2F;tree-sitter&#x2F;</a>
dangover 5 years ago
Discussed at the time: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18213022" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=18213022</a>
based2over 5 years ago
(2018)
评论 #21675252 未加载