From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2716 invoked by alias); 11 Nov 2015 22:01:21 -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: 37094 Received: (qmail 11142 invoked from network); 11 Nov 2015 22:01:19 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [86.6.158.222] X-Spam: 0 X-Authority: v=2.1 cv=AJvf2gUA c=1 sm=1 tr=0 a=2SBOh4l1h08DI0L+aujZyQ==:117 a=2SBOh4l1h08DI0L+aujZyQ==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=hD80L64hAAAA:8 a=I4bdYmmXYvTJnokJ1bgA:9 a=CjuIK1q_8ugA:10 Date: Wed, 11 Nov 2015 21:55:41 +0000 From: Peter Stephenson To: Peter Stephenson Cc: zsh-workers@zsh.org Subject: Re: PATCH: nested ${(P)} (formerly SHWORDSPLIT and leading spaces) Message-ID: <20151111215541.4a1fb149@ntlworld.com> In-Reply-To: <20151111174911.4384bf73@pwslap01u.europe.root.pri> References: <87a8qr75za.fsf@gmail.com> <20151106170007.5196bd5e@pwslap01u.europe.root.pri> <20151107174255.74054b28@ntlworld.com> <151107114314.ZM24285@torch.brasslantern.com> <20151108181833.574cf0d6@ntlworld.com> <20151111174911.4384bf73@pwslap01u.europe.root.pri> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 11 Nov 2015 17:49:11 +0000 Peter Stephenson wrote: > tests. With a little more tweaking, nested references work naturally, if "naturally" is the word. See final test. pws diff --git a/Src/subst.c b/Src/subst.c index f3a4ad4..c1369b5 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2315,7 +2315,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * substitution. */ if (isarr) { - if (aval[1]) { + if (aval[0] && aval[1]) { zerr("parameter name reference used with array"); return NULL; } @@ -2324,7 +2324,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, } s = dyncat(val, s); /* Now behave po-faced as if it was always like that... */ - subexp = aspar = 0; + subexp = 0; } v = (Value) NULL; } else if (aspar) { @@ -2360,7 +2360,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags, * far has just yielded us a parameter name to be processed * with (P). */ - else if (!subexp || aspar) { + if (!subexp || aspar) { char *ov = val; /* diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index 694b613..6f325d2 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1798,3 +1798,52 @@ >1: x bar y >1: x bar bar y >1: x bar y + + testfn() { + local scalar=obfuscation + local -a array=(alpha bravo charlie delta echo foxtrot) + local -A assoc=(one eins two zwei three drei four vier) + local name subscript + for name subscript in scalar 3 array 5 assoc three; do + print ${${(P)name}[$subscript]} + done + } + testfn +0:${(P)...} with normal subscripting +>f +>echo +>drei + + testfn() { + local s1=foo s2=bar + local -a val=(s1) + print ${${(P)val}[1,3]} + val=(s1 s2) + print ${${(P)val}[1,3]} + } + testfn +1:${(P)...} with array as name +>foo +?testfn:5: parameter name reference used with array + + testfn() { + local -A assoc=(one buckle two show three knock four door) + local name='assoc[two]' + print ${${(P)name}[2,3]} + } + testfn +0:${(P)...} with internal subscripting +>ho + + testfn() { + local one=two + local two=three + local three=four + local -a four=(all these worlds belong to foo) + print ${${(P)${(P)${(P)one}}}} + print ${${(P)${(P)${(P)one}}}[3]} + } + testfn +0:nested parameter name references +>all these worlds belong to foo +>worlds