From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16842 invoked by alias); 23 Jun 2015 16:57:32 -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: 35575 Received: (qmail 11216 invoked from network); 23 Jun 2015 16:57:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f5-f794b6d000001495-45-55898d9ae278 Date: Tue, 23 Jun 2015 17:47:19 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Re: Typeset with array Message-id: <20150623174719.43eaa1e2@pwslap01u.europe.root.pri> In-reply-to: <20150621213842.621886e0@ntlworld.com> References: <5578996E.3080700@thequod.de> <150610191427.ZM30841@torch.brasslantern.com> <5579C247.1060800@thequod.de> <150611183639.ZM32247@torch.brasslantern.com> <20150612094237.338f79d5@pwslap01u.europe.root.pri> <20150619123930.2688d9e3@pwslap01u.europe.root.pri> <20150621210512.113577a6@ntlworld.com> <20150621213842.621886e0@ntlworld.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+NgFjrELMWRmVeSWpSXmKPExsVy+t/xK7qzeztDDdrmM1ocbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujMNX/7MWrBSr+PLtKXMD42P+LkYODgkBE4kD+6q7GDmBTDGJ C/fWs3UxcnEICSxllOj+1gHlzGCSaH24ixnC2cYo8Wd3JxNIC4uAqkTXn0OsIDabgKHE1E2z GUGmighoS7R/FAMJCwvIS+w+uZ8ZJMwrYC8x+UI2SJhTwFjiQ+9hdoiRj5kkXh+dCjaSX0Bf 4urfT0wQF9lLzLxyhhHE5hUQlPgx+R4LiM0soCWxeVsTK4QtL7F5zVtmEFtIQF3ixt3d7BMY hWYhaZmFpGUWkpYFjMyrGEVTS5MLipPSc430ihNzi0vz0vWS83M3MUJC9usOxqXHrA4xCnAw KvHwFkzuCBViTSwrrsw9xCjBwawkwmuR2hkqxJuSWFmVWpQfX1Sak1p8iFGag0VJnHfmrvch QgLpiSWp2ampBalFMFkmDk6pBkbVPxel/Za3q1WsTWHvzJqeb8NgyjUzoPmRyHSvY/F/2U77 FAjvKzqYbTf5cuTbsvt/RDasYnHf9KhAKP5FqurihL1sl15WCnVNidezkVec/9fF6eHyb99e fBeI3yjneU2snEF9p9CxFb+b9SNkK12fX70lcL9kxQrG2IWqkS/3PNufdy/Fw1WJpTgj0VCL uag4EQBFTvqGVQIAAA== Some more tests and one quite subtle fix. I think this is now basically working. Any more comments, or should I roll this out and see what happens? pws diff --git a/Src/parse.c b/Src/parse.c index 5357851..477f8a0 100644 --- a/Src/parse.c +++ b/Src/parse.c @@ -1898,10 +1898,18 @@ par_simple(int *cmplx, int nr) parr = ecadd(0); ecstr(tokstr); cmdpush(CS_ARRAY); + /* + * Careful here: this must be the typeset case, + * but we need to tell the lexer not to look + * for assignments until we've finished the + * present one. + */ + intypeset = 0; zshlex(); n = par_nl_wordlist(); ecbuf[parr] = WCB_ASSIGN(WC_ASSIGN_ARRAY, WC_ASSIGN_NEW, n); cmdpop(); + intypeset = 1; if (tok != OUTPAR) YYERROR(oecused); zshlex(); diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst index 75c475c..e5c4310 100644 --- a/Test/B02typeset.ztst +++ b/Test/B02typeset.ztst @@ -22,6 +22,8 @@ %prep + mkdir typeset.tmp && cd typeset.tmp + setopt noglob scalar=scalar @@ -517,6 +519,7 @@ print -l $one $two $three $four $five } fn + print -l $one $two $three $four $five 0:typeset reserved word interface: basic > eins >zwei @@ -525,3 +528,82 @@ > vier >cinq >cinque +>hidden +>hidden +>hidden +>hidden +>hidden + + ( + setopt glob + mkdir -p arrayglob + touch arrayglob/{one,two,three,four,five,six,seven} + fn() { + typeset array=(arrayglob/[tf]*) + print -l ${array:t} + # + typeset {first,second,third}=the_same_value array=( + extends + over + multiple + lines + ) + print -l $first $second $third "$array" + # + integer i=$(echo 1 + 2 + 3 + 4) + print $i + # + # only noted by accident this was broken.. + # we need to turn off special recognition + # of assignments within assignments... + typeset careful=( i=1 j=2 k=3 ) + print -l $careful + } + fn + ) +0:typeset reserved word, more complicated cases +>five +>four +>three +>two +>the_same_value +>the_same_value +>the_same_value +>extends over multiple lines +>10 +>i=1 +>j=2 +>k=3 + + ( + # reserved word is recognised at parsing. + # yes, this is documented. + # anyway, that means we need to + # re-eval the function... + fn=' + fn() { + typeset foo=`echo one word=two` + print $foo + print $word + } + ' + print reserved + eval $fn; fn + print builtin + disable -r typeset + eval $fn; fn + enable -r typeset + disable typeset + print reserved + eval $fn;fn + ) +0:reserved word and builtin interfaces +>reserved +>one word=two +> +>builtin +>one +>two +>reserved +>one word=two +>