zsh-workers
 help / color / mirror / code / Atom feed
* Builtin test and parsing of conditionals
@ 2013-09-04 16:15 Bart Schaefer
  2013-09-04 16:31 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2013-09-04 16:15 UTC (permalink / raw)
  To: zsh-workers

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?].)


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-09-06 19:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-04 16:15 Builtin test and parsing of conditionals Bart Schaefer
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

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).