From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19091 invoked from network); 18 Apr 2001 08:15:14 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 18 Apr 2001 08:15:14 -0000 Received: (qmail 16784 invoked by alias); 18 Apr 2001 08:15:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 14007 Received: (qmail 16739 invoked from network); 18 Apr 2001 08:15:09 -0000 From: "Bart Schaefer" Message-Id: <1010418073853.ZM28977@candle.brasslantern.com> Date: Wed, 18 Apr 2001 07:38:53 +0000 In-Reply-To: Comments: In reply to Andrej Borsenkow "Patterns quoting in subscript (was: Re: PATCH: Assorted parameter stuff)" (Apr 17, 10:30pm) References: X-Mailer: Z-Mail (5.0.0 30July97) To: Andrej Borsenkow , Subject: Re: Patterns quoting in subscript (was: Re: PATCH: Assorted parameter stuff) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Apr 17, 10:30pm, Andrej Borsenkow wrote: } } At least one thing has changed (but I consider behaviour broken in } anyway): } } bor@itsrm2:~%> foo=(a '?' '\?') } bor@itsrm2:~%> print -r $foo[(r)?] } a } bor@itsrm2:~%> print -r $foo[(r)\?] } ? } bor@itsrm2:~%> print -r $foo[(r)\\?] } ? } bor@itsrm2:~%> print -r $foo[(r)\\\?] } ? You just didn't try enough backslashes yet: schaefer[507] print -r $foo[(r)\\\\\?] \? The reason you need five is that [...] is parsed as if double quoted, except that \] is magic instead of \". Then the pattern inside it is tokenized by (r) before being passed to patcompile(). So it goes like: parse tokenize pattern \\ \\ \? --> \\ \? --> \? (In double quotes, \\ --> \ but \? --> \?.) } Both are broken. Without patch you have at least some (albeit completely } unclear) possibility to quote patterns in subscript - with patch even this } one is gone. Not true. Without the patch you can't explain the rationale for quoting, but with the patch it's predictable. Similarly, without the patch this fails utterly: schaefer[508] x='\?' schaefer[509] print -r $foo[(r)${(q)x}] \? But with the patch it's possible to explain why it works: parse tokenize pattern ${(q)x} --> \\ \? --> \? } Suggestion is something like } } $foo[()pattern] - is parsed just like a "normal" globbing pattern, taking } in account any quoting. I.e. in $foo[(r)\*$bar] neither ``*'' nor contents } of $bar is taken as pattern. Unfortunately, this is a significant change in zsh semantics. I don't think we have the opportunity to do this any longer. It may be too bad that this wasn't originally the spec, but I think we're stuck with the current interpretation of [(r)$bar]. } Special consideration is needed for double quotes. Because normally } "$foo[(r)\?]" is parsed as *two* characters - ``\'' and ``?'', to allow } quoting inside double-quotes extension of quoting rules is needed. I.e. } ``\'' should be allowed to quote pattern metacharacters inside of } subscript. You'll note that with my patch the quoting inside and outside of double quotes works exactly the same (except of course for the double-quote character itself). That is, schaefer[513] print -r "$foo[(r)\\\\\?]" \? Five backslashes, just as before; same result. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net