Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: [key]=value syntax, work in progress
- X-seq: zsh-workers 41698
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: PATCH: [key]=value syntax, work in progress
- Date: Wed, 13 Sep 2017 20:41:08 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1505331670; bh=eyBDOEEmBGaF0tAfDOzEDfD6Dz/ngePQORwYrUVub0A=; h=Date:From:To:Subject:In-Reply-To:References; b=PfGCMPdCNhLgby/p/Ov4OntFf5QZIV9xTvf5nip90wACKbJCQm1n1/UiSla1/wRX7 KL1ta1yjcAb5zA62ZIBh8BvYqrJagfMcU3vnnvZ1KPVtSLHSOOYzaYS0hWwosMxpTw tCTGTEsi94O0IuwuFNOob7k0xwbNI+KsTJc5+/8nQcmKN+ptgsQ1aizkkjbMNt2woX z3df9LL5Qi1JCUse6DTBrqtb4kuv+DmCFgBmI3F+tiB27pEqyLrYPeXnDg5YqKSTAf FMXeGjINzKxQwZ8gj1VyJiBe8KvVwX++Ly8SmCWlR15gxvf6FdqTU7BSLJiVljYSjx No8E0DqZK3SrQ==
- In-reply-to: <30374.1505294044@thecus.kiddle.eu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20170911215115.6aa27dec@ntlworld.com> <20170912212519.3d873212@ntlworld.com> <30374.1505294044@thecus.kiddle.eu>
On Wed, 13 Sep 2017 11:14:04 +0200
Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote:
> Appending has issues - seg fault with:
> arr=( 1 2 3 )
> arr+=( [5]=val )
Thanks for the testing.
That was just a maxlen that should have been origlen.
> Bash actually appends element wise with +=. Ksh doesn't. Ksh instead would
> require an inner +=. Ksh behaviour on this seems far more logical to me.
> ksh$ arr+=( [0]+=X )
> bash$ arr+=( [0]=X )
Yes, I was thinking about the former, but it can wait. If we do that it
would make a bash compatibility "do you really, really want to set
this?" option fairly straightforward.
> A range doesn't evoke an error, (or clever multi-element assignment):
> % arr=( [1,2]=x )
> % typeset -p arr
> typeset -a arr=( x )
> Note that is the first element so it must be parsing the range rather than
> treating the , as the arithmentic , operator (and returning 2).
That's because I'm using mathevalarg(), which is designed for the range
case, becase I blindly copied it from elsewhere in params.c. The
obvious fix is to use mathevali() -- in which case it becomes an
ordinary comma operator, which is logically correct. Possibly
mathevalarg and an error on a following comma would make it more
obvious?
> What about brace expansion:
> % arr=( [{2..3}]=x )
> zsh: bad math expression: operand expected at `{2..3}'
Looks OK to me, actually. It's a single word expansion on the key, so
braces aren't useful in that context, and the single word in question
indeed doesn't make sens as arithmetic, which is what you need to get an
index. More importantly, with an associative array, that becomes an
actual string that's valid as a key, as intended.
> bash$ arr=( [{2..3}]=x )
> bash$ typeset -p arr
> declare -a arr='([0]="[2]=x" [1]="[3]=x")'
This doesn't look very useful.
> This is interesting (syntax error in bash). Could be good to reserve this
> syntax for ksh style nested assignments.
> % arr=( [1]=(x y z) )
> % typeset -p arr
> typeset -a arr=( '(x y z)' )
That's a consequence of (i) some time ago I made a parenthesis not
appearing in command position require a match so you could put spaces in
patterns and glob qualifiers without extra quotes (ii) single word
expansion, again. The contents of the parentheses aren't actually
parsed specially, it just counts them all out and counts them all back.
> Any user deserves what they get with this but note that as a fatal error, the
> shell bails out completely. Might be nice if this could be non-fatal with the
> effect that the array is not assigned.
>
> % arr=( [99999999999]=hello )
> zsh: fatal error: out of memory
This isn't really new. It's a long-standing bugbear that there are so
many places where this can fail that it's hard to fix. I've added a
test in the new allocation.
> It would be good to make typeset -p output use this new syntax by default
> for associative arrays because (without other cues like alignment) it
> can be clearer which items in the list are keys and which values. Are
> there certain keys that can't easily be quoted with the new syntax? If
> so, typeset -p could mix the two formats once that's supported.
Hmm... the path of least resistance is to quote just as we normally
would for an output word, which may be slight overkill but probably not
bad overall, and better guarantees compatibility. You need to quote a
space in the key --- it's less obvious than in the value, but probably
logical enough.
Quoting is easy to get wrong, so I've added some tests where the key and
value use arbitrary quoting that should get removed (and do).
I'm still wondering about plans of attack for the mixed syntax. I
thought about doing the recognition in prefork() when given a special
flag, removing all pattern characters immediately so that they pass
unchanged through globlist, and doing [something devilishly clever I
haven't worked out yet --- I don't want to create a new token if I can
help it, but maybe Marker will work] to mark the words to expand as
special.
I think I'll commit this and do the mixed syntax, typeset -p, and
internal += later.
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 817496b..31266a7 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -91,13 +91,36 @@ cindex(array assignment)
ifzman()
indent(tt(set -A) var(name) var(value) ...)
indent(var(name)tt(=LPAR())var(value) ...tt(RPAR()))
+indent(var(name)tt(=LPAR())tt([)var(key)tt(]=)var(value) ...tt(RPAR()))
+
+In the third form, var(key) is an expression that will be evaluated in
+arithmetic context (in its simplest form, an integer) that gives the
+index of the element to be assigned with var(value). In this form any
+elements not explicitly mentioned that come before the largest index to
+which a value is assigned will be assigned an empty string. The indices
+may be in any order. Note that this syntax is strict: tt([) and tt(]=) must
+not be quoted, while var(key) may not consist of the unquoted string
+tt(]=), but is otherwise treated as a simple string. Furthermore, all
+elements must match this form or an error is genereted; likewise, if the
+first entry does not match this form any later entry that does is taken
+as a simple value rather than a key / value pair. The enhanced forms of
+subscript expression that may be used when directly subscripting a
+variable name, described in the section Array Subscripts below, are not
+available. Both var(key) and var(value) undergo all forms of expansion
+allowed for single word substitutions (this does not include filename
+generation).
If no parameter var(name) exists, an ordinary array parameter is created.
If the parameter var(name) exists and is a scalar, it is replaced by a new
array. To append to an array without changing the existing values, use
-the syntax:
+one of the following:
ifzman()
indent(var(name)tt(+=LPAR())var(value) ...tt(RPAR()))
+indent(var(name)tt(+=LPAR())tt([)var(key)tt(]=)var(value) ...tt(RPAR()))
+
+In the second form var(key) may specify an existing index as well as an
+index off the end of the old array; any existing value is overwritten by
+var(value).
Within the parentheses on the right hand side of either form of the
assignment, newlines and semicolons are treated the same as white space,
@@ -118,12 +141,14 @@ is interpreted as alternating keys and values:
ifzman()
indent(tt(set -A) var(name) var(key) var(value) ...)
indent(var(name)tt(=LPAR())var(key) var(value) ...tt(RPAR()))
+indent(var(name)tt(=LPAR())tt([)var(key)tt(]=)var(value) ...tt(RPAR()))
Every var(key) must have a var(value) in this case. Note that this
assigns to the entire array, deleting any elements that do not appear in
the list. The append syntax may also be used with an associative array:
ifzman()
indent(var(name)tt(+=LPAR())var(key) var(value) ...tt(RPAR()))
+indent(var(name)tt(+=LPAR())tt([)var(key)tt(]=)var(value) ...tt(RPAR()))
This adds a new key/value pair if the key is not already present, and
replaces the value for the existing key if it is.
diff --git a/Src/builtin.c b/Src/builtin.c
index 0c2a62a..f5ccf52 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -450,15 +450,35 @@ execbuiltin(LinkList args, LinkList assigns, Builtin bn)
Asgment asg = (Asgment)node;
fputc(' ', xtrerr);
quotedzputs(asg->name, xtrerr);
- if (asg->is_array) {
- LinkNode arrnode;
+ if (asg->flags & ASG_ARRAY) {
fprintf(xtrerr, "=(");
if (asg->value.array) {
- for (arrnode = firstnode(asg->value.array);
- arrnode;
- incnode(arrnode)) {
- fputc(' ', xtrerr);
- quotedzputs((char *)getdata(arrnode), xtrerr);
+ if (asg->flags & ASG_KEY_VALUE) {
+ LinkNode keynode, valnode;
+ keynode = firstnode(asg->value.array);
+ for (;;) {
+ if (!keynode)
+ break;
+ valnode = nextnode(keynode);
+ if (!valnode)
+ break;
+ fputc('[', xtrerr);
+ quotedzputs((char *)getdata(keynode),
+ xtrerr);
+ fprintf(stderr, "]=");
+ quotedzputs((char *)getdata(valnode),
+ xtrerr);
+ keynode = nextnode(valnode);
+ }
+ } else {
+ LinkNode arrnode;
+ for (arrnode = firstnode(asg->value.array);
+ arrnode;
+ incnode(arrnode)) {
+ fputc(' ', xtrerr);
+ quotedzputs((char *)getdata(arrnode),
+ xtrerr);
+ }
}
}
fprintf(xtrerr, " )");
@@ -1519,7 +1539,7 @@ bin_fc(char *nam, char **argv, Options ops, int func)
asgl = a;
}
a->name = *argv;
- a->is_array = 0;
+ a->flags = 0;
a->value.scalar = s;
a->node.next = a->node.prev = NULL;
argv++;
@@ -1910,7 +1930,7 @@ getasg(char ***argvp, LinkList assigns)
return NULL;
}
asg.name = s;
- asg.is_array = 0;
+ asg.flags = 0;
/* search for `=' */
for (; *s && *s != '='; s++);
@@ -2171,7 +2191,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
* ii. we are creating a new local parameter
*/
if (usepm) {
- if (asg->is_array ?
+ if ((asg->flags & ASG_ARRAY) ?
!(PM_TYPE(pm->node.flags) & (PM_ARRAY|PM_HASHED)) :
(asg->value.scalar && (PM_TYPE(pm->node.flags &
(PM_ARRAY|PM_HASHED))))) {
@@ -2241,10 +2261,11 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
if (asg->value.scalar &&
!(pm = assignsparam(pname, ztrdup(asg->value.scalar), 0)))
return NULL;
- } else if (asg->is_array) {
+ } else if (asg->flags & ASG_ARRAY) {
+ int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
if (!(pm = assignaparam(pname, asg->value.array ?
zlinklist2array(asg->value.array) :
- mkarray(NULL), 0)))
+ mkarray(NULL), flags)))
return NULL;
}
if (errflag)
@@ -2255,7 +2276,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
return pm;
}
- if (asg->is_array ?
+ if ((asg->flags & ASG_ARRAY) ?
!(on & (PM_ARRAY|PM_HASHED)) :
(asg->value.scalar && (on & (PM_ARRAY|PM_HASHED)))) {
zerrnam(cname, "%s: inconsistent type for assignment", pname);
@@ -2287,7 +2308,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
*/
if (!ASG_VALUEP(asg) && !((pm->node.flags|on) & (PM_ARRAY|PM_HASHED))) {
asg->value.scalar = dupstring(getsparam(pname));
- asg->is_array = 0;
+ asg->flags = 0;
}
/* pname may point to pm->nam which is about to disappear */
pname = dupstring(pname);
@@ -2396,13 +2417,14 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
ztrdup(asg->value.scalar ? asg->value.scalar : ""), 0)))
return NULL;
dont_set = 1;
- asg->is_array = 0;
+ asg->flags = 0;
keeplocal = 0;
on = pm->node.flags;
} else if (PM_TYPE(on) == PM_ARRAY && ASG_ARRAYP(asg)) {
+ int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
if (!(pm = assignaparam(pname, asg->value.array ?
zlinklist2array(asg->value.array) :
- mkarray(NULL), 0)))
+ mkarray(NULL), flags)))
return NULL;
dont_set = 1;
keeplocal = 0;
@@ -2479,6 +2501,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
Param ipm = pm;
if (pm->node.flags & (PM_ARRAY|PM_HASHED)) {
char **arrayval;
+ int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
if (!ASG_ARRAYP(asg)) {
/*
* Attempt to assign a scalar value to an array.
@@ -2497,7 +2520,7 @@ typeset_single(char *cname, char *pname, Param pm, UNUSED(int func),
arrayval = zlinklist2array(asg->value.array);
else
arrayval = mkarray(NULL);
- if (!(pm=assignaparam(pname, arrayval, 0)))
+ if (!(pm=assignaparam(pname, arrayval, flags)))
return NULL;
} else {
DPUTS(ASG_ARRAYP(asg), "BUG: inconsistent array value for scalar");
@@ -2750,13 +2773,15 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
* Already tied in the fashion requested.
*/
struct tieddata *tdp = (struct tieddata*)pm->u.data;
+ int flags = (asg->flags & ASG_KEY_VALUE) ?
+ ASSPM_KEY_VALUE : 0;
/* Update join character */
tdp->joinchar = joinchar;
if (asg0.value.scalar)
assignsparam(asg0.name, ztrdup(asg0.value.scalar), 0);
else if (asg->value.array)
assignaparam(
- asg->name, zlinklist2array(asg->value.array), 0);
+ asg->name, zlinklist2array(asg->value.array),flags);
return 0;
} else {
zwarnnam(name, "can't tie already tied scalar: %s",
@@ -2778,7 +2803,7 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
* to be exported properly.
*/
asg2.name = asg->name;
- asg2.is_array = 0;
+ asg2.flags = 0;
asg2.value.array = (LinkList)0;
if (!(apm=typeset_single(name, asg->name,
(Param)paramtab->getnode(paramtab,
@@ -2816,9 +2841,10 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
if (apm->ename)
zsfree(apm->ename);
apm->ename = ztrdup(asg0.name);
- if (asg->value.array)
- assignaparam(asg->name, zlinklist2array(asg->value.array), 0);
- else if (oldval)
+ if (asg->value.array) {
+ int flags = (asg->flags & ASG_KEY_VALUE) ? ASSPM_KEY_VALUE : 0;
+ assignaparam(asg->name, zlinklist2array(asg->value.array), flags);
+ } else if (oldval)
assignsparam(asg0.name, oldval, 0);
unqueue_signals();
diff --git a/Src/exec.c b/Src/exec.c
index e2432fd..d136766 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2389,6 +2389,60 @@ addfd(int forked, int *save, struct multio **mfds, int fd1, int fd2, int rflag,
}
}
+/* Check for array assignent with entries like [key]=val.
+ *
+ * All entries or none must match this form, else error and return 0.
+ *
+ * Convert list to alternate key / val form, perform
+ * appropriate substitution, and return 1 if found.
+ *
+ * Caller to check errflag.
+ */
+
+/**/
+static int
+keyvalpairarray(LinkList vl, int htok)
+{
+ char *start, *end, *dat;
+ LinkNode ve, next;
+
+ if (vl &&
+ (ve = firstnode(vl)) &&
+ (start = (char *)getdata(ve)) &&
+ start[0] == Inbrack &&
+ (end = strchr(start+1, Outbrack)) &&
+ end[1] == Equals) {
+ for (;;) {
+ *end = '\0';
+ next = nextnode(ve);
+
+ dat = start + 1;
+ if (htok)
+ singsub(&dat);
+ untokenize(dat);
+ setdata(ve, dat);
+ dat = end + 2;
+ if (htok)
+ singsub(&dat);
+ untokenize(dat);
+ insertlinknode(vl, ve, dat);
+ ve = next;
+ if (!ve)
+ break;
+ if (!(start = (char *)getdata(ve)) ||
+ start[0] != Inbrack ||
+ !(end = strchr(start+1, Outbrack)) ||
+ end[1] != Equals) {
+ zerr("bad array element, expected [key]=value: %s",
+ start);
+ return 0;
+ }
+ }
+ return 1;
+ }
+ return 0;
+}
+
/**/
static void
addvars(Estate state, Wordcode pc, int addflags)
@@ -2428,8 +2482,17 @@ addvars(Estate state, Wordcode pc, int addflags)
if ((isstr = (WC_ASSIGN_TYPE(ac) == WC_ASSIGN_SCALAR))) {
init_list1(svl, ecgetstr(state, EC_DUPTOK, &htok));
vl = &svl;
- } else
+ } else {
vl = ecgetlist(state, WC_ASSIGN_NUM(ac), EC_DUPTOK, &htok);
+ if (keyvalpairarray(vl, htok)) {
+ myflags |= ASSPM_KEY_VALUE;
+ htok = 0;
+ }
+ if (errflag) {
+ state->pc = opc;
+ return;
+ }
+ }
if (vl && htok) {
prefork(vl, (isstr ? (PREFORK_SINGLE|PREFORK_ASSIGN) :
@@ -3914,7 +3977,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
while ((data = ugetnode(&svl))) {
char *ptr;
asg = (Asgment)zhalloc(sizeof(struct asgment));
- asg->is_array = 0;
+ asg->flags = 0;
if ((ptr = strchr(data, '='))) {
*ptr++ = '\0';
asg->name = data;
@@ -3936,7 +3999,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
asg->name = name;
if (WC_ASSIGN_TYPE(ac) == WC_ASSIGN_SCALAR) {
char *val = ecgetstr(state, EC_DUPTOK, &htok);
- asg->is_array = 0;
+ asg->flags = 0;
if (WC_ASSIGN_TYPE2(ac) == WC_ASSIGN_INC) {
/* Fake assignment, no value */
asg->value.scalar = NULL;
@@ -3961,18 +4024,23 @@ execcmd_exec(Estate state, Execcmd_params eparams,
asg->value.scalar = val;
}
} else {
- asg->is_array = 1;
+ asg->flags = ASG_ARRAY;
asg->value.array =
ecgetlist(state, WC_ASSIGN_NUM(ac),
EC_DUPTOK, &htok);
if (asg->value.array)
{
- prefork(asg->value.array, PREFORK_ASSIGN, NULL);
- if (errflag) {
- state->pc = opc;
- break;
+ if (keyvalpairarray(asg->value.array, 1))
+ asg->flags |= ASG_KEY_VALUE;
+ else if (!errflag) {
+ prefork(asg->value.array, PREFORK_ASSIGN,
+ NULL);
+ if (errflag) {
+ state->pc = opc;
+ break;
+ }
+ globlist(asg->value.array, 0);
}
- globlist(asg->value.array, 0);
if (errflag) {
state->pc = opc;
break;
diff --git a/Src/params.c b/Src/params.c
index 6fbee88..e0aaaf6 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3185,6 +3185,72 @@ assignaparam(char *s, char **val, int flags)
if (flags & ASSPM_WARN)
check_warn_pm(v->pm, "array", created, may_warn_about_nested_vars);
+
+ if ((flags & ASSPM_KEY_VALUE) && (PM_TYPE(v->pm->node.flags) & PM_ARRAY)) {
+ /*
+ * This is an ordinary array with key / value pairs.
+ */
+ int maxlen, origlen;
+ char **aptr, **fullval;
+ zlong *subscripts = (zlong *)zhalloc(arrlen(val) * sizeof(zlong));
+ zlong *iptr = subscripts;
+ if (flags & ASSPM_AUGMENT) {
+ maxlen = origlen = arrlen(v->pm->gsu.a->getfn(v->pm));
+ } else {
+ maxlen = origlen = 0;
+ }
+ for (aptr = val; *aptr && aptr[1]; aptr += 2) {
+ *iptr = mathevali(*aptr);
+ if (*iptr < 0 ||
+ (!isset(KSHARRAYS) && *iptr == 0)) {
+ unqueue_signals();
+ zerr("bad subscript for direct array assignment: %s", *aptr);
+ return NULL;
+ }
+ if (!isset(KSHARRAYS))
+ --*iptr;
+ if (*iptr + 1 > maxlen)
+ maxlen = *iptr + 1;
+ ++iptr;
+ }
+ fullval = zshcalloc((maxlen+1) * sizeof(char *));
+ if (!fullval) {
+ zerr("array too large");
+ return NULL;
+ }
+ fullval[maxlen] = NULL;
+ if (flags & ASSPM_AUGMENT) {
+ char **srcptr = v->pm->gsu.a->getfn(v->pm);
+ for (aptr = fullval; aptr <= fullval + origlen; aptr++) {
+ *aptr = ztrdup(*srcptr);
+ srcptr++;
+ }
+ }
+ iptr = subscripts;
+ for (aptr = val; *aptr && aptr[1]; aptr += 2) {
+ zsfree(*aptr);
+ fullval[*iptr] = aptr[1];
+ ++iptr;
+ }
+ if (*aptr) { /* Shouldn't be possible */
+ DPUTS(1, "Extra element in key / value array");
+ zsfree(*aptr);
+ }
+ free(val);
+ for (aptr = fullval; aptr < fullval + maxlen; aptr++) {
+ /*
+ * Remember we don't have sparse arrays but and they're null
+ * terminated --- so any value we don't set has to be an
+ * empty string.
+ */
+ if (!*aptr)
+ *aptr = ztrdup("");
+ }
+ setarrvalue(v, fullval);
+ unqueue_signals();
+ return v->pm;
+ }
+
if (flags & ASSPM_AUGMENT) {
if (v->start == 0 && v->end == -1) {
if (PM_TYPE(v->pm->node.flags) & PM_ARRAY) {
diff --git a/Src/zsh.h b/Src/zsh.h
index 1e982a6..27642f2 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1217,17 +1217,25 @@ struct alias {
struct asgment {
struct linknode node;
char *name;
- int is_array;
+ int flags;
union {
char *scalar;
LinkList array;
} value;
};
+/* Flags for flags element of asgment */
+enum {
+ /* Array value */
+ ASG_ARRAY = 1,
+ /* Key / value array pair */
+ ASG_KEY_VALUE = 2
+};
+
/*
* Assignment is array?
*/
-#define ASG_ARRAYP(asg) ((asg)->is_array)
+#define ASG_ARRAYP(asg) ((asg)->flags & ASG_ARRAY)
/*
* Assignment has value?
@@ -2060,6 +2068,11 @@ enum {
ASSPM_WARN = (ASSPM_WARN_CREATE|ASSPM_WARN_NESTED),
/* Import from environment, so exercise care evaluating value */
ASSPM_ENV_IMPORT = 1 << 3,
+ /* Array is key / value pairs.
+ * This is normal for associative arrays but variant behaviour for
+ * normal arrays.
+ */
+ ASSPM_KEY_VALUE = 1 << 4
};
/* node for named directory hash table (nameddirtab) */
diff --git a/Test/B02typeset.ztst b/Test/B02typeset.ztst
index b27bb4f..ae21804 100644
--- a/Test/B02typeset.ztst
+++ b/Test/B02typeset.ztst
@@ -721,3 +721,58 @@
# 'date' did not run.
>Status is printed, 1
*?*: failed to change user ID: *
+
+ typeset -A keyvalhash=([one]=eins [two]=zwei)
+ keyvalhash+=([three]=drei)
+ for key in ${(ok)keyvalhash}; do
+ print $key $keyvalhash[$key]
+ done
+0:[key]=val for hashes
+>one eins
+>three drei
+>two zwei
+
+ local keyvalarray=([1]=one [3]=three)
+ print -l "${keyvalarray[@]}"
+ keyvalarray+=([2]=two)
+ print -l "${keyvalarray[@]}"
+ local keyvalarray=([1]=one [3]=three)
+ print -l "${keyvalarray[@]}"
+0:[key]=val for normal arrays
+>one
+>
+>three
+>one
+>two
+>three
+>one
+>
+>three
+
+ touch foo Xnot_globbedX
+ inkey="another key" val="another value"
+ typeset -A keyvalhash=([$(echo the key)]=$(echo the value)
+ [$inkey]=$val
+ [*]=?not_globbed?)
+ for key in ${(ok)keyvalhash}; do
+ print -l $key $keyvalhash[$key]
+ done
+ typeset -A keyvalhash=([$(echo the key)]=$(echo the value)
+ [$inkey]=$val
+ [*]=?not_globbed?)
+ for key in ${(ok)keyvalhash}; do
+ print -l $key $keyvalhash[$key]
+ done
+0:Substitution in [key]=val syntax
+>*
+>?not_globbed?
+>another key
+>another value
+>the key
+>the value
+>*
+>?not_globbed?
+>another key
+>another value
+>the key
+>the value
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 8dbc1e8..367bca1 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -2207,3 +2207,71 @@ F:behavior, see http://austingroupbugs.net/view.php?id=888
0:(z) splitting with remaining tokens
>foo-bar*thingy?
+ typeset -A keyvalhash
+ keyvalhash=([one]=eins [two]=zwei)
+ keyvalhash+=([three]=drei)
+ for key in ${(ok)keyvalhash}; do
+ print $key $keyvalhash[$key]
+ done
+0:[key]=val for hashes
+>one eins
+>three drei
+>two zwei
+
+ local keyvalarray
+ keyvalarray=([1]=one [3]=three)
+ print -l "${keyvalarray[@]}"
+ keyvalarray+=([2]=two)
+ print -l "${keyvalarray[@]}"
+0:[key]=val for normal arrays
+>one
+>
+>three
+>one
+>two
+>three
+
+ typeset -A keyvalhash
+ touch foo Xnot_globbedX
+ key="another key" val="another value"
+ keyvalhash=([$(echo the key)]=$(echo the value)
+ [$key]=$val
+ [*]=?not_globbed?)
+ for key in ${(ok)keyvalhash}; do
+ print -l $key $keyvalhash[$key]
+ done
+0:Substitution in [key]=val syntax
+>*
+>?not_globbed?
+>another key
+>another value
+>the key
+>the value
+
+ local keyvalarray
+ keyvalarray=(1 2 3)
+ keyvalarray+=([5]=5 [7]=7)
+ keyvalarray+=([4]=4 [6]=6)
+ print $#keyvalarray
+ print $keyvalarray
+0:append to normal array using [key]=val
+>7
+>1 2 3 4 5 6 7
+
+ local -A keyvalhash
+ keyvalhash=(['1first element!']=first' 'value
+ ["2second element?"]=second" "value
+ [$'3third element#']=third$' 'value
+ [\4\f\o\u\r\t\h\ \e\l\e\m\e\n\t\\]=fourth\ value)
+ for key in ${(ok)keyvalhash}; do
+ print -rl -- $key $keyvalhash[$key]
+ done
+0:quoting in [key]=value syntax
+>1first element!
+>first value
+>2second element?
+>second value
+>3third element#
+>third value
+>4fourth element\
+>fourth value
Messages sorted by:
Reverse Date,
Date,
Thread,
Author