Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh bug in . builtin
- X-seq: zsh-workers 27092
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: zsh bug in . builtin
- Date: Mon, 6 Jul 2009 21:39:49 +0100
- In-reply-to: <loom.20090702T115609-92@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <4A4B614E.7000406@xxxxxxx> <20090701152420.2beb1c78@news01> <loom.20090702T115609-92@xxxxxxxxxxxxxx>
On Thu, 2 Jul 2009 12:01:11 +0000 (UTC)
Eric Blake <ebb9@xxxxxxx> wrote:
> Also, you may want to consistently detect syntax errors in eval and in the
> action to trap:
>
> $ zsh -c 'eval "if"; echo $?'
> 0
The problem isn't in eval or trap. The problem is that the short form
of "if" (which is an abomination anyway and no one should use) isn't
tested properly.
Adding the test below to the parser should fix it. My heart sank when
this caused a failure in the test system---however, having read the
manual again, that test should never have worked, since the if-clause
wasn't delimited, which is the prerequisite for the syntax to work. The
old if-clause therefore extended to the end of the evaluated block and
the then-clause was missing, so failing is correct. (If you're not
convinced, try eval'ing "if false; print False is true" and you'll see
it gets to the "print", because it's still looking for the end of the
if-clause at that point.) I've fixed the tests.
Index: Src/parse.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/parse.c,v
retrieving revision 1.79
diff -u -r1.79 parse.c
--- Src/parse.c 25 Feb 2009 10:24:01 -0000 1.79
+++ Src/parse.c 6 Jul 2009 20:28:56 -0000
@@ -1199,6 +1199,10 @@
type = (xtok == IF ? WC_IF_IF : WC_IF_ELIF);
par_save_list(complex);
incmdpos = 1;
+ if (tok == ENDINPUT) {
+ cmdpop();
+ YYERRORV(oecused);
+ }
while (tok == SEPER)
zshlex();
xtok = FI;
Index: Test/A01grammar.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A01grammar.ztst,v
retrieving revision 1.21
diff -u -r1.21 A01grammar.ztst
--- Test/A01grammar.ztst 2 Jul 2009 13:48:36 -0000 1.21
+++ Test/A01grammar.ztst 6 Jul 2009 20:28:56 -0000
@@ -378,10 +378,15 @@
>true-2
>false
- if true; print true
+ if { true } print true
+ if { false } print false
0:Short form of `if'
>true
+ eval "if"
+1:Short form of `if' can't be too short
+?(eval):1: parse error near `if'
+
for name ( word1 word2 word3 ) print $name
0:Form of `for' with parentheses.
>word1
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author