zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Builtin test and parsing of conditionals
Date: Wed, 04 Sep 2013 09:15:03 -0700	[thread overview]
Message-ID: <130904091503.ZM28369@torch.brasslantern.com> (raw)

According to some discussion on the austin-group (POSIX) mailing list,
the following:

	test ! -a !
	test ! -o !
	test ! = !

should all be parsed as comparing the string "!" to the string "!", but
zsh gets this right only in the last case.

This is especially annoying because

	test ! -f !

should be interpreted as the negation of the unary file-exists operator.

This is probably complicated by the different meanings of -a and -o in
[[ ... ]] as opposed to "test" because the same parser is used.

Furthermore:

	test ! = -o a

should be parsed as the negation of the comparison between the strings "="
and "a", implying that zsh also gets this wrong:

	test ! = = =

which should return false (negation of (equal is the same string as equal)),
rather than give a parse error as zsh does.  (Zsh does get

	test = = =

right.)

Apparently the only way to do this correctly is to examine both argv[1] and
the number of arguments, and skip to argv[2] for recursive descent parsing
when argv[1] is "!" and there are four arguments.  (As already mentioned in
the zsh manual, what to do with more than four arguments in the absence of
explicit parens is unclear [unspecified?].)


             reply	other threads:[~2013-09-04 16:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-04 16:15 Bart Schaefer [this message]
2013-09-04 16:31 ` Peter Stephenson
2013-09-04 17:39   ` Bart Schaefer
2013-09-04 19:09     ` Peter Stephenson
2013-09-05 14:25       ` Bart Schaefer
2013-09-06 19:20         ` Peter Stephenson
2013-09-04 20:15     ` Chet Ramey

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=130904091503.ZM28369@torch.brasslantern.com \
    --to=schaefer@brasslantern.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).