zsh-users
 help / color / mirror / code / Atom feed
* Suggested "case" syntax extension
@ 1996-07-08 23:46 Morris M. Siegel
  1996-07-09  0:33 ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Morris M. Siegel @ 1996-07-08 23:46 UTC (permalink / raw)
  To: zsh-users; +Cc: segal

Newer versions of ksh allow an optional '(' before each pattern in a case
statement, complementary to the mandatory ')' following the pattern.  As
well as being esthetically symmetric, this also facilitates verifying that
a shell script has balanced parentheses (e.g. with the '%' command in vi).

It seems that zsh still recognizes only the classic Bourne shell syntax for
"case", with the ')' but no optional '('.  Considering all the syntactic
variation zsh supports, it would be quite reasonable for zsh to allow a
leading '(', thereby enhancing compatibility with ksh scripts.  Although
I have not looked into the zsh source, I imagine this should not pose an
implementation problem.

-- Morrie Siegel



edit



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

* Re: Suggested "case" syntax extension
  1996-07-08 23:46 Suggested "case" syntax extension Morris M. Siegel
@ 1996-07-09  0:33 ` Zoltan Hidvegi
  1996-07-09 20:09   ` Morris M. Siegel
  0 siblings, 1 reply; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-07-09  0:33 UTC (permalink / raw)
  To: Morris M. Siegel; +Cc: zsh-users, segal

> Newer versions of ksh allow an optional '(' before each pattern in a case
> statement, complementary to the mandatory ')' following the pattern.  As
> well as being esthetically symmetric, this also facilitates verifying that
> a shell script has balanced parentheses (e.g. with the '%' command in vi).
> 
> It seems that zsh still recognizes only the classic Bourne shell syntax for
> "case", with the ')' but no optional '('.  Considering all the syntactic
> variation zsh supports, it would be quite reasonable for zsh to allow a
> leading '(', thereby enhancing compatibility with ksh scripts.  Although
> I have not looked into the zsh source, I imagine this should not pose an
> implementation problem.

Zsh accepts an optional leading '(' since 2.6-beta21.  POSIX 1003.2
requires this.  It also allows us to use case sttement in $(...) command
substitutions (of course even a normal case should work in a command
substitution but the zsh implementation requires ballanced parentheses like
bash and pdksh).

Zsh is not completely ksh compatible here since due to the enhanced glob
pattern syntax recognized by zsh if there is a leading '(' the closing ')'
must be delimited with a blank from the command following that.  So

case foo in
(f*)echo yes;;
(*)echo no;;
esac

does not work in zsh but

case foo in
(f*) echo yes;;
(*) echo no;;
esac

works.

Zoltan



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

* Re: Suggested "case" syntax extension
  1996-07-09  0:33 ` Zoltan Hidvegi
@ 1996-07-09 20:09   ` Morris M. Siegel
  1996-07-09 21:07     ` Zoltan Hidvegi
  0 siblings, 1 reply; 4+ messages in thread
From: Morris M. Siegel @ 1996-07-09 20:09 UTC (permalink / raw)
  To: Zoltan Hidvegi; +Cc: zsh-users

On Jul 9,  2:33am, Zoltan Hidvegi wrote:
> Subject: Re: Suggested "case" syntax extension
> > Newer versions of ksh allow an optional '(' before each pattern in a case
> > statement, complementary to the mandatory ')' following the pattern.  As
> > well as being esthetically symmetric, this also facilitates verifying that
> > a shell script has balanced parentheses (e.g. with the '%' command in vi).
> >
> > It seems that zsh still recognizes only the classic Bourne shell syntax for
> > "case", with the ')' but no optional '('.  Considering all the syntactic
> > variation zsh supports, it would be quite reasonable for zsh to allow a
> > leading '(', thereby enhancing compatibility with ksh scripts.  Although
> > I have not looked into the zsh source, I imagine this should not pose an
> > implementation problem.
>
> Zsh accepts an optional leading '(' since 2.6-beta21.  POSIX 1003.2
> requires this.  It also allows us to use case sttement in $(...) command
> substitutions (of course even a normal case should work in a command
> substitution but the zsh implementation requires ballanced parentheses like
> bash and pdksh).
>
> Zsh is not completely ksh compatible here since due to the enhanced glob
> pattern syntax recognized by zsh if there is a leading '(' the closing ')'
> must be delimited with a blank from the command following that.  So
>
> case foo in
> (f*)echo yes;;
> (*)echo no;;
> esac
>
> does not work in zsh but
>
> case foo in
> (f*) echo yes;;
> (*) echo no;;
> esac
>
> works.
>
> Zoltan
>-- End of excerpt from Zoltan Hidvegi
______________________________________

I'm glad to learn this has already been implemented.  (The last time I tried it
was with 2.6-beta20, I believe.)  However, I double-checked in the zsh-3.0-pre2
distribution, and both man/man1/zshmisc.1 and Doc/zshmisc.man lack any mention
of an optional leading '('.  This should be fairly easy to remedy.

-- Morrie Siegel



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

* Re: Suggested "case" syntax extension
  1996-07-09 20:09   ` Morris M. Siegel
