Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: cshjunkieparen bothers me (and always has)



> 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




Messages sorted by: Reverse Date, Date, Thread, Author