Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Abort on parse errors
- X-seq: zsh-workers 4191
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Abort on parse errors
- Date: Wed, 01 Jul 1998 18:18:15 +0200
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@xxxxxxxxxxxxxxxxx> Tel: +39 50 844536
WWW: http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author