chmln / sd

Intuitive find & replace CLI (sed alternative)
MIT License
5.84k stars 138 forks source link

Error on `$<num><non_num>` capture replacement names #258

Closed CosmicHorrorDev closed 11 months ago

CosmicHorrorDev commented 11 months ago

Fixes #44

(Still a draft. Needs a lot of cleanup)

This is a mostly working implementation that errors on capture names that are a number followed by a non-number valid capture char (a-zA-Z_). It's a decent chunk of code mostly because regex-automata doesn't expose a replacement capture name iterator (and couldn't without a non-trivial refactoring of their code based on the current implementation). Instead we provide our own which requires a lot of care to match regex-automata's implementation

Anyhoo, here's what the error looks like

image

CosmicHorrorDev commented 11 months ago

Alright, I'm quite happy with things now. Most of the code is from implementing our own replacement capture parsing to match upstream or building up the custom error to show the user. Making sure that we match upstream's implementation was the part I was most concerned with, but I'm rather happy with how the tests turned out, so that should hopefully be fine

This should be good enough to merge now :+1: