From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5510 invoked by alias); 3 Oct 2014 12:27:22 -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: 33343 Received: (qmail 11182 invoked from network); 3 Oct 2014 12:27:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f776d000003e54-87-542e9617341d Date: Fri, 03 Oct 2014 13:27:02 +0100 From: Peter Stephenson To: zsh workers Subject: Re: More incmdpos stuff Re: Crash Re: Trial for 5.0.7 Message-id: <20141003132702.044f9475@pwslap01u.europe.root.pri> In-reply-to: References: 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+NgFuplluLIzCtJLcpLzFFi42I5/e/4FV3xaXohBu0LdS0ONj9kcmD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxq9F95gKDkhXzNl0lKmB8ZJIFyMnh4SAicTpndNZIWwxiQv3 1rN1MXJxCAksZZT4fekLK4SznEli27Vt7CBVLAKqEnO2LGcGsdkEDCWmbprNCGKLAMWbv/9j AbGFBewkVt1ZBhbnFbCX2LFoL1icUyBY4v3XOUwgtpBAgMSChSfA4vwC+hJX/35igrjCXmLm lTNQvYISPybfA6thFtCS2LytiRXClpfYvOYt8wRGgVlIymYhKZuFpGwBI/MqRtHU0uSC4qT0 XCO94sTc4tK8dL3k/NxNjJAg/LqDcekxq0OMAhyMSjy8H27ohgixJpYVV+YeYpTgYFYS4ZVu 0gsR4k1JrKxKLcqPLyrNSS0+xMjEwSnVwGjUdv+SS6hex8d1Age+6nxYvKBMuWXVKbvLTuqv BHMOlnfYhT74uKv78W2xu/ndWT94fPWn8sULmi303NASEVCocdjUIk3gw9V7n2+ZP6073L38 1r+y2iTrtx3l9kfjrH44LVCc9ab2RbOLSd8NCZ/gkyxPdCsfhG2cV9ljPUOmTE2hYIOMsRJL cUaioRZzUXEiABeMuqggAgAA On Fri, 03 Oct 2014 13:47:25 +0200 Mikael Magnusson wrote: > % () ( echo hi; echo $@ ) ls > hi > ls --color=auto -T 0 -A -v --quoting-style=shell I think the right answer is along the lines of "WHY THE **@*@*@ WOULD ANYBODY USE SYNTAX LIKE THAT SHELL SYNTAX IS UNREADABLE ENOUGH AS IT IS WITHOUT (FROTH, GIBBER, ...)", but instead here's a minimal change until I get around to investigating why I thought I needed to leave incmdpos = 1 for non-anymous functions. diff --git a/Src/parse.c b/Src/parse.c index 6cba050..860bb4b 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -729,7 +729,7 @@ par_pline(int *complex) p = ecadd(0); - if (!par_cmd(complex)) { + if (!par_cmd(complex, 0)) { ecused--; return 0; } @@ -780,11 +780,15 @@ par_pline(int *complex) /* * cmd : { redir } ( for | case | if | while | repeat | * subsh | funcdef | time | dinbrack | dinpar | simple ) { redir } + * + * With zsh_construct non-zero, we're doing a zsh special in which + * the following token is not considered in command position. This + * is used for arguments of anonymous functions. */ /**/ static int -par_cmd(int *complex) +par_cmd(int *complex, int zsh_construct) { int r, nr = 0; @@ -839,12 +843,12 @@ par_cmd(int *complex) case INPAR: *complex = 1; cmdpush(CS_SUBSH); - par_subsh(complex); + par_subsh(complex, zsh_construct); cmdpop(); break; case INBRACE: cmdpush(CS_CURSH); - par_subsh(complex); + par_subsh(complex, zsh_construct); cmdpop(); break; case FUNC: @@ -1378,11 +1382,13 @@ par_repeat(int *complex) /* * subsh : INPAR list OUTPAR | * INBRACE list OUTBRACE [ "always" INBRACE list OUTBRACE ] + * + * zsh_construct is passed through to par_cmd(), q.v. */ /**/ static void -par_subsh(int *complex) +par_subsh(int *complex, int zsh_construct) { enum lextok otok = tok; int oecused = ecused, p, pp; @@ -1395,7 +1401,7 @@ par_subsh(int *complex) ecadd(WCB_END()); if (tok != ((otok == INPAR) ? OUTPAR : OUTBRACE)) YYERRORV(oecused); - incmdpos = 1; + incmdpos = !zsh_construct; zshlex(); /* Optional always block. No intervening SEPERs allowed. */ @@ -1760,10 +1766,21 @@ par_simple(int *complex, int nr) sl = ecadd(0); (void)ecadd(WCB_PIPE(WC_PIPE_END, 0)); - if (!par_cmd(&c)) { + if (!par_cmd(&c, argc == 0)) { cmdpop(); YYERROR(oecused); } + if (argc == 0) { + /* + * Anonymous function, possibly with arguments. + * N.B. for complex structures in particular + * ( ... ) we rely on lower level code doing this + * to get the immediately following word (the + * first token after the ")" has already been + * read). + */ + incmdpos = 0; + } set_sublist_code(sl, WC_SUBLIST_END, 0, ecused - 1 - sl, c); set_list_code(ll, (Z_SYNC | Z_END), c); diff --git a/Test/C04funcdef.ztst b/Test/C04funcdef.ztst index a266031..1937570 100644 --- a/Test/C04funcdef.ztst +++ b/Test/C04funcdef.ztst @@ -272,6 +272,12 @@ >ignorebraces is off >ignorebraces is still on here +# lsfoo should not be expanded as an anonymous function argument + alias lsfoo='This is not ls.' + () (echo anon func; echo "$@") lsfoo +0:Anonmous function with arguments in a form nobody sane would ever use but unfortunately we have to support anyway +>anon func +>lsfoo %clean