From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17979 invoked by alias); 11 Nov 2014 17:59:25 -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: 33679 Received: (qmail 18034 invoked from network); 11 Nov 2014 17:59:22 -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-b7f6c6d00000120b-11-54624e7629cb Date: Tue, 11 Nov 2014 17:59:17 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: (#m) and "case" alternation Message-id: <20141111175917.3b0fd81e@pwslap01u.europe.root.pri> In-reply-to: <20141111174326.GD4343@chaz.gmail.com> References: <20141111125423.GA4343@chaz.gmail.com> <141111074407.ZM30753@torch.brasslantern.com> <20141111174326.GD4343@chaz.gmail.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+NgFuphluLIzCtJLcpLzFFi42I5/e/4Nd0yv6QQg4sbJCwONj9kcmD0WHXw A1MAYxSXTUpqTmZZapG+XQJXxpurEQWbeSsap/s1MH7j6mLk5JAQMJHo3jmfDcIWk7hwbz2Q zcUhJLCUUWL65ROMEM5yJol/T1pYQKpYBFQlNj+ZyAhiswkYSkzdNBvMFhHQkthx8iQTiC0s oCGx9/tksHpeAXuJ7qmzwDZwChhL3Ls2hR1iaDejRPv/rawgCX4BfYmrfz8xQZxhLzHzyhlG iGZBiR+T74ENYgZasHlbEyuELS+xec1b5gmMArOQlM1CUjYLSdkCRuZVjKKppckFxUnpuYZ6 xYm5xaV56XrJ+bmbGCEh+GUH4+JjVocYBTgYlXh4DcISQ4RYE8uKK3MPMUpwMCuJ8EpKJIUI 8aYkVlalFuXHF5XmpBYfYmTi4JRqYFR88k3y4tonBgtu5GWYLLzilbT8U69Q1pE/T7tS391Y pjy5Pnglo4vAnlO3jpcY78xv3nJfg3HatOXzXJMfXlbXqYnpTBR4rfXnrwovr2K+HYf1jfOv rL4zn1h70qZdv/vXlfezm3Z6cU/mSgyO2DL91PubW5VnrUssSeSSKD2yZ41O8VKtD3eUWIoz Eg21mIuKEwEJD+QVHwIAAA== On Tue, 11 Nov 2014 17:43:26 +0000 Stephane Chazelas wrote: > OK, but in: > > case abc in (#m)a* | b*) echo $MATCH; esac > > my understanding was that we've got two patterns as that's the > "|" case alternation operator, not the "|" glob operator (with > which you can't have spaces on either side).. zsh is a bit different from other shells and the difference is a little bit fudged --- so you and Bart are kind of both right. We parse case patterns separately, hence the whitespace handling, but after parsing we weld the alternatives back together as one big group with an "or". See par_case() in parse.c, though that's probably not going to tell you much further of interest. It probably wouldn't hurt to document this. Suggest improvements if the following isn't clear enough... diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 4d04c24..63d90df 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -239,7 +239,11 @@ item(tt(case) var(word) tt(in) [ [tt(LPAR())] var(pattern) [ tt(|) var(pattern) Execute the var(list) associated with the first var(pattern) that matches var(word), if any. The form of the patterns is the same as that used for filename generation. See -noderef(Filename Generation). +noderef(Filename Generation). Note further that the whole +pattern with alternatives is treated by the shell as equivalent +to a group of patterns within parentheses, even though in +the tt(case) syntax whitespace may appear about the parentheses and the +vertical bar. If the var(list) that is executed is terminated with tt(;&) rather than tt(;;), the following list is also executed. The rule for pws