zsh-workers
 help / color / mirror / code / Atom feed
* Abort on parse errors
@ 1998-07-01 16:18 Peter Stephenson
  1998-07-01 18:32 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 1998-07-01 16:18 UTC (permalink / raw)
  To: Zsh hackers list

I don't know how controversial this is going to be, but here is one
way of making the shell abort the current command level on a parse
error.  The logic is (1) don't abort if noerrexit was set, which
means, for example, continue parsing initialisation scripts (2) don't
abort if executing at top level and SHINSTDIN is set, which covers
interactive shells (3) otherwise abort if there was an error parsing
the last input: this includes scripts and explicit sources.  Functions
are different since they won't be available unless they parsed cleanly
anyway.

It seemed more appropriate to pick SHINSTDIN instead of INTERACTIVE,
since that's the option that tells you the shell is sitting waiting
for input rather than reading it from a file, which is just the
circumstance when you don't want the shell to abort on unparseable
input: the difference appears, for example, when the whole shell is
running as a coprocess (no exit in this case).

Ksh will even abort initialisation scripts if they have a parse error.

*** Src/init.c.err	Fri May  8 11:52:18 1998
--- Src/init.c	Wed Jul  1 17:53:25 1998
***************
*** 98,104 ****
  	lexinit();              /* initialize lexical state */
  	if (!(list = parse_event())) {	/* if we couldn't parse a list */
  	    hend();
! 	    if ((tok == ENDINPUT && !errflag) || justonce)
  		break;
  	    continue;
  	}
--- 98,106 ----
  	lexinit();              /* initialize lexical state */
  	if (!(list = parse_event())) {	/* if we couldn't parse a list */
  	    hend();
! 	    if ((tok == ENDINPUT && !errflag) ||
! 		(tok == LEXERR && !noerrexit &&
! 		 (!isset(SHINSTDIN) || !toplevel)) || justonce)
  		break;
  	    continue;
  	}
*** Src/main.c.err	Wed Jul  1 17:38:15 1998
--- Src/main.c	Wed Jul  1 17:53:48 1998
***************
*** 75,81 ****
      for (;;) {
  	do
  	    loop(1,0);
! 	while (tok != ENDINPUT);
  	if (!(isset(IGNOREEOF) && interact)) {
  #if 0
  	    if (interact)
--- 75,86 ----
      for (;;) {
  	do
  	    loop(1,0);
! 	while (tok != ENDINPUT &&
! 	       (tok != LEXERR || noerrexit || isset(SHINSTDIN)));
! 	if (tok == LEXERR) {
! 	    stopmsg = 1;
! 	    zexit(lastval, 0);
! 	}
  	if (!(isset(IGNOREEOF) && interact)) {
  #if 0
  	    if (interact)


-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 50 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

* Re: Abort on parse errors
  1998-07-01 16:18 Abort on parse errors Peter Stephenson
@ 1998-07-01 18:32 ` Bart Schaefer
  1998-07-02 12:14   ` Peter Stephenson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1998-07-01 18:32 UTC (permalink / raw)
  To: Zsh hackers list

On Jul 1,  6:18pm, Peter Stephenson wrote:
} Subject: Abort on parse errors
}
} I don't know how controversial this is going to be

Looks fine to me.

} It seemed more appropriate to pick SHINSTDIN instead of INTERACTIVE

I agree.

} Ksh will even abort initialisation scripts if they have a parse error.

Which this will, too, given `setopt errexit`, right?  I think that's fine,
but perhaps in ksh emulation mode it should behave differently ...

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


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

* Re: Abort on parse errors
  1998-07-01 18:32 ` Bart Schaefer
@ 1998-07-02 12:14   ` Peter Stephenson
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 1998-07-02 12:14 UTC (permalink / raw)
  To: Zsh hackers list

"Bart Schaefer" wrote:
> } Ksh will even abort initialisation scripts if they have a parse error.
> 
> Which this will, too, given `setopt errexit`, right?  I think that's fine,

The reference in the code to noerrexit is a bit confusing: it isn't
directly connected to the errexit option, it just specifies that there
shouldn't be an exit on an error whether the option's set or not.  I
used it because it seemed to give the best way of deciding when to
ignore parse errors.  (I hate being dumped out of initialisation
scripts, emacs does it to me all the time.)

> but perhaps in ksh emulation mode it should behave differently ...

True:  in that case the `!noerrexit' in init.c becomes
(!noerrexit || emulate == EMULATE_KSH)
--- it's not necessary in main.c at least in this case, in fact I'm
not sure if the noerrexit test there is useful.

*** Src/init.c.err2	Wed Jul  1 17:53:25 1998
--- Src/init.c	Thu Jul  2 14:01:21 1998
***************
*** 99,106 ****
  	if (!(list = parse_event())) {	/* if we couldn't parse a list */
  	    hend();
  	    if ((tok == ENDINPUT && !errflag) ||
! 		(tok == LEXERR && !noerrexit &&
! 		 (!isset(SHINSTDIN) || !toplevel)) || justonce)
  		break;
  	    continue;
  	}
--- 99,106 ----
  	if (!(list = parse_event())) {	/* if we couldn't parse a list */
  	    hend();
  	    if ((tok == ENDINPUT && !errflag) ||
! 		(tok == LEXERR && (!noerrexit || emulation == EMULATE_KSH)
! 		 && (!isset(SHINSTDIN) || !toplevel)) || justonce)
  		break;
  	    continue;
  	}

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy



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

end of thread, other threads:[~1998-07-02 12:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-07-01 16:18 Abort on parse errors Peter Stephenson
1998-07-01 18:32 ` Bart Schaefer
1998-07-02 12:14   ` Peter Stephenson

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