Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Allow / in full pattern alternations
- X-seq: zsh-workers 38275
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Allow / in full pattern alternations
- Date: Mon, 11 Apr 2016 14:06:14 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references; bh=d98ndQIpUz+6Hi8HHjuoctydt6a7+b1InMckBmdh7sg=; b=W3a232V2OBmzt8fIu2JX+c3OPIodRSQm2tEAJJwWNGSmOQTcrLAmMANHC6AVH6ohgs 1lv5tvRFJSyqjl7z0JdBDETSgZKXfv80y+40EkesgEdiUCDi6MOk+Abies7i+30PbEWt UcG8N/RcyMtcZN+RBxSpNLaHr5exnqnTzSa26g/FiOgp/0E9YW0hiNXENRnIIgQFMBDo p3ap4PXcgobUxsJpaDeSemToOVVZTpr85Y4dRweEQcdOjb4oWvM48w8A61lliux2E6bl +/kUyr4KRvodj9ulQrAZE2hErDQhM4WXoX70AIqTEyWXP3H5pefBHc+eV8vLbPuMEWbc S/Ow==
- In-reply-to: <CAHYJk3SEeghkbpLCE26bG_76nM5PYp9MF68AO1ue00DHTwRV6A@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHYJk3SEeghkbpLCE26bG_76nM5PYp9MF68AO1ue00DHTwRV6A@mail.gmail.com>
Well, it was a bit easier than I thought.
% print -l (${(~j:|:)${:-$^fpath/rep*}})
/home/mikaelh/.zsh/functions/repoint
/home/mikaelh/.zsh/functions/repointmany
/usr/local/share/zsh/5.2-dev-1-mika/functions/replace-argument
/usr/local/share/zsh/5.2-dev-1-mika/functions/replace-string
/usr/local/share/zsh/5.2-dev-1-mika/functions/replace-string-again
This patch is obviously pretty ugly, and just intended as a proof of
concept / pile of crap, and it will leak stuff / do weird things if
there was an error in a sub-globpattern.
It is also obviously not intended for inclusion, I just wanted to see
what the code might look like and what would be needed. But if someone
is struck by some inspiration about how to implement this in a way that
is less horrible, feel free to say how :).
---
Src/glob.c | 47 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 11 deletions(-)
diff --git a/Src/glob.c b/Src/glob.c
index 7848598..610396d 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1829,17 +1829,27 @@ zglob(LinkList list, LinkNode np, int nountok)
quals = newquals;
}
q = parsepat(str);
+ int specialhack = 0;
if (!q || errflag) { /* if parsing failed */
- restore_globstate(saved);
- if (unset(BADPATTERN)) {
- if (!nountok)
- untokenize(ostr);
- insertlinknode(list, node, ostr);
+ char *par = str;
+ if (*str == zpc_special[ZPC_INPAR] &&
+ !skipparens(Inpar, Outpar, (char **)&par) &&
+ !*par && zpc_special[ZPC_BAR] && strchr(str, zpc_special[ZPC_BAR]))
+ {
+ specialhack = 1;
+ errflag &= ~ERRFLAG_ERROR;
+ } else {
+ restore_globstate(saved);
+ if (unset(BADPATTERN)) {
+ if (!nountok)
+ untokenize(ostr);
+ insertlinknode(list, node, ostr);
+ return;
+ }
+ errflag &= ~ERRFLAG_ERROR;
+ zerr("bad pattern: %s", ostr);
return;
}
- errflag &= ~ERRFLAG_ERROR;
- zerr("bad pattern: %s", ostr);
- return;
}
if (!gf_nsorts) {
gf_sortlist[0].tp = gf_sorts = (shortcircuit ? GS_NONE : GS_NAME);
@@ -1852,9 +1862,24 @@ zglob(LinkList list, LinkNode np, int nountok)
matchct = 0;
pattrystart();
- /* The actual processing takes place here: matches go into *
- * matchbuf. This is the only top-level call to scanner(). */
- scanner(q, shortcircuit);
+ if (!specialhack) {
+ /* The actual processing takes place here: matches go into *
+ * matchbuf. This is the only top-level call to scanner(). */
+ scanner(q, shortcircuit);
+ } else {
+ str++;
+ while (*str) {
+ char *next = strchr(str, zpc_special[ZPC_BAR]);
+ if (!next) next = strchr(str, Outpar);
+ if (!next) break;
+ *next = '\0';
+ q = parsepat(str);
+ // XXX handle errors magically
+ scanner(q, shortcircuit);
+ str = next+1;
+ }
+ }
+
/* Deal with failures to match depending on options */
if (matchct)
--
2.6.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author