zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Johan Grande <nahoj@crans.org>, zsh-workers@zsh.org
Subject: Re: Pattern bug on (a*|)~^(*b)
Date: Mon, 31 Jul 2023 12:36:06 +0100 (BST)	[thread overview]
Message-ID: <138967397.1507519.1690803366587@mail.virginmedia.com> (raw)
In-Reply-To: <599e3c13-53a5-1823-6d0d-68dd722967d9@crans.org>

> On 25/07/2023 14:19 Johan Grande <nahoj@crans.org> wrote:
> In zsh 5.8.1 (x86_64-ubuntu-linux-gnu) with extended_glob,
> 
> [[ "ab" = (|a*)~^(*b) ]]
> 
> incorrectly (unless I'm mistaken) returns 1. However
> 
> [[ "ab" = (a*|)~^(*b) ]]
> 
> correctly returns 0.

You can see this is a real bug with

[[ ab = (a|a*)~^*b ]]

which also fails, while

[[ ab = (b*|a*)~^*b ]]

succeeds, so this is clearly inconsistent.

I think I've tracked down the problem.  Because of the unpleasant
hierarchy-violating properties of exclusion pointed out by Bart, we record the
point at which the match succeeded.  The point we do this isn't where the
entire pattern succeeds, however, only the point where the part we're going to
exclude has matched.  So at this point we've successfully matched "a" in the
case I showed, or the empty string in the original case.  But we haven't yet
taken account of the anchor at the end, which will later cause us to fail.

When we do fail and backtrack, the marker is still there saying we matched just
the "a" or the empty string.  We then successfully match a*, but when we get
to the point of trying to exclude ^*b the record saying what we're excluding
against is messed up --- ^*b DOES match either a or the empty string, so
the exclusion succeeds.

The fixes I can think of are either to find a point at which to undo the sync
record for the match that has failed after the event or, perhaps better as it's
a local change even though it does more work, reset any previous matches before
the sync point on the next alternative when we mark that as having matched
(we will only do that if the previous branch failed --- remember [irony
intended] that a branch succeeds only if all following patterns match too).

This is a bit fraught as some of the markers (not necessarily these ones, it's
almost a quarter of a century since the first version of this code) are there
to take account of some pathological cases so removing them might have hard
to discover effects.  This will take another load of wet towels and caffeine.

pws


  parent reply	other threads:[~2023-07-31 11:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 13:19 Johan Grande
2023-07-25 18:35 ` Bart Schaefer
2023-07-25 18:47   ` Johan Grande
2023-07-28  1:02     ` Bart Schaefer
2023-07-28  6:41       ` Stephane Chazelas
2023-07-29  1:35         ` Bart Schaefer
2023-08-01 13:19           ` Johan Grande
2023-08-01 13:30             ` Peter Stephenson
2023-08-01 13:46               ` Johan Grande
2023-08-02  8:31               ` Johan Grande
2023-08-02  9:37                 ` Peter Stephenson
2023-07-31 11:36 ` Peter Stephenson [this message]
2023-07-31 15:21   ` Peter Stephenson

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=138967397.1507519.1690803366587@mail.virginmedia.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=nahoj@crans.org \
    --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).