zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Allow slash in alternation patterns in limited cases?
Date: Sun, 10 Apr 2016 15:11:05 -0700	[thread overview]
Message-ID: <160410151105.ZM21544@torch.brasslantern.com> (raw)
In-Reply-To: <CAHYJk3TY5kU0fXDkk2iO7kRJhhMTS1f4a9Am1ueN4wCXOQ7Hsg@mail.gmail.com>

On Apr 10, 10:36pm, Mikael Magnusson wrote:
}
} /path/(to/file|or/another/file) # nope, too hard
} (/path/to/a/dir/*|/path/to/some/other/files/*) # can we allow this?

My gut feeling is that this is close to impossible.  In fact your first
example might actually be easier than your second, because there are no
pattern characters within the alternation.  Similarly I think
    (/path/to/a/dir|/path/to/some/other/files)/*
would be easier than the case where the wildcard is inside the parens,
because an opendir() might be forced on each fixed path.

} If not, would it be possible to invent some new syntax to "paste" two
} or more globs together so that a single set of glob
} quals/sorts/flags/subscripts could apply to it?

Syntactically, this would probably work best as a parameter expansion
flag, which accepts a glob qualifier and applies it to every value in
the (array) expansion.  I'm not sure if there are any letters left for
this; we've reserved (_:stuff:) for future use, so possibly something
like e.g. ${(_:#qom[1]:)array} would work.  I insert the #q so that
other stuff in (_:stuff:) might still be adopted in future.

(Also is the above equivalent to ${${(_:#qom:)array}[1]} and if so do
we prohibit the qualifier subscripting in this form?)

Internally, to make this fly, the glob.c:zglob() function must be
factored apart into the bit that parses glob flags, the bit that makes
the call to scanner() [which would get called in a loop over the array
elements], and finally the bit that handles gf_sortlist and makes the
calls to insert_glob_match().

This is probably a significant effort because of the use of C globals
for glob state [although that might be easier since workers/38188].

Of course readability takes a major dive here as we're mating together
our two most cryptic bits of syntax into a single monster.  The only
other idea I have is to use a command form like

    zglob -q 'om[1]' $array

which to substitute-in place like a normal glob would need to be written

    echo $(zglob -q 'om[1]' $array)

which for efficiency would mean we implement the ksh-style non-fork of
builtins appearing in $(...), and now we're down another rabbit hole.


  reply	other threads:[~2016-04-10 22:10 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-10 20:36 Mikael Magnusson
2016-04-10 22:11 ` Bart Schaefer [this message]
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       ` PATCH: Allow / in full pattern alternations Mikael Magnusson
2016-04-11 13:47         ` 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=160410151105.ZM21544@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).