From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23051 invoked from network); 18 Apr 2001 17:28:27 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 18 Apr 2001 17:28:27 -0000 Received: (qmail 28396 invoked by alias); 18 Apr 2001 17:28:18 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 14014 Received: (qmail 28379 invoked from network); 18 Apr 2001 17:28:17 -0000 From: "Bart Schaefer" Message-Id: <1010418172622.ZM30038@candle.brasslantern.com> Date: Wed, 18 Apr 2001 17:26:22 +0000 In-Reply-To: Comments: In reply to Andrej Borsenkow "Re: Patterns quoting in subscript (was: Re: PATCH: Assorted parameter stuff)" (Apr 18, 12:34pm) References: In-Reply-To: Comments: In reply to Andrej Borsenkow "Re: Patterns quoting in subscript (was: Re: PATCH: Assorted parameter stuff)" (Apr 18, 12:45pm) X-Mailer: Z-Mail (5.0.0 30July97) To: 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 18, 12:34pm, Andrej Borsenkow wrote: } Subject: Re: Patterns quoting in subscript (was: Re: PATCH: Assorted param } } On Wed, 18 Apr 2001, Bart Schaefer wrote: } > } > 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 \? --> \?.) } } O.K., any chance to explain the above in Zsh doc? Yes, I just don't want to spend time writing doc if this change is going to cause some other problem and therefore not be included. } Just to make sure that I understand: } } - "as if in double quotes" means, that I cannot use "..." or '...' quoting } inside of subscript, only back-slash is possible? It's exactly like quoting for $[...] math expressions, except that (as of 14008) spaces are not permitted. Which for a traditional numeric subscript makes sense, as it *is* a math expression. } - the rule for ``\\'' and ``\$'' still aplies? But ``\"'' is parsed as } *two* characters? Yes. On Apr 18, 12:45pm, Andrej Borsenkow wrote: } } O.K., but why when I add additional backslashes I still get a match?: } } bor@itsrm2:~%> print -r $foo[(r)\\\\\\\\\?] } \? } } ?? It seems to happen for any number of extra backslashes. Well, sigh, patcompile() also apparently does a level of backslash-removal, so i've forgotten one step in the explanation above. It's something like: parse tokenize pattern match \\ \\ \? --> \\ \? --> \? --> \? \\ \\ \\ \\ \? --> \\ \\ \? --> \\ ? --> \? Then you also have to remember that `?' as a metacharacter matches any character, so one extra backslash will result in a pattern that matches by wildcard rather than by a literal question-mark. So if you want to match 4 backslashes, you need 16 backslashes; but if you want to match 4 backslashes followed by a literal question mark, you need a whopping 34 backslashes, because you have to double all 16 of those backslashes and then add two more to quote the `?' itself. Clearly this is silly; it results because of the extra call to parsestr() that happens when the `needtok' loop in getarg() detects an ispecial() (the `?' in this example). I'll see if that can't be made to behave a bit more intelligibly. -- 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