zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: chris0e3@gmail.com
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: [PATCH?] Re: [BUG] `$match` is haunting my regex’s trailing, optional, capture
Date: Sat, 9 Dec 2023 12:54:56 -0800	[thread overview]
Message-ID: <CAH+w=7bSrq8p8-LNbn-M-Fkigo1GP3S=5+uXho5zw3bJxXBbBQ@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7b8tF16GhZvpcF8urVV-tAAY6DHFRwp=7QNUfA27QxJhA@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 866 bytes --]

On Fri, Dec 8, 2023 at 10:23 PM Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Fri, Dec 8, 2023 at 9:14 PM <chris0e3@gmail.com> wrote:
> >
> >   setopt rematch_pcre
> >   [[ 'REQUIRE. OPT' =~ 'REQUIRE.(\s*OPT)?' ]] && printf '\tA. ‹%s›\n'
> $match
> >   [[ 'REQUIRE.'     =~ 'REQUIRE.(\s*OPT)?' ]] && printf '\tB. ‹%s›\n'
> $match
>
> [...] I can reproduce your example with the most recent git checkout, as
> well.  Oliver recently updated to pcre2, so if a patch appears, you
> may be on your own to backport it.
>

This was easier to track down than I feared, but possibly difficult to
handle correctly.

Is "unset match" OK here?  There doesn't seem to be an obvious way to
distinguish "there are capture expressions, but none matched anything" from
"there were no capture expressions".  Maybe Oliver has a better clue.

[-- Attachment #1.2: Type: text/html, Size: 1398 bytes --]

[-- Attachment #2: pcre-unset-match.txt --]
[-- Type: text/plain, Size: 444 bytes --]

diff --git a/Src/Modules/pcre.c b/Src/Modules/pcre.c
index e48ae3ae5..e4cdd8dbd 100644
--- a/Src/Modules/pcre.c
+++ b/Src/Modules/pcre.c
@@ -210,7 +210,8 @@ zpcre_get_substrings(pcre2_code *pat, char *arg, pcre2_match_data *mdata,
 	    }
 	    *x = NULL;
 	    setaparam(substravar, matches);
-	}
+	} else if (substravar)
+	    unsetparam(substravar);
 
 	if (namedassoc
 		&& !pcre2_pattern_info(pat, PCRE2_INFO_NAMECOUNT, &ncount) && ncount

  reply	other threads:[~2023-12-09 20:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-09  5:14 chris0e3
2023-12-09  6:23 ` Bart Schaefer
2023-12-09 20:54   ` Bart Schaefer [this message]
2023-12-11 23:49     ` [PATCH?] " Oliver Kiddle
2023-12-12  1:38       ` Bart Schaefer
2024-01-25 22:14         ` Oliver Kiddle

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='CAH+w=7bSrq8p8-LNbn-M-Fkigo1GP3S=5+uXho5zw3bJxXBbBQ@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=chris0e3@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).