Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: substitution anchors
- X-seq: zsh-workers 11200
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx (Zsh hackers list)
- Subject: PATCH: substitution anchors
- Date: Fri, 05 May 2000 15:26:16 +0100
- In-reply-to: "Your message of Fri, 05 May 2000 17:32:58 +0400." <001701bfb696$6d2abbd0$21c9ca95@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
> That's because I used wrong syntax in _arguments (_long_options at the
> time of writing). This patch gets it right and replaces # with (#s),
> that also works. Patch attached.
OK, this would remove the effect of anchors in substituted parameters, and
makes it a bit clearer what's going on. I don't if Bart is still keen on
keeping this effect. This needs Andrej's patch (the only effect at the
moment is whether `configure' shows all --enable/--disable pairs when the
help text contains one of them, as is usual) and I will commit the two
together or not at all.
Index: Doc/Zsh/expn.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v
retrieving revision 1.11
diff -u -r1.11 expn.yo
--- Doc/Zsh/expn.yo 2000/05/04 06:21:18 1.11
+++ Doc/Zsh/expn.yo 2000/05/05 14:20:23
@@ -456,13 +456,21 @@
Replace the longest possible match of var(pattern) in the expansion of
parameter var(name) by string var(repl). The first form
replaces just the first occurrence, the second form all occurrences.
+Both var(pattern) and var(repl) are subject to double-quoted substitution,
+so that expressions like tt(${name/$opat/$npat}) will work, but note the
+usual rule that pattern characters in tt($opat) are not treated specially
+unless either the option tt(GLOB_SUBST) is set, or tt($opat) is instead
+substituted as tt(${~opat}).
+
The var(pattern) may begin with a `tt(#)', in which case the
var(pattern) must match at the start of the string, or `tt(%)', in
which case it must match at the end of the string. The var(repl) may
be an empty string, in which case the final `tt(/)' may also be omitted.
To quote the final `tt(/)' in other cases it should be preceded by two
backslashes (i.e., a quoted backslash); this is not necessary if the
-`tt(/)' occurs inside a substituted parameter.
+`tt(/)' occurs inside a substituted parameter. Note also that the `tt(#)'
+and `tt(%)' are not active if they occur inside a substituted parameter,
+even at the start.
The first `tt(/)' may be preceded by a `tt(:)', in which case the match
will only succeed if it matches the entire word. Note also the
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.3
diff -u -r1.3 subst.c
--- Src/subst.c 2000/05/03 12:21:56 1.3
+++ Src/subst.c 2000/05/05 14:20:23
@@ -1466,6 +1466,13 @@
char t = s[-1];
singsub(&s);
+#if 0
+ /*
+ * This allows # and % to be at the start of
+ * a parameter in the substitution, which is
+ * a bit nasty, and can be done (although
+ * less efficiently) with anchors.
+ */
if (t == '/' && (flags & SUB_SUBSTR)) {
if ((c = *s) == '#' || c == '%') {
flags &= ~SUB_SUBSTR;
@@ -1476,6 +1483,7 @@
s++;
}
}
+#endif
}
if (!vunset && isarr) {
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author