9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.61k stars 319 forks source link

plumber: allow up to libregexp's NSUBEXP subexpression match variables #566

Closed igorburago closed 1 year ago

igorburago commented 2 years ago

Motivated by #565.

Unlike, e.g., backslash references in replacement strings of sam’s substitution command, where multi-digit subexpression references would be ambigiuos, this change does not create any ambiguity that cannot be easily avoided thanks to the single-quote literal syntax.

Granted, it is backward incompatible, but I doubt anyone wrote something like …$7123… instead of …$7'123'…—to an eye used to rc variable substitution syntax (which plumbing rules deliberately resemble), the former is too uncomfortable looking, even if one knows that in plumbing rules it works slightly differently than in rc.

In subexpmatch(), we consume all the digits following the dollar sign even if the resulting number would exceed NMATCHSUBEXP (or even overflow) to avoid any potential ambiguity and bring it in line with rc behavior for such syntax.