I'm just starting to learn about tree-sitter but my understanding is that it can also handle nested syntax, for example code in documentation html pages. Does sg support this a well?
What I would like to do is use sg to update my project's code samples. Is that possible? What part of the docs should I look at for this?
For update code, I recommend first read the quick start, pattern and rule essentials
https://ast-grep.github.io/guide/quick-start.html
Specifically,
While($conn.hasrows()){
…
$conn.commit()
}
Where $conn needed to be of a specific connection class to be a match.I ended up taking a Java parser, adding simple type resolution myself, and then the rest of the find-replace logic from there. I wouldn’t expect a tree-sitter based tool to deal with types, but if there’s a hook to add metadata to the parse tree and replace utilizing it, then this might have saved me some trouble
GritQL shares a lot of common ground with ast-grep, which is also a code rewriter based on tree-sitter.
Interested folks may wonder about their difference. The key difference is that their surface APIs are quite different. GritQL is more like a DSL (or SQL). while ast-grep is more like pattern language + embedded configuration in YAML. Check it out here if you are interested https://github.com/ast-grep/ast-grep