zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Abort on parse errors
Date: Wed, 01 Jul 1998 18:18:15 +0200	[thread overview]
Message-ID: <9807011618.AA39366@ibmth.df.unipi.it> (raw)

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


             reply	other threads:[~1998-07-01 16:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-07-01 16:18 Peter Stephenson [this message]
1998-07-01 18:32 ` Bart Schaefer
1998-07-02 12:14   ` Peter Stephenson

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=9807011618.AA39366@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --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).