Subject: Re: Allow slash in alternation patterns in limited cases?
From: Mikael Magnusson <[email-masked]>
To: Peter Stephenson <[email-masked]>
Cc: zsh workers <[email-masked]>
Date: Mon, 11 Apr 2016 12:22:49 +0200
List-Id: Zsh Workers List <zsh-workers.zsh.org>

On Mon, Apr 11, 2016 at 10:37 AM, Peter Stephenson
<[email-masked]> wrote:
> On Sun, 10 Apr 2016 15:11:05 -0700
> Bart Schaefer <[email-masked]> wrote:
>
>> 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.
>
> The problem's not the parsing, it's the fact that you don't have
> appropriate chunks corresponding to directories for the scanner to loop
> over once pattern matching has parsed it.
>
> The only way I can see is effectively to parse it first in the globbing
> code to treat a complete set of parentheses specially.

Yeah, that's what I had in mind too as the possibility. This is
probably naive but I imagined we would see the ( and go "ah, the
matching ) is at the end [and there's only glob qualifiers after it],
so i'll loop over each alternatee and push them on the pile of glob
results, and then apply the qualifiers".

> But this is
> going to be inconsistent with pattern matching one way or another.  So a
> different syntax would be more sensible.

Doesn't this already work as is with pattern matching? Eg, I could do
/path/to/**/*~^(/path/to/a/dir/*|/path/to/some/other/files/*)
even though that would be insanely inefficient, especially when
/path/to is just /.

>> } 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?
>
> I think Bart's answered this.

This occurred to me just now,
a=( (/path/to/a/dir/*|/path/to/some/other/files/*) )
echo .(e*'reply=($a)'*om[1])

This works syntactically, the only problem seems to be that sort
qualifiers do nothing on matches inserted by e::, nor do ones like .
and / (they all just act on the original . which is probably
reasonable). It's also pretty ugly to have to act on a dummy match.

-- 
Mikael Magnusson