News for hackers. Stuff that matters.
Re:Show HN: GritQL, a Rust CLI for rewriting source code by herrington_d on Wednesday March 20, 2024 @06:11PM (#39772612)
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

Re:Show HN: GritQL, a Rust CLI for rewriting source code by snthpy on Thursday March 21, 2024 @01:31AM (#39775116)
This 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?

Re:Show HN: GritQL, a Rust CLI for rewriting source code by herrington_d on Thursday March 21, 2024 @03:10AM (#39775593)
Hi! 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/pattern-syntax.html

https://ast-grep.github.io/guide/rule-config.html

Re:Show HN: GritQL, a Rust CLI for rewriting source code by Princess_98 on Friday March 22, 2024 @01:16AM (#39787658)
thanks for sharing... https://valerocreditcard.fun/
Re:Show HN: GritQL, a Rust CLI for rewriting source code by setr on Friday March 22, 2024 @05:28AM (#39788843)
Are 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