zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: zsh-workers@zsh.org
Subject: Re: PATCH: nested ${(P)} (formerly SHWORDSPLIT and leading spaces)
Date: Wed, 11 Nov 2015 21:55:41 +0000	[thread overview]
Message-ID: <20151111215541.4a1fb149@ntlworld.com> (raw)
In-Reply-To: <20151111174911.4384bf73@pwslap01u.europe.root.pri>

On Wed, 11 Nov 2015 17:49:11 +0000
Peter Stephenson <p.stephenson@samsung.com> 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


  parent reply	other threads:[~2015-11-11 22:01 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-06 10:54 Inconsistency with SHWORDSPLIT and leading spaces Christian Neukirchen
2015-11-06 17:00 ` Peter Stephenson
2015-11-07 17:42   ` Peter Stephenson
2015-11-07 19:43     ` Bart Schaefer
2015-11-08 18:18       ` Peter Stephenson
2015-11-08 18:55         ` Bart Schaefer
2015-11-09  6:03           ` Bart Schaefer
2015-11-11 17:49         ` PATCH: nested ${(P)} (formerly SHWORDSPLIT and leading spaces) Peter Stephenson
2015-11-11 18:13           ` Bart Schaefer
2015-11-11 21:55           ` Peter Stephenson [this message]
2015-11-12  9:46             ` Peter Stephenson
2015-11-12 14:19               ` Peter Stephenson
2015-11-13  8:17                 ` Jun T.
2015-11-13 15:07                   ` Jun T.
2015-11-14  1:33                     ` Bart Schaefer
2015-11-14  9:45                       ` Peter Stephenson
2015-11-14 18:51                         ` Bart Schaefer
     [not found] <0faa0ee3-303a-4cb5-a270-d3d1787accf1@email.android.com>
2015-11-15  5:14 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151111215541.4a1fb149@ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).