From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15740 invoked by alias); 7 Aug 2017 18:21:14 -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: 41506 Received: (qmail 21206 invoked by uid 1010); 7 Aug 2017 18:21:14 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-10.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(80.0.253.74):SA:0(-2.8/5.0):. Processed in 1.810644 secs); 07 Aug 2017 18:21:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Originating-IP: [86.21.219.59] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.1 cv=SeoKDalu c=1 sm=1 tr=0 a=utowdAHh8RITBM/6U1BPxA==:117 a=utowdAHh8RITBM/6U1BPxA==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=kj9zAlcOel0A:10 a=x7bEGLp0ZPQA:10 a=hD80L64hAAAA:8 a=7roM2qpFNizaeLnkHpoA:9 a=CjuIK1q_8ugA:10 Date: Mon, 7 Aug 2017 19:21:03 +0100 From: Peter Stephenson To: "zsh-workers@zsh.org" Subject: Re: parsing empty alternatives: case foo|) :;; Message-ID: <20170807192103.77258330@ntlworld.com> In-Reply-To: <20170807155856.7882f89f@pwslap01u.europe.root.pri> References: <20170807135559.odtceysgqn5qeqql@tarpaulin.shahaf.local2> <20170807152649.6a5e7d70@pwslap01u.europe.root.pri> <20170807155856.7882f89f@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1502130065; bh=YcHm1I6xq3w929YLVJps1E5UDUD69T0+S5qE+0g0rDY=; h=Date:From:To:Subject:In-Reply-To:References; b=uVPAVsw4bsiTeYm1TdSQEI1ajgbeDaYVTU1fWdjEcLBQgSpZv/VlcPAdzHdIKpY/f HCcUihLEQQUpALXkGyHXWhM62IdMAEYrHh47z+bkmy2TjcwfCKmJRy8jJPf23fAYJg UEkClvs7Cegx7bD3QMGJoG3AfmvgCrEGUJEIQuqlJrmwK8mkdZRzYST5AUEct960aH f1HZJaUmHmIkQKFdf2JyMoqNhQe9bGXtWtY0WbTg90V2jkQz8CwYjseGvvrPYLFMbj 04pZ59SIvoY4mu+6t0qaORBPE2C7wE3Shu6WVZ6FMlcJLWj/t057AXLvY+w5i8fxbP 3bx/GtX3MkU5w== On Mon, 07 Aug 2017 15:58:56 +0100 Peter Stephenson wrote: > I think this might be some fix-up code that got added for the old case > (nothing to do with pipes in that case). It's complicated because of the two cases, but I'm not sure this ever worked. It's straightforward to fix, but note I can't fix "foo||bar)" without more work because || is a different token. I think we can probably avoid parsing it that way here if we want to go down that route. I deliberately haven't tried to squeeze this into 5.4. pws diff --git a/Src/parse.c b/Src/parse.c index ba9cd61..d99826d 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1194,6 +1194,7 @@ par_case(int *cmplx) for (;;) { char *str; + int skip_zshlex; while (tok == SEPER) zshlex(); @@ -1201,11 +1202,17 @@ par_case(int *cmplx) break; if (tok == INPAR) zshlex(); - if (tok != STRING) - YYERRORV(oecused); - if (!strcmp(tokstr, "esac")) - break; - str = dupstring(tokstr); + if (tok == BAR) { + str = dupstring(""); + skip_zshlex = 1; + } else { + if (tok != STRING) + YYERRORV(oecused); + if (!strcmp(tokstr, "esac")) + break; + str = dupstring(tokstr); + skip_zshlex = 0; + } type = WC_CASE_OR; pp = ecadd(0); palts = ecadd(0); @@ -1245,8 +1252,9 @@ par_case(int *cmplx) */ incasepat = 0; incmdpos = 1; - for (;;) { + if (!skip_zshlex) zshlex(); + for (;;) { if (tok == OUTPAR) { ecstr(str); ecadd(ecnpats++); @@ -1302,9 +1310,24 @@ par_case(int *cmplx) } zshlex(); - if (tok != STRING) + switch (tok) { + case STRING: + /* Normal case */ + str = dupstring(tokstr); + zshlex(); + break; + + case OUTPAR: + case BAR: + /* Empty string */ + str = dupstring(""); + break; + + default: + /* Oops. */ YYERRORV(oecused); - str = dupstring(tokstr); + break; + } } par_save_list(cmplx); if (tok == SEMIAMP) diff --git a/Test/A01grammar.ztst b/Test/A01grammar.ztst index 9625a15..db62875 100644 --- a/Test/A01grammar.ztst +++ b/Test/A01grammar.ztst @@ -820,6 +820,26 @@ 0:case keeps exit status of last command executed in compound-list >37 + case '' in + burble) print No. + ;; + spurble|) print Yes! + ;; + |burble) print Not quite. + ;; + esac + case '' in + burble) print No. + ;; + |burble) print Wow! + ;; + spurble|) print Sorry. + ;; + esac +0: case with no opening parentheses and empty string +>Yes! +>Wow! + x=1 x=2 | echo $x echo $x