Mark Erikson @acemarke.dev · 24/03/2025I've been looking at tools like `ast-grep` and `gritql`, which can search for AST-based patterns, but they both seem limited to matching a single AST node at a time, not multi-line. Ideally, I'd like: ``` var a = 1; let b = fn(c) ``` to match: ``` let a = 2; var b = fn( c ) ``` 240
Herrington Darkholme @hd-nvim.bsky.social · 25/03/2025Hi Mark! ast-grep can do tricks like `expanding the match region`. Combining `precedes`, you can replace multiple statements at once. In case you are analyzing files, you can match the following statement as a new meta-var and use --json flag to extract the line ast-grep.github.io/playground.h...ast-grep.github.ioPlayground | ast-grepast-grep playground is an online tool that lets you explore AST, debug custom lint rules, and inspect code rewriting with instant feedback. 120
Herrington Darkholme @hd-nvim.bsky.social · 25/03/2025This is the example of using multiple variable ast-grep.github.io/playground.h...ast-grep.github.ioPlayground | ast-grepast-grep playground is an online tool that lets you explore AST, debug custom lint rules, and inspect code rewriting with instant feedback. 100