zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Re: Why no $match for parens inside a ~^ ?
Date: Wed, 25 Jan 2023 16:31:40 +0000	[thread overview]
Message-ID: <CAKc7PVAvsOFkPjJ0syPe5FnXEwOJJYvQXyELXE892ZSCaOZdXw@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVAi_sV+=NELcYuwH4Tf4i=XH+p6_=eaen-Yq0d+t5LQYw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2097 bytes --]

I've found a workaround for testing of -F has been given in one go – via
the super cool negation `~`:

QE='zparseopts qqq -F afwe'
print ${QE//(#b)zparseopts(*~*-F*~*-)(-F|)*/°match°}
printf °%s\\n "$match[@]" $?

Output:
°match°
° qqq
°-F
°0

So the -F exists there in $match[3] for testing if it has been given to
zparseopts. The main point is the ~ rejection of -F on part of the input
string:

…(*~*-F*~*-)…

It translates: everything (*) but not -F (~*-F*) and in that subset, also
not dash = (~*-). Without the ~*- it would match "not -F", so "-" from
within it is still allowed:

QE='zparseopts qqq -F afwe'
print ${QE//(#b)zparseopts(*~*-F*)(-F|)*/°match°}
printf °%s\\n "$match[@]" $?

Output:

°match°
° qqq -
°
°0

With it and with ~*-F* it correctly accepts other options:

QE='zparseopts qqq -q -F afwe'
print ${QE//(#b)zparseopts(*~*-F*~*-)(-F|)*/°match°}
printf °%s\\n "$match[@]" $?

Output:

°match°
° qqq -q
°-F
°0

I think that this demonstrates the uniqueness of Zsh pattern negations.
That really should be available in regexps.



On Wed, 25 Jan 2023 at 14:52, Sebastian Gniazdowski <sgniazdowski@gmail.com>
wrote:

> PS. (#b) is missing in the pattern, correct code is:
> [[ "zparseopts -F" == (#b)*(zparseopts)*~^*(-F)* ]]
> printf →%s\\n $? "$match[@]"
>
> output is the same.
>
>
> On Wed, 25 Jan 2023 at 14:50, Sebastian Gniazdowski <
> sgniazdowski@gmail.com> wrote:
>
>> Hi,
>> I'm matching a pattern:
>> [[ "zparseopts -F" == *(zparseopts)*~^*(-F)* ]]
>> printf →%s\\n $? "$match[@]"
>>
>> with output:
>> →0
>> →zparseopts
>> →
>>
>> I would want \3 to contain -F… because, I would once want to use (-F|)
>> there, and be able to test if the option is given… Is it possible?
>>
>> ~^ is a double negation that makes the pattern work like "if-contains
>> zparseopts AND -F"
>>
>>
>> --
>> Best regards,
>> Sebastian Gniazdowski
>>
>>
>
> --
> Best regards,
> Sebastian Gniazdowski
>
>

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 6473 bytes --]

  reply	other threads:[~2023-01-25 16:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-25 14:50 Sebastian Gniazdowski
2023-01-25 14:52 ` Sebastian Gniazdowski
2023-01-25 16:31   ` Sebastian Gniazdowski [this message]
2023-01-25 22:05   ` Bart Schaefer
2023-01-26 14:45     ` Sebastian Gniazdowski

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=CAKc7PVAvsOFkPjJ0syPe5FnXEwOJJYvQXyELXE892ZSCaOZdXw@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-users@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).