From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9495 invoked by alias); 14 May 2015 23:46:00 -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: 35142 Received: (qmail 6970 invoked from network); 14 May 2015 23:45:59 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.2 Message-ID: <555533AE.4000705@case.edu> Date: Thu, 14 May 2015 19:45:50 -0400 From: Chet Ramey Reply-To: chet.ramey@case.edu Organization: ITS, Case Western Reserve University User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Peter Stephenson , Martijn Dekker , zsh-workers@zsh.org CC: chet.ramey@case.edu Subject: Re: 'case' pattern matching bug with bracket expressions References: <55549FB2.80705@inlv.org> <20150514154238.0e547ff0@pwslap01u.europe.root.pri> In-Reply-To: <20150514154238.0e547ff0@pwslap01u.europe.root.pri> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Junkmail-Whitelist: YES (by domain whitelist at mpv1.tis.cwru.edu) On 5/14/15 10:42 AM, Peter Stephenson wrote: > The handling of ']' at the start is mandated, if I've > followed all the logic corretly --- POSIX 2007 Shell and Utilities > 2.13.1 says: > > [ > If an open bracket introduces a bracket expression as in XBD RE > Bracket Expression, except that the character ( > '!' ) shall replace the character ( '^' ) in its role > in a non-matching list in the regular expression notation, it shall > introduce a pattern bracket expression. A bracket expression > starting with an unquoted character produces > unspecified results. Otherwise, '[' shall match the character > itself. > > The languaqge is a little turgid, but I think it's saying "unless > you have ^ or [ just go with the RE rules in [section 9.3.5]". I think it means that improperly-formed pattern bracket expressions have to be matched by a literal `[' followed by whatever the following characters mean. > I haven't read through the "case" doc so there may be some killer reason > why that " | " has to be a case separator and not part of a > square-bracketed expression. But that would seem to imply some form of > hierarchical parsing in which those characters couldn't occur within a > pattern. It's the grammar. If you want `|' to be in a pattern you have to quote it. Otherwise it's a metacharacter and a token delimiter (section 2.2). The basic idea is that you tokenize case patterns as words and analyze them as patterns after doing so. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/