From 54b395844030342213cacba4c569a6c5e6781c46 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 13 Sep 2017 20:54:00 +0100 Subject: First go at var=([key]=value) syntax. Works for both normal and typeset case, also var+=... Still to do: allow to be mixed with straight array assignment, improve typeset -p, implement [key]+=value. --- Doc/Zsh/params.yo | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'Doc') diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo index 817496b8a..31266a7d0 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. -- cgit 1.4.1