zsh-workers
 help / color / mirror / code / Atom feed
From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: schaefer@nbn.com
Cc: pws@ifh.de, zsh-workers@math.gatech.edu
Subject: Re: cshjunkieparen bothers me (and always has)
Date: Thu, 4 Jul 1996 15:14:49 +0200 (MET DST)	[thread overview]
Message-ID: <199607041314.PAA11866@bolyai.cs.elte.hu> (raw)
In-Reply-To: <960702123554.ZM4790@candle.brasslantern.com> from Bart Schaefer at "Jul 2, 96 12:35:50 pm"

> I *think* this is what happened:
> 
> Cshjunkieparen at one time affected whether
> 
> 	if [[ $TERM == xterm ]] then
> 
> would work.  This was the csh compatibility feature, even though it
> wasn't precisely csh syntax.  I have no idea why "paren" was used in
> the name of the option.

This syntax is really a ksh compatibility syntax.  But by a more general
rure it is a POSIX compatibility syntax.  POSIX does not requires separator
before then so the syntax

if (subshell ...) then

should be accepted by a POSIX shell.  The accepted syntax is

if compound_list then compound_list fi

So

if true ; false ; true ; then echo yes ; fi

is valid, and should print yes.  The semicolon before then is necessary
to recognize then as a reserved word.

POSIX also states that reserved words are recognized after one of the
reserved words other than case, for, or in.  In ksh [[ and ]] are reserved
words so it is not necessary to use a semicolon before then (in zsh [[ is
not a reserved word but it behaves similarily).

> However, par_list() now permits empty statements, consuming all trailing
> SEPER tokens; so by necessity par_if() no longer requires a SEPER before
> the "then".

POSIX does not seem to allow that but the zsh behaviour is more logical.
The biggest problem using braces instead of then ... fi is the following:

if (true)
{ echo yes; }

The patch I posted recently to the manual says that it is equivalent to

if (true)
then
	echo yes
fi

But that's not true since par_list parses a list as long as it is possible
so the above is the same as

if (true) ; { echo yes; }

And now a then or an open brace should come after some semicolons.  I think
csh junkies do not like that change.

if true {
	echo yes
}

does not work either since { behaves like a reserved word (POSIX says that
{ and } should be reserved words).

if (true) {
	echo yes
}

works since a separator must come after a subshell so par_list could not
continue parsing of the list.

if [[ foo -eq 13 ]] {
	echo yes
}

and

if ((foo == 13)) {
	echo yes
}

works for similar reasons.  As it turns out { can only be used in place of
if when it comes after a ) terminating a subshell or a ]] terminating a
conditional command.  When csh_junkie_paren was on zsh digested an open
parenthesis before calling par_list which terefore stopped before the
matching closing parenthesis.  To summarize this after Bart's patch the

if (foo)
{
	...
}

syntax will not work but the

if (foo) {
	...
}

syntax still works.

Zoltan



  reply	other threads:[~1996-07-04 13:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-06-30  7:19 Bart Schaefer
1996-07-01 19:19 ` Bart Schaefer
1996-07-01 21:02   ` Zoltan Hidvegi
1996-07-01 21:35     ` Anthony Heading
1996-07-02  1:03       ` Bart Schaefer
1996-07-02  8:48   ` Peter Stephenson
1996-07-02 19:35     ` Bart Schaefer
1996-07-04 13:14       ` Zoltan Hidvegi [this message]
1996-07-04 15:58         ` 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=199607041314.PAA11866@bolyai.cs.elte.hu \
    --to=hzoli@cs.elte.hu \
    --cc=pws@ifh.de \
    --cc=schaefer@nbn.com \
    --cc=zsh-workers@math.gatech.edu \
    /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).