From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9798 invoked by alias); 22 Jun 2015 15:46:15 -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: 35564 Received: (qmail 1405 invoked from network); 22 Jun 2015 15:46:12 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,T_HDRS_LCASE, T_MANY_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.0 X-AuditID: cbfec7f4-f79c56d0000012ee-98-55882b6220e4 Date: Mon, 22 Jun 2015 16:35:59 +0100 From: Peter Stephenson To: Zsh Hackers' List Subject: Typeset dpc (typeset-array) Message-id: <20150622163559.2c2b737a@pwslap01u.europe.root.pri> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFLMWRmVeSWpSXmKPExsVy+t/xy7pJ2h2hBq9XaVscbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujLt7rrMXNIVWnHi+lrmB8ZRrFyMnh4SAiUT7u2Z2CFtM4sK9 9WxdjFwcQgJLGSWaZnxgh3BmMEm8OrYSKrONUeLst9XMIC0sAqoSd/5sZQWx2QQMJaZums3Y xcjBISKgLdH+UQzEFBZQkXh2twCkglfAXuJD02M2EJtfQF/i6t9PTBCL7SVmXjnDCFEjKPFj 8j0WEJtZQEti87YmVghbXmLzmrdgW4UE1CVu3N3NPoFRYBaSlllIWmYhaVnAyLyKUTS1NLmg OCk911CvODG3uDQvXS85P3cTIyQEv+xgXHzM6hCjAAejEg+vg217qBBrYllxZe4hRgkOZiUR 3pazQCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8c3e9DxESSE8sSc1OTS1ILYLJMnFwSjUwyv63 +Fe0ZPM9tkKH1Q/iziRdSLkknzH/pcu9d+7pHOa5Kp/FSm+yn5Dbvr2d+aVU/MeGBw0fPu76 +0E+s08/m+He54u3vxWv6bOdO+WZ9m7udJcFHpGunwNrtVxnTHp2rikp5PWDf9LHRb9+zO37 EO1ulrtc7GmE5ZbCLey7Jq2z+3HqZ2uisBJLcUaioRZzUXEiAGSZmxE9AgAA This mostly adds various sorts of documentation to describe how the typeset changes work, which deserve reading. I've assumed for now we aren't going to find anything that makes this hard to turn on by default. There are a couple of rationalisations: KSH_TYPESET is no longer needed even in emulation, and also I realised there are cases for which it makes sense to parse integer and float the same as the others: integer val=$(echo 1 + 2) pws diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 12a13ca..aca0439 100644 --- a/Doc/Zsh/builtins.yo +++ b/Doc/Zsh/builtins.yo @@ -1753,12 +1753,60 @@ tt(typeset vbl=$(echo one two)) is treated as having one argument if tt(KSH_TYPESET) is set, but otherwise is treated as having the two arguments tt(vbl=one) and tt(two). +If the reserved word tt(declare), tt(export), tt(float), tt(integer), +tt(local), tt(readonly) or tt(typeset) is matched when the line is +parsed (N.B. not when it is executed), and the reserved word has not +been disabled with tt(disable -r), the shell will try to parse arguments +as assignments, except that the `tt(+=)' syntax and the tt(GLOB_ASSIGN) +option are not supported. This has two major differences from normal +command line argument parsing: array assignment is possible, and scalar +values after tt(=) are not split further into words even if expanded +(regardless of the setting of the tt(KSH_TYPESET) option). Here is an +example: + +example(# Reserved word parsing +typeset svar=$(echo one word) avar=(several words)) + +The above creates a scalar parameter tt(svar) with the value `tt(one +word)' and an array parameter tt(avar) with a value containing two +entries, `tt(several)' and `tt(words)'. On the other hand: + +example(# Normal builtin interface +cmd=typeset +$cmd svar=$(echo two words)) + +The above creates a scalar tt(svar) contain the value tt(two) and +another scalar parameter tt(words) with no value. An array value in +this case would either cause an error or be treated as an obscure set of +glob qualifiers. + +Arbitrary arguments are allowed if they take the form of assignments +after command line expansion; however, these only perform scalar +assignment: + +example(var='svar=val' +typeset $var) + +The above sets the scalar parameter tt(svar) to the value tt(val). +Parentheses around the value within tt(var) would not cause array +assignment as they will be treated as ordinary characters when tt($var) +is substituted. Any non-trivial expansion in the name part of the +assignment causes the argument to be treated in this fashion: + +example(typeset {var1,var2,var3}=name) + +The above syntax is valid, and has the expected effect of setting the +three parameters to the same value, but the command line is parsed as +a set of three normal command line arguments to tt(typeset) after +expansion. Hence it is not possible to assign to multiple arrays by +this means. + If the shell option tt(TYPESET_SILENT) is not set, for each remaining -var(name) that refers to a parameter that is set, the name and value of the -parameter are printed in the form of an assignment. Nothing is printed for -newly-created parameters, or when any attribute flags listed below are -given along with the var(name). Using `tt(PLUS())' instead of minus to -introduce an attribute turns it off. +var(name) that refers to a parameter that is already set, the name and +value of the parameter are printed in the form of an assignment. +Nothing is printed for newly-created parameters, or when any attribute +flags listed below are given along with the var(name). Using +`tt(PLUS())' instead of minus to introduce an attribute turns it off. If no var(name) is present, the names and values of all parameters are printed. In this case the attribute flags restrict the display to only @@ -1829,7 +1877,7 @@ the current state, readonly specials (whose values cannot be changed) are not shown and assignments to arrays are shown before the tt(typeset) rendering the array readonly. ) -item(tt(-T) [ var(scalar)[tt(=)var(value)] var(array) [ var(sep) ] ])( +item(tt(-T) [ var(scalar)[tt(=)var(value)] var(array)[tt(=)LPAR()var(value...)RPAR()] [ var(sep) ] ])( This flag has a different meaning when used with tt(-f); see below. Otherwise the tt(-T) option requires zero, two, or three arguments to be present. With no arguments, the list of parameters created in this @@ -1839,10 +1887,13 @@ together in the manner of tt($PATH) and tt($path). The optional third argument is a single-character separator which will be used to join the elements of the array to form the scalar; if absent, a colon is used, as with tt($PATH). Only the first character of the separator is significant; -any remaining characters are ignored. +any remaining characters are ignored. Multibyte characters are not +yet supported. + +Only one of the scalar and array parameters may be assigned an initial +value (the restrictions on assignment forms described above also apply). -Only the scalar parameter may be assigned an initial value. Both the -scalar and the array may otherwise be manipulated as normal. If one is +Both the scalar and the array may be manipulated as normal. If one is unset, the other will automatically be unset too. There is no way of untying the variables without unsetting them, nor of converting the type of one of them with another tt(typeset) command; tt(+T) does not work, diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 4476fc3..83968fe 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -472,7 +472,8 @@ word of a command unless quoted or disabled using tt(disable -r): tt(do done esac then elif else fi for case if while function repeat time until -select coproc nocorrect foreach end ! [[ { }) +select coproc nocorrect foreach end ! [[ { } +declare export float integer local readonly typeset) Additionally, `tt(})' is recognized in any position if neither the tt(IGNORE_BRACES) option nor the tt(IGNORE_CLOSE_BRACES) option is set. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index db9b18b..b4a5e10 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1928,7 +1928,13 @@ pindex(KSHTYPESET) pindex(NOKSHTYPESET) cindex(argument splitting, in typeset etc.) cindex(ksh, argument splitting in typeset) -item(tt(KSH_TYPESET) )( +item(tt(KSH_TYPESET))( +This option is now obsolete: a better appropximation to the behaviour of +other shells is obtained with the reserved word interface to +tt(declare), tt(export), tt(float), tt(integer), tt(local), tt(readonly) +and tt(typeset). Note that the option is only applied when the reserved +word interface is em(not) in use. + Alters the way arguments to the tt(typeset) family of commands, including tt(declare), tt(export), tt(float), tt(integer), tt(local) and tt(readonly), are processed. Without this option, zsh will perform normal diff --git a/NEWS b/NEWS index 44bf6b9..d515a60 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,21 @@ CHANGES FROM PREVIOUS VERSIONS OF ZSH Note also the list of incompatibilities in the README file. -Changes from 5.0.7 to 5.0.8 +Changes from 5.0.8 to 5.0.9 +--------------------------- + +The builtins declare, export, local, readonly and typeset +now have corresponding reserved words. When used in +this form, the builtin syntax is extended so that assignments +following the reserved word are treated similarly to +assignments that appear at the start of the command line. +For example, + local scalar=`echo one word` array=(several words) +creates a local "scalar" containing the text "one word" +and an array "array" containing the words "several" +"words". + +Changes from 5.0.0 to 5.0.8 --------------------------- - Global aliases can be created for syntactic tokens such as command @@ -47,9 +61,6 @@ Changes from 5.0.7 to 5.0.8 - Some rationalisations have been made to the zsh/db/gdbm module that should make it more useful and predictable in operation. -Changes from 5.0.0 to 5.0.7 ---------------------------- - - Numeric constants encountered in mathematical expressions (but not other contexts) can contain underscores as separators that will be ignored on evaluation, as allowed in other scripting languages. For example, diff --git a/README b/README index 10f29a4..0b985fb 100644 --- a/README +++ b/README @@ -30,6 +30,23 @@ Zsh is a shell with lots of features. For a list of some of these, see the file FEATURES, and for the latest changes see NEWS. For more details, see the documentation. +Incompatibilites between 5.0.8 and 5.0.9 +---------------------------------------- + +As noted in NEWS, the builtins declare, export, float, integer, local, +readonly and typeset now have corresponding reserved words that provide +true assignment semantics instead of an approximation by means of normal +command line arguments. It is hoped that this additional consistency +provides a more natural interface. However, compatbility with older +versions of zsh can be obtained by turning off the reserved word +interface, exposing the builtin interface: + + disable -r declare export float integer local readonly typeset + +This is also necessary in the unusual eventuality that the builtins are +to be replaced by shell functions, since reserved words take precedence +over functions. + Incompatibilites between 5.0.7 and 5.0.8 ---------------------------------------- diff --git a/Src/hashtable.c b/Src/hashtable.c index b4c83a1..90739a8 100644 --- a/Src/hashtable.c +++ b/Src/hashtable.c @@ -1059,10 +1059,12 @@ static struct reswd reswds[] = { {{NULL, "esac", 0}, ESAC}, {{NULL, "export", 0}, TYPESET}, {{NULL, "fi", 0}, FI}, + {{NULL, "float", 0}, TYPESET}, {{NULL, "for", 0}, FOR}, {{NULL, "foreach", 0}, FOREACH}, {{NULL, "function", 0}, FUNC}, {{NULL, "if", 0}, IF}, + {{NULL, "integer", 0}, TYPESET}, {{NULL, "local", 0}, TYPESET}, {{NULL, "nocorrect", 0}, NOCORRECT}, {{NULL, "readonly", 0}, TYPESET}, diff --git a/Src/options.c b/Src/options.c index 78f603d..da3d830 100644 --- a/Src/options.c +++ b/Src/options.c @@ -172,7 +172,7 @@ static struct optname optns[] = { {{NULL, "kshautoload", OPT_EMULATE|OPT_BOURNE}, KSHAUTOLOAD}, {{NULL, "kshglob", OPT_EMULATE|OPT_KSH}, KSHGLOB}, {{NULL, "kshoptionprint", OPT_EMULATE|OPT_KSH}, KSHOPTIONPRINT}, -{{NULL, "kshtypeset", OPT_EMULATE|OPT_KSH}, KSHTYPESET}, +{{NULL, "kshtypeset", 0}, KSHTYPESET}, {{NULL, "kshzerosubscript", 0}, KSHZEROSUBSCRIPT}, {{NULL, "listambiguous", OPT_ALL}, LISTAMBIGUOUS}, {{NULL, "listbeep", OPT_ALL}, LISTBEEP},