Sr

Srgn, AST-aware text manipulation

Hacker News

Srgn, AST-aware text manipulation

srgn is a niche source code (or just text) manipulation tool. It's written in Rust, with performance in mind. I used it to learn the language a while back, in order to work towards something resembling "useful in the real world". Think of srgn as a blend of rip-grep, tree-sitter and GNU `tr`/`sed`. At its core, it most closely resembles `tr`, but expands on it in two important ways. First, srgn provides scoping , used to specify what part of an input to work on. This can be literal text, regular expressions, or tree-sitter queries. The latter is the most interesting one. As tree-sitter queries can be tough to construct (although the tool is excellent, with an online playground for testing and more), srgn has pre-defined queries and makes an effort to unify these across languages. For example, across TypeScript, C#, Go, Rust and Python, you can specify to scope all "comments", and it (hopefully) just works as expected, despite these languages having different ideas of how comments work and look like (C# has multi-line and inline, for example, while Python only has a single type, all of which is also reflected in what tree-sitter calls those corresponding nodes). Secondly, there's actions , which simply perform text manipulation on whatever is in scope from the previous step. One could delete certain parts of all comments, for example, or rewrite all import statements across an entire code base ( https://github.com/alexpovel/srgn#mass-import-module-renamin... ). I had looked around a bunch for similar tools ( https://github.com/alexpovel/srgn#similar-tools ), but couldn't find any that quite did what srgn does. The CLI is a rather thin wrapper around the Rust library, which is usable in the usual way. By the way, the name srgn stands for surgeon, in the sense of a code surgeon: precise manipulation of text. Regular expressions and tree-sitter queries can be combined, which turns out to be much more powerful than either of these by itself, and also fills a different niche than LSP-powered Rename all -like features. It can also be used in CI, as a simple custom linter ("fail if you find any 'TODO' strings in comments"). A lot of the use cases can be covered by just regex, and then fixing mistakes manually; srgn mainly inches the precision of these operations closer to 100%, for when it's needed (like large refactors, where srgn offers full parallelization as well).

Share card

Actual performance

2points
1comments
Did not reach leaderboard

Launch Intel predictions

Analyze your own launch →
Indie HackersFits the IH revenue-focused audience · Strong signals: mistakes, para · Missing: supports, reddit linkedin, podcasting
81%81% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Product HuntOn track for Day 1 leaderboard · Strong signals: single, code · Missing: mac, agents, macos
73%73% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
Hacker NewsStrong engagement from HN community · Strong signals: ide, io · Missing: https docs, excited, just released
71%71% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
TrustMRRFits verified-revenue profile · Strong signals: way, para · Missing: mobile apps, ios, personal
63%63% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Strong signals: calls · Missing: plus, platform, intuitive
37%37% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
15%15% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Strong signals: real world · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Incorrect prediction on native model

Similar products

Text Piper
Text Piper14%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Composable Unix-like Text Manipulation Functions in WebApp

Indie Hackers1analytics
The Anchor Archipelago
The Anchor Archipelago53%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

The psychological war against AI manipulation

Indie Hackers1$2,000/moai
Te
TextFlow – Automator workflows for text manipulation in OS X65%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

TextFlow – Automator workflows for text manipulation in OS X

Hacker News76
Im
Image Manipulation via Triangulation58%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Image Manipulation via Triangulation

Hacker News5
DO
DOM registry for a better DOM Manipulation59%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

DOM registry for a better DOM Manipulation

Hacker News1
Ra
Rack-aware Kafka partition assigner49%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Rack-aware Kafka partition assigner

Hacker News1
IP
IPyflow: a reactive, dataflow-aware IPython kernel44%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

IPyflow: a reactive, dataflow-aware IPython kernel

Hacker News3
St
String-fn – string manipulation library55%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

String-fn – string manipulation library

Hacker News4
A
A RIFF parsing and manipulation library61%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A RIFF parsing and manipulation library

Hacker News1
Me
Memeforth – a “Forth” based on text manipulation and text-based memes63%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Memeforth – a “Forth” based on text manipulation and text-based memes

Hacker News3