From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: Allow / in full pattern alternations
Date: Mon, 11 Apr 2016 14:06:14 +0200 [thread overview]
Message-ID: <1460376374-9081-1-git-send-email-mikachu@gmail.com> (raw)
In-Reply-To: <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
next prev parent reply other threads:[~2016-04-11 13:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-10 20:36 Allow slash in alternation patterns in limited cases? Mikael Magnusson
2016-04-10 22:11 ` Bart Schaefer
2016-04-11 8:37 ` Peter Stephenson
2016-04-11 10:22 ` Mikael Magnusson
2016-04-11 10:29 ` Peter Stephenson
2016-04-11 10:47 ` Mikael Magnusson
2016-04-11 11:07 ` Peter Stephenson
2016-04-11 12:06 ` Mikael Magnusson
2016-04-11 12:31 ` Peter Stephenson
2016-04-11 13:45 ` Mikael Magnusson
2016-04-11 13:50 ` Peter Stephenson
2016-04-11 12:06 ` Mikael Magnusson [this message]
2016-04-11 13:47 ` PATCH: Allow / in full pattern alternations Peter Stephenson
2016-04-11 14:46 ` Bart Schaefer
2016-04-11 14:44 ` Bart Schaefer
2016-04-11 14:50 ` Allow slash in alternation patterns in limited cases? Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460376374-9081-1-git-send-email-mikachu@gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).