From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12257 invoked by alias); 21 Aug 2015 14:52:57 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36265 Received: (qmail 26181 invoked from network); 21 Aug 2015 14:52:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-66-55d73b435fc2 Date: Fri, 21 Aug 2015 15:52:49 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: Anonymous function syntax and "sh" emulation Message-id: <20150821155249.3f773977@pwslap01u.europe.root.pri> In-reply-to: <150820211638.ZM29649@torch.brasslantern.com> References: <150820211638.ZM29649@torch.brasslantern.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrELMWRmVeSWpSXmKPExsVy+t/xq7rO1tdDDf4/07U42PyQyYHRY9XB D0wBjFFcNimpOZllqUX6dglcGZtefGYtOMlfMbvhPnsDYytPFyMnh4SAicTyzo/sELaYxIV7 69m6GLk4hASWMkrc2nCXGcKZwSTx898UKGcbo8SfU0dYuxg5OFgEVCU2tSeCdLMJGEpM3TSb EcQWERCXOLv2PAuILSxgKXHy6zNWEJtXwF6i4/pbRpBWTgErif+b/UDCQkAl81bcZwax+QX0 Ja7+/cQEcZC9xMwrZxghWgUlfky+BzaSWUBLYvO2JlYIW15i85q3zBBz1CVu3N3NPoFRaBaS lllIWmYhaVnAyLyKUTS1NLmgOCk911CvODG3uDQvXS85P3cTIyRkv+xgXHzM6hCjAAejEg/v jMhroUKsiWXFlbmHGCU4mJVEeD9bXg8V4k1JrKxKLcqPLyrNSS0+xCjNwaIkzjt31/sQIYH0 xJLU7NTUgtQimCwTB6dUAyP74X2+e6+yfhdSFNn6TuFRW+KTxRunXju7PNbvhlb4gdMl0Wdj 9P+Fmu4/sSZJwHer1+49/ZuNIuueeOiun7faQOyJmJLJuVlpU8MqlrWYHeHOXlH+0mLp7w75 fden3GZ6OWu+yPNV32wbbSf3nvjxW/yTd8cKo9WcHj96V+QXZf/06/99++I9JZbijERDLeai 4kQAYjHy4FUCAAA= On Thu, 20 Aug 2015 21:16:38 -0700 Bart Schaefer wrote: > This works in zsh emulation but not in sh emulation: > > function { print hello; } This is a combination of two effects. The one specific to sh is, as you might guess, IGNOREBRACES. Clearly we're not supposed to ignore a brace as the start of a function, so I think this can be considered a bug. I think compensating for this is unproblematic, since we see the raw string input coming from lex.c and hence any quoting that should stop this being treated as the start of a function, so I've done that. What's worried me is the other part of the effect, which isn't specific to sh emulation, which is that the first word after "function" is treated as not a command word, while the remaining words are treated as command words: % alias first='fn1 fn2' second='fn3 fn4' % function first second { print This is a function; } % functions first fn3 fn4 first () { print This is a function } fn3 () { print This is a function } fn4 () { print This is a function } I would hazard a guess this is a bad thing, which hasn't been noticed because multiple words after "function" aren't very common. More tentatively, I suspect it may have been a trick to get the shell to cough up an INBRACE before we had the test I've just patched below. So I suspect we can just move the "incmdpos = 1" until after we've found something that is either not a STRING or a possibly tokenized "{". Not included in the patch below, but I'll do it unless anyone contradicts. Does not cause any tests to fail. pws diff --git a/Src/parse.c b/Src/parse.c index 1a74164..c2dcd2b 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1602,7 +1602,8 @@ par_funcdef(int *cmplx) incmdpos = 1; while (tok == STRING) { - if (*tokstr == Inbrace && !tokstr[1]) { + if ((*tokstr == Inbrace || *tokstr == '{') && + !tokstr[1]) { tok = INBRACE; break; }