@ 1996-07-09 21:07     ` Zoltan Hidvegi
  0 siblings, 0 replies; 4+ messages in thread
From: Zoltan Hidvegi @ 1996-07-09 21:07 UTC (permalink / raw)
  To: Morris M. Siegel; +Cc: zsh-users

> > case foo in
> > (f*) echo yes;;
> > (*) echo no;;
> > esac
> >
> > works.
>
> I'm glad to learn this has already been implemented.  (The last time I tried it
> was with 2.6-beta20, I believe.)  However, I double-checked in the zsh-3.0-pre2
> distribution, and both man/man1/zshmisc.1 and Doc/zshmisc.man lack any mention
> of an optional leading '('.  This should be fairly easy to remedy.

Here it is.  It also improves parsing a little bit.

Zoltan


*** Src/parse.c	1996/07/08 01:56:51	2.16
--- Src/parse.c	1996/07/09 20:57:16
***************
*** 488,494 ****
      lists = newlinklist();
      for (;;) {
  	char *str;
- 	int barct;
  
  	while (tok == SEPER)
  	    yylex();
--- 488,493 ----
***************
*** 503,515 ****
  	    break;
  	}
  	str = tokstr;
- 	barct = 0;
  	yylex();
  	while (tok == BAR) {
  	    char *str2;
  	    int sl = strlen(str);
  
- 	    barct++;
  	    yylex();
  	    if (tok == OUTPAR) {
  		str2 = ncalloc(sl + 2);
--- 502,512 ----
***************
*** 532,538 ****
  	incmdpos = 1;
  	if (tok != OUTPAR) {
  	    /* POSIX allows (foo*) patterns */
! 	    if (barct || str[strlen(str)-1] != Outpar)
  		YYERRORV;
  	} else
  	    yylex();
--- 529,537 ----
  	incmdpos = 1;
  	if (tok != OUTPAR) {
  	    /* POSIX allows (foo*) patterns */
! 	    char *s = str;
! 
! 	    if (skipparens(Inpar, Outpar, &s) || *s)
  		YYERRORV;
  	} else
  	    yylex();
*** Doc/zshmisc.man	1996/07/07 16:00:21	2.10
--- Doc/zshmisc.man	1996/07/09 21:00:13
***************
*** 172,178 ****
  .PP
  .PD 0
  .TP
! \fBcase\fP \fIword\fP \fBin\fP [ \fIpattern\fP ) \fIlist\fP ;; ] ...  \fBesac\fP
  Execute the \fIlist\fP associated with the first \fIpattern\fP
  that matches \fIword\fP, if any.  The form of the patterns
  is the same as that used for filename generation.  See
--- 172,178 ----
  .PP
  .PD 0
  .TP
! \fBcase\fP \fIword\fP \fBin\fP [ [\fB(\fP] \fIpattern\fP \fB)\fP \fIlist\fP ;; ] ...  \fBesac\fP
  Execute the \fIlist\fP associated with the first \fIpattern\fP
  that matches \fIword\fP, if any.  The form of the patterns
  is the same as that used for filename generation.  See
***************
*** 181,187 ****
  .PP
  .PD 0
  .TP
! \fBcase\fP \fIword\fP \fB{\fP [ \fIpattern\fP ) \fIlist\fP ;; ] ...  \fB}\fP
  Another form of \fBcase\fP.
  .PD
  .PP
--- 181,187 ----
  .PP
  .PD 0
  .TP
! \fBcase\fP \fIword\fP \fB{\fP [ [\fB(\fP] \fIpattern\fP \fB)\fP \fIlist\fP ;; ] ...  \fB}\fP
  Another form of \fBcase\fP.
  .PD
  .PP
*** Doc/zsh.texi	1996/07/09 17:11:50	2.7
--- Doc/zsh.texi	1996/07/09 21:02:23
***************
*** 616,622 ****
  @item repeat @var{word} @var{sublist}
  This is a short form of @code{repeat}.
  
! @item case @var{word} in [ @var{pattern} ) @var{list} ;; ] @dots{} esac
  @findex case
  @cindex case selection
  @cindex selection, case
--- 616,622 ----
  @item repeat @var{word} @var{sublist}
  This is a short form of @code{repeat}.
  
! @item case @var{word} in [ [(] @var{pattern} ) @var{list} ;; ] @dots{} esac
  @findex case
  @cindex case selection
  @cindex selection, case
***************
*** 624,630 ****
  matches @var{word}, if any.  The form of the patterns is the same as
  that used for filename generation.  @xref{Filename Generation}.
  
! @item case @var{word} @{ [ @var{pattern} ) @var{list} ;; ] @dots{} @}
  Another form of @code{case}.
  
  @item select @var{name} [ in @var{word} @dots{} ]
--- 624,630 ----
  matches @var{word}, if any.  The form of the patterns is the same as
  that used for filename generation.  @xref{Filename Generation}.
  
! @item case @var{word} @{ [ [(] @var{pattern} ) @var{list} ;; ] @dots{} @}
  Another form of @code{case}.
  
  @item select @var{name} [ in @var{word} @dots{} ]



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

end of thread, other threads:[~1996-07-09 21:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-08 23:46 Suggested "case" syntax extension Morris M. Siegel
1996-07-09  0:33 ` Zoltan Hidvegi
1996-07-09 20:09   ` Morris M. Siegel
1996-07-09 21:07     ` Zoltan Hidvegi

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