tree-sitter / tree-sitter

An incremental parsing system for programming tools
https://tree-sitter.github.io
MIT License
17.46k stars 1.3k forks source link

[Feature] hope to be able to replace or modify a specific Node. #3419

Open songhtdo opened 1 month ago

songhtdo commented 1 month ago

Problem

Hello, thank you very much for providing a great library. However, during my specific use, I found that there were occasional parsing errors, especially when parsing C++ due to the complexity of the syntax, which can easily lead to some inconsistencies with expectations. This kind of problem usually occurs in a complex grammatical structure, and if the problematic node content is parsed separately, it is correct.

Expected behavior

I hope you can provide a function that allows manual replacement of specific Node nodes. This method is equivalent to patching specific error results, which is easier to implement than directly modifying the language's grammar.js requirements. Through the analysis of this patch method, it will be cleaner than the later conversion process.

songhtdo commented 1 month ago

It is hoped that the nodes from Tree A can be merged into Tree B.

jeff-hykin commented 3 weeks ago

You might want to look into this discussion here

They pretty much say, no but it is a feature that can be built on top of the tree-sitter