From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21428 invoked from network); 16 Dec 1998 18:06:34 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 16 Dec 1998 18:06:34 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id MAA15737; Wed, 16 Dec 1998 12:58:02 -0500 (EST) Resent-Date: Wed, 16 Dec 1998 12:58:02 -0500 (EST) From: "Bart Schaefer" Message-Id: <981216095309.ZM14130@candle.brasslantern.com> Date: Wed, 16 Dec 1998 09:53:09 -0800 In-Reply-To: <199812161431.PAA05365@beta.informatik.hu-berlin.de> Comments: In reply to Sven Wischnowsky "Problem with associative arrays" (Dec 16, 3:31pm) References: <199812161431.PAA05365@beta.informatik.hu-berlin.de> X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: PATCH: 3.1.5-pws-3: (subscripts) Re: Problem with associative arrays MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"oKWcR.0.qr3.fI_Ts"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4826 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu On Dec 16, 3:31pm, Sven Wischnowsky wrote: } Subject: Problem with associative arrays } } And this time it's for real: } } % typeset -A a } % a[x*]=foo } zsh: bad math expression: unbalanced stack } % echo $a[x*] } foo } % } } The problem is that isident() uses mathevalarg() to skip (!) over the } contents of a subscript (unless the subscript contains flags). isident() seems to be rather inconsistent about strict checking of the text inside the [ ]. Below is the most obvious fix (#ifdef'd for now). This has the side-effect of making associative array syntax more like ksh, in that you can put quoted strings inside the subscript: zsh% typeset -A foo zsh% foo['a b c']=cba zsh% print -l ${(kv)foo} a b c cba However, this fails (because of the "balanced brackets" test): zsh% foo['a ] c']=cba zsh: not an identifier: foo[a ] c] So a better test might be just strchr(ss, ']') and let other code report subscripting errors after it knows what kind of array it's accessing. I also don't know how widely available strcspn() is; this might break the build on some older platforms. Also, this is a bit strange: zsh% echo $foo['a b c'] zsh% echo ${foo[a b c]} <-- note, must omit the quotes on 'a b c' cba Probably the subscript needs to be untokenized somewhere. Index: Src/params.c =================================================================== --- params.c 1998/12/15 06:08:15 1.16 +++ params.c 1998/12/16 17:19:05 @@ -633,6 +633,7 @@ if (!iident(*ss)) break; +#if 0 /* If this exhaust `s' or the next two characters * * are [(, then it is a valid identifier. */ if (!*ss || (*ss == '[' && ss[1] == '(')) @@ -642,6 +643,7 @@ * definitely not a valid identifier. */ if (*ss != '[') return 0; + noeval = 1; (void)mathevalarg(++ss, &ss); if (*ss == ',') @@ -650,6 +652,19 @@ if (*ss != ']' || ss[1]) return 0; return 1; +#else + /* If the next character is not [, then it is * + * definitely not a valid identifier. */ + if (!*ss) + return 1; + if (*ss != '[') + return 0; + + /* Require balanced [ ] pairs */ + for (s = ss; *(s += strcspn(++ss, "[]")) && s > ss; ss = s) + ; + return (*ss == ']' && !s[1]); +#endif } static char **garr; -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com