mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-06 09:01:13 +02:00
More [key]=value tweaks
Some rephrasings. Update typeset -p for associative arrays to use new syntax.
This commit is contained in:
parent
7ca2e97c14
commit
ab7be4238c
6 changed files with 24 additions and 10 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2017-09-14 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
|
* Doc/Zsh/expn.yo, Doc/ZSh/params.yo, Src/params.c,
|
||||||
|
Test/B02typeset.ztst, Test/V10private.ztst: typeset -p output
|
||||||
|
for associative arrays and some rephrasings.
|
||||||
|
|
||||||
2017-09-13 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
2017-09-13 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
* unposted: typo in proceeding Doc noticed by Oliver.
|
* unposted: typo in proceeding Doc noticed by Oliver.
|
||||||
|
|
|
@ -1025,9 +1025,10 @@ ifnzman(noderef(Filename Expansion))\
|
||||||
ifzman(the section FILENAME EXPANSION below).
|
ifzman(the section FILENAME EXPANSION below).
|
||||||
)
|
)
|
||||||
item(tt(e))(
|
item(tt(e))(
|
||||||
Perform em(parameter expansion), em(command substitution) and
|
Perform single word shell expansions, namely em(parameter expansion),
|
||||||
em(arithmetic expansion) on the result. Such expansions can be
|
em(command substitution) and em(arithmetic expansion), on the
|
||||||
nested but too deep recursion may have unpredictable effects.
|
result. Such expansions can be nested but too deep recursion may have
|
||||||
|
unpredictable effects.
|
||||||
)
|
)
|
||||||
item(tt(f))(
|
item(tt(f))(
|
||||||
Split the result of the expansion at newlines. This is a shorthand
|
Split the result of the expansion at newlines. This is a shorthand
|
||||||
|
|
|
@ -102,13 +102,16 @@ 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
|
not be quoted, while var(key) may not consist of the unquoted string
|
||||||
tt(]=), but is otherwise treated as a simple string. Furthermore, all
|
tt(]=), but is otherwise treated as a simple string. Furthermore, all
|
||||||
elements must match this form or an error is generated; likewise, if the
|
elements must match this form or an error is generated; likewise, if the
|
||||||
first entry does not match this form any later entry that does is taken
|
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
|
as a simple value rather than a key / value pair. The enhanced forms of
|
||||||
subscript expression that may be used when directly subscripting a
|
subscript expression that may be used when directly subscripting a
|
||||||
variable name, described in the section Array Subscripts below, are not
|
variable name, described in the section Array Subscripts below, are not
|
||||||
available. Both var(key) and var(value) undergo all forms of expansion
|
available. Both var(key) and var(value) undergo all forms of expansion
|
||||||
allowed for single word substitutions (this does not include filename
|
allowed for single word shell expansions (this does not include filename
|
||||||
generation).
|
generation); these are as performed by the parameter expansion flag
|
||||||
|
tt(LPAR()e+RPAR()) as described in
|
||||||
|
ifzman(zmanref(zshparam))\
|
||||||
|
ifnzman(nodref(Parameter Expansion)).
|
||||||
|
|
||||||
If no parameter var(name) exists, an ordinary array parameter is created.
|
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
|
If the parameter var(name) exists and is a scalar, it is replaced by a new
|
||||||
|
|
|
@ -5564,9 +5564,7 @@ printparamvalue(Param p, int printflags)
|
||||||
{
|
{
|
||||||
char *t, **u;
|
char *t, **u;
|
||||||
|
|
||||||
if (printflags & PRINT_KV_PAIR)
|
if (!(printflags & PRINT_KV_PAIR))
|
||||||
putchar(' ');
|
|
||||||
else
|
|
||||||
putchar('=');
|
putchar('=');
|
||||||
|
|
||||||
/* How the value is displayed depends *
|
/* How the value is displayed depends *
|
||||||
|
@ -5721,7 +5719,11 @@ printparamnode(HashNode hn, int printflags)
|
||||||
zputs(p->node.nam, stdout);
|
zputs(p->node.nam, stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
} else {
|
} else {
|
||||||
|
if (printflags & PRINT_KV_PAIR)
|
||||||
|
putchar('[');
|
||||||
quotedzputs(p->node.nam, stdout);
|
quotedzputs(p->node.nam, stdout);
|
||||||
|
if (printflags & PRINT_KV_PAIR)
|
||||||
|
printf("]=");
|
||||||
|
|
||||||
printparamvalue(p, printflags);
|
printparamvalue(p, printflags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -763,6 +763,7 @@
|
||||||
for key in ${(ok)keyvalhash}; do
|
for key in ${(ok)keyvalhash}; do
|
||||||
print -l $key $keyvalhash[$key]
|
print -l $key $keyvalhash[$key]
|
||||||
done
|
done
|
||||||
|
typeset -p keyvalhash
|
||||||
0:Substitution in [key]=val syntax
|
0:Substitution in [key]=val syntax
|
||||||
>*
|
>*
|
||||||
>?not_globbed?
|
>?not_globbed?
|
||||||
|
@ -776,3 +777,4 @@
|
||||||
>another value
|
>another value
|
||||||
>the key
|
>the key
|
||||||
>the value
|
>the value
|
||||||
|
>typeset -A keyvalhash=( ['*']='?not_globbed?' ['another key']='another value' ['the key']='the value' )
|
||||||
|
|
|
@ -123,7 +123,7 @@
|
||||||
print ${(kv)hash_test}
|
print ${(kv)hash_test}
|
||||||
0:private hides value from surrounding scope in nested scope
|
0:private hides value from surrounding scope in nested scope
|
||||||
>typeset -a hash_test=( top level )
|
>typeset -a hash_test=( top level )
|
||||||
>typeset -A hash_test=( in function )
|
>typeset -A hash_test=( [in]=function )
|
||||||
>typeset -g -a hash_test=( top level )
|
>typeset -g -a hash_test=( top level )
|
||||||
>array-local top level
|
>array-local top level
|
||||||
>top level
|
>top level
|
||||||
|
|
Loading…
Reference in a new issue