4 ms·
Congrats from ast-grep team! Nice job Morgante! GritQL shares a lot of common ground with ast-grep, which is also a code rewriter based on tree-sitter. Intere
by herrington_d 3y ago
Congrats from ast-grep team! Nice job Morgante!
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 https://github.com/ast-grep/ast-grep
- snthpy 3y agoThis is great. Thanks for the link. 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?
- herrington_d 3y agoHi! This is Grit's release news so please allow me to only briefly answer your question. > nested syntax sg does not support it natively now and you need API to extract relevant text out. For update code, I recommend first read the quick start, pattern and rule essentials https://ast-grep.github.io/guide/quick-start.html https://ast-grep.github.io/guide/quick-start.html https://ast-grep.github.io/guide/pattern-syntax.html https://ast-grep.github.io/guide/pattern-syntax.html https://ast-grep.github.io/guide/rule-config.html https://ast-grep.github.io/guide/rule-config.html
- Princess_98 3y ago[flagged]
- setr 3y agoAre either of these exposed conveniently to build on? One scenario I dealt with recently was replacing a pattern that required rudimentary type resolution to apply properly. 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