From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26076 invoked from network); 1 Jul 1998 16:32:05 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 1 Jul 1998 16:32:05 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id MAA07349; Wed, 1 Jul 1998 12:23:22 -0400 (EDT) Resent-Date: Wed, 1 Jul 1998 12:23:22 -0400 (EDT) Message-Id: <9807011618.AA39366@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 From: Peter Stephenson Resent-Message-ID: <"HlFrq1.0.mo1.v9ccr"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4191 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu 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 Tel: +39 50 844536 WWW: http://www.ifh.de/~pws/ Gruppo Teorico, Dipartimento di Fisica Piazza Torricelli 2, 56100 Pisa, Italy