zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@zsh.org
Subject: Re: behavior of test true -a \( ! -a \)
Date: Thu, 21 Mar 2024 11:29:39 +0000 (GMT)	[thread overview]
Message-ID: <1507569659.5899391.1711020579178@mail.virginmedia.com> (raw)
In-Reply-To: <20240321110444.GC164665@qaa.vinc17.org>

> On 21/03/2024 11:04 GMT Vincent Lefevre <vincent@vinc17.net> wrote:
> On 2024-03-21 10:28:16 +0000, Peter Stephenson wrote:
> > I haven't had time to go through this completely but I think somewhere
> > near the root of the issue is this chunk in par_cond_2(), encountered at
> > the opint we get to the "!":
> > 
> >     if (tok == BANG) {
> > 	/*
> > 	 * In "test" compatibility mode, "! -a ..." and "! -o ..."
> > 	 * are treated as "[string] [and] ..." and "[string] [or] ...".
> > 	 */
> > 	if (!(n_testargs > 2 && (check_cond(*testargs, "a") ||
> > 				 check_cond(*testargs, "o"))))
> > 	{
> > 	    condlex();
> > 	    ecadd(WCB_COND(COND_NOT, 0));
> > 	    return par_cond_2();
> > 	}
> >     }
> > 
> > in which case it needs yet more logic to decide why we shouldn't treat !
> > -a as a string followed by a logical "and" in this case.  To be clear,
> > obviously *I* can see why you want that, the question is teaching the
> > code without confusing it further.
> 
> Perhaps follow the coreutils logic. What matters is that if there is
> a "(" argument, it tries to look at a matching ")" argument among the
> following 3 arguments. So, for instance, if it can see
> 
>   ( arg2 arg3 )
> 
> (possibly with other arguments after the closing parenthesis[*]), it
> will apply the POSIX test on 4 arguments.
> 
> [*] which can make sense if the 5th argument is -a or -o.

I suppose as long as we only look for ")" when we know there's one to
match we can probably get away with it without being too clever.  If
there's a ")" that logically needs to be treated as a string following a
"(" we're stuck but I think that's fair game.

Something simple like: if we find a (, look for a matching ), so blindly
count intervening ('s and )'s regardless of where they occur, and then
NULL out the matching ) temporarily until we've parsed the expression
inside.  If we don't find a matching one treat the ( as as a string.

pws


  reply	other threads:[~2024-03-21 11:30 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-21 10:07 Vincent Lefevre
2024-03-21 10:28 ` Peter Stephenson
2024-03-21 11:04   ` Vincent Lefevre
2024-03-21 11:29     ` Peter Stephenson [this message]
2024-03-21 12:18       ` Vincent Lefevre
2024-03-21 12:25         ` Peter Stephenson
2024-03-21 19:06           ` Bart Schaefer
2024-03-22  5:02             ` Bart Schaefer
2024-03-25 16:38       ` Peter Stephenson
2024-03-25 17:36         ` Bart Schaefer
2024-04-03 13:59           ` Vincent Lefevre
2024-03-21 17:39 ` Bart Schaefer
2024-03-23 21:48   ` Bart Schaefer
2024-03-23 22:20     ` Vincent Lefevre
2024-03-23 22:41       ` Bart Schaefer
2024-03-23 23:33         ` Lawrence Velázquez
2024-03-24  0:14           ` Bart Schaefer
2024-03-24  2:52             ` Lawrence Velázquez
2024-03-25 10:23         ` Vincent Lefevre
2024-03-25 15:21           ` Bart Schaefer
2024-03-25 17:33             ` Vincent Lefevre
2024-03-25 17:43               ` 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=1507569659.5899391.1711020579178@mail.virginmedia.com \
    --to=p.w.stephenson@ntlworld.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).