TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Is tree-sitter good enough?

18 点作者 jamesbvaughan将近 3 年前

2 条评论

layer8将近 3 年前
Regarding the `foo() { bar() {` example, I wonder if a possible approach would be to determine in which syntactic contexts the local token sequence around the parse error (here: `bar() {`) would be correct, and then try to determine what is missing for that context (here: class scope) to have been established; or just give the error “method definition in local scope”, but still parse it as a method definition.<p>As it currently works, the interpretation as a method definition is not even considered, because the grammar doesn’t have method definitions in that syntactic context. But that’s not how human pattern recognition works: we tend to recognize a method definition regardless of the context. So maybe we could build a parser that would try do determine all possible valid interpretations of all token subsequences in parallel (like a nondeterministic generalized parser), outputting errors where neighboring &#x2F;overlapping sequences clash which each other (“this starts out like a method body but then transitions into a method definition”).
gravypod将近 3 年前
Another issue with tree-sitter is how basic functionality is not consistent across all languages. Want to find all comment text in all languages? Each tree-sitter lang support will have a slightly different behavior for every language. When you extract the comment you&#x27;ll have syntax from the language in there like `&#x2F;*&#x2F;` or `{}`.<p>Example from a sourcegraph docs generation project:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;sourcegraph&#x2F;doctree&#x2F;blob&#x2F;07a2d593fe9855be6a8928394abee72e2543fef9&#x2F;doctree&#x2F;indexer&#x2F;zig&#x2F;indexer.go#L360" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sourcegraph&#x2F;doctree&#x2F;blob&#x2F;07a2d593fe9855be...</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;sourcegraph&#x2F;doctree&#x2F;blob&#x2F;07a2d593fe9855be6a8928394abee72e2543fef9&#x2F;doctree&#x2F;indexer&#x2F;golang&#x2F;indexer.go#L418" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sourcegraph&#x2F;doctree&#x2F;blob&#x2F;07a2d593fe9855be...</a>