Closed Himujjal closed 3 years ago
@Himujjal It's not possible to edit tree-sitter's AST cause it runs counter to tree-sitter abilities like cheap syntax tree edits, recovering after errors and precise nodes position tracking. There only one way is to edit grammar.js
file so the tree-sitter would build a different syntax tree by itself.
Cool no problem. I anyways got the problem solved. Thanks for your help. We can close this issue.
In a certain use case, I need to edit the AST to enclose a for-loop in a
statment_block
for tree-sitter-javascript:Before:
After:
Is it possible to edit the AST this way using tree-sitter-node? If yes. How do I do it? Currently, the only way I see is to create a new
StatementBlockNode
object and then attach it to the tree. In the after case, I don't care about the row and column numbers.