Amber: A code search and replace tool
github.com
github.com
More specifically for the "string constant" search/replace, you can see the playground example!
https://ast-grep.github.io/playground.html#eyJtb2RlIjoiUGF0Y...
If you want to do queries that understand the grammar, https://github.com/getgrit/gritql is closer to what you're looking for. (Disclaimer: I'm the author.)
Ex. here's how you would search for your example of looking for a string unless it's inside a string constant. [0]
grit apply '"this_string" => `new_string` where $match <: not within string()'
It seems ast-grep is more powerful if you don't exactly know how the code is structured.
There is some optimization to [skip parsing](https://github.com/ast-grep/ast-grep/blob/9f8ed5fb2abf35d928...) but generally I don't expect ast-grep can beat ripgrep or amber. (but sometimes ast-grep can beat grep due to parallel processing)
"Namespace collisions" in the real world get my goat in general, but in this case, I'm about to have a heart attack from the discovery of all 3 in one week.
I get why for all cases : amber=electron/ήλεκτρο in Ancient Greek.* But still.
* One of my favorite albums is Amber by Autechre, and where I learned this nugget (also - it's a pile of Sand Dunes on the cover, so silicon). Clever boys.
I'll check this one out...
ast-grep and gritql are both much better.
which in my mind was the first “replace” version of ripgrep
grep -> ripgrep
sed -> sd
https://gist.github.com/jaysoffian/0eda35a6a41f500ba5c458f02...
Put it in `PATH` and then: `git gsr <old> <new>`
EDIT: Opps same name different project.
find . [ ... find args ] | sed -e 's/nee\(dl[aeiou]\)/stack\1/g' $ rg 'sear' -r 'repl' file.txtEdit: Oh, it's you. Thanks for a brilliant tool, I use it every workday and have been for years.
If you really need to search for code constructs that can span multiple lines (but not always do) then Treesitter-aware tools like ast-grep and gritql are superior.