From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17494 invoked by alias); 4 Mar 2015 15:28:42 -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: 34641 Received: (qmail 18701 invoked from network); 4 Mar 2015 15:28:40 -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: cbfec7f4-b7f126d000001e9a-fa-54f721b83f62 Date: Wed, 04 Mar 2015 15:18:30 +0000 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: grammar triviality with '&&' Message-id: <20150304151830.5e20d732@pwslap01u.europe.root.pri> In-reply-to: <20150304144756.GA27231@ypig.lip.ens-lyon.fr> References: <54F33934.2070607@eastlink.ca> <13666281425228233@web7o.yandex.ru> <54F345D3.9010204@eastlink.ca> <20150302022754.GA7449@xvii.vinc17.org> <20150302104619.GC6869@xvii.vinc17.org> <20150302110610.2e2c7e86@pwslap01u.europe.root.pri> <20150304144756.GA27231@ypig.lip.ens-lyon.fr> 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+NgFlrGLMWRmVeSWpSXmKPExsVy+t/xK7o7FL+HGFzYyG1xsPkhkwOjx6qD H5gCGKO4bFJSczLLUov07RK4Mt7s3sNWcEi24vPEa6wNjN9Fuxg5OSQETCT6/u9nhrDFJC7c W8/WxcjFISSwlFHi9Y/tTBDOEiaJi39WMUM42xgllsz7xALSwiKgKjF73yImEJtNwFBi6qbZ jF2MHBwiAtoS7R/FQMLCApoSyz58ZgOxeQXsJa6f3MkOYnMKWEk8fL2EFWLmK2aJDwc3gc3h F9CXuPr3ExPESfYSM6+cYYRoFpT4Mfke2F5mAS2JzduaWCFseYnNa96CvSAkoC5x4+5u9gmM QrOQtMxC0jILScsCRuZVjKKppckFxUnpuYZ6xYm5xaV56XrJ+bmbGCFh+2UH4+JjVocYBTgY lXh4C5K+hQixJpYVV+YeYpTgYFYS4X3O9j1EiDclsbIqtSg/vqg0J7X4ECMTB6dUA6OvQOLD uos9enWP1z17aOCe2aTHvuzQK65bs9a0MfOzpve3ueW8yj6bbym6ePv5wvOT9Fd2PkmStTSM 0a/51DLvcmh0clCzU8LXaaeVP97nfvzke+vGmx6s1j/OPsiuOnjzdUDu5LRlkXICYjGtrrLO h5wUeO+feiuju/OJdwfzQrsj9af+NiuxFGckGmoxFxUnAgD3FxH/OQIAAA== On Wed, 4 Mar 2015 15:47:56 +0100 Vincent Lefevre wrote: > I've found a bug: > > % alias '&&=(){ return $? } && ' > % && echo OK > zsh: parse error near `&&' (Moved to zsh-workers) I was keeping very quiet about this, but it looks like it's not as hairy as I thought it might be and the new code is actually slightly cleaner... Now waiting for obscure failures elsewhere... pws diff --git a/Src/lex.c b/Src/lex.c index 307b6e9..a076614 100644 --- a/Src/lex.c +++ b/Src/lex.c @@ -1728,13 +1728,48 @@ gotword(void) } } +/* Check if current lex text matches an alias: 1 if so, else 0 */ + +static int +checkalias(void) +{ + Alias an; + + if (!noaliases && isset(ALIASESOPT) && + (!isset(POSIXALIASES) || + !reswdtab->getnode(reswdtab, zshlextext))) { + char *suf; + + an = (Alias) aliastab->getnode(aliastab, zshlextext); + if (an && !an->inuse && + ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) { + inpush(an->text, INP_ALIAS, an); + if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL)) + aliasspaceflag = 1; + lexstop = 0; + return 1; + } + if ((suf = strrchr(zshlextext, '.')) && suf[1] && + suf > zshlextext && suf[-1] != Meta && + (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && + !an->inuse && incmdpos) { + inpush(dupstring(zshlextext), INP_ALIAS, NULL); + inpush(" ", INP_ALIAS, NULL); + inpush(an->text, INP_ALIAS, an); + lexstop = 0; + return 1; + } + } + + return 0; +} + /* expand aliases and reserved words */ /**/ int exalias(void) { - Alias an; Reswd rw; hwend(); @@ -1746,7 +1781,7 @@ exalias(void) if (!tokstr) { zshlextext = tokstrings[tok]; - return 0; + return checkalias(); } else { VARARR(char, copy, (strlen(tokstr) + 1)); @@ -1772,34 +1807,10 @@ exalias(void) if (tok == STRING) { /* Check for an alias */ - if (!noaliases && isset(ALIASESOPT) && - (!isset(POSIXALIASES) || - !reswdtab->getnode(reswdtab, zshlextext))) { - char *suf; - - an = (Alias) aliastab->getnode(aliastab, zshlextext); - if (an && !an->inuse && - ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) { - inpush(an->text, INP_ALIAS, an); - if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL)) - aliasspaceflag = 1; - lexstop = 0; - if (zshlextext == copy) - zshlextext = tokstr; - return 1; - } - if ((suf = strrchr(zshlextext, '.')) && suf[1] && - suf > zshlextext && suf[-1] != Meta && - (an = (Alias)sufaliastab->getnode(sufaliastab, suf+1)) && - !an->inuse && incmdpos) { - inpush(dupstring(zshlextext), INP_ALIAS, NULL); - inpush(" ", INP_ALIAS, NULL); - inpush(an->text, INP_ALIAS, an); - lexstop = 0; - if (zshlextext == copy) - zshlextext = tokstr; - return 1; - } + if (checkalias()) { + if (zshlextext == copy) + zshlextext = tokstr; + return 1; } /* Then check for a reserved word */ diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst index 7121c50..36dfa24 100644 --- a/Test/A02alias.ztst +++ b/Test/A02alias.ztst @@ -42,3 +42,18 @@ cat <(echo foo | cat) 0:Alias expansion works at the end of parsed strings >foo + + alias '&&=(){ return $?; } && ' + alias not_the_print_command=print + eval 'print This is output + && print And so is this + && { print And this too; false; } + && print But not this + && print Nor this + true + && not_the_print_command And aliases are expanded' +0:We can now alias special tokens. Woo hoo. +>This is output +>And so is this +>And this too +>And aliases are expanded