Search your source tree using a Tree-Sitter Query and apply replacemnts scripted in Rhai and print out the change as a patch file.
Find all dbg!(...) macros are in the current source tree (unlike grep this
will not find comment out ones from document examples):
ssr search --language rust --query '(macro_invocation macro: (identifier) @m (#eq? @m "dbg"))'See [ts-query][Tree-Sitter Query Syntax] for the explaination of the query syntax. For prototyping the query a good place is the [ts-playground][playground of Tree-Sitter].
To provide a high degree of flexibility in the replacement expressions the rhai scripting language is used which also offers an online rhai-playground.
The Rhai runtime is extended of a document object whith an edit method to
modify the current document. Matches from the --query are accessible via the
found object. The --replacement is called for every match.
For example to replace all dbg!(...) macros call with a call to println!
use:
ssr replace --language rust \
--query '((expression_statement ((macro_invocation macro: (identifier) @m (#eq? @m "dbg")))) @exp)' \
--replacement 'for m in found.captures { if m.name == "exp" { document.edit(m.range, "println!"); } }'