From 5c513aa33f136aebfdb1cb4f25ea18b7cc750f22 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 22 Jun 2015 16:37:59 +0100 Subject: Documentation for new typeset parsing. Don't need KSH_TYPESET even in emulation. integer and float should be parsed the same way in case of arguments that will be evaluated as expressions. --- Doc/Zsh/builtins.yo | 69 ++++++++++++++++++++++++++++++++++++++++++++++------- Doc/Zsh/grammar.yo | 3 ++- Doc/Zsh/options.yo | 8 ++++++- NEWS | 19 +++++++++++---- README | 17 +++++++++++++ Src/hashtable.c | 2 ++ Src/options.c | 2 +- 7 files changed, 104 insertions(+), 16 deletions(-) diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo index 12a13caa0..aca0439dd 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 4476fc392..83968fedf 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 db9b18b8c..b4a5e105f 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 44bf6b9c0..d515a6036 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 10f29a4ed..0b985fb7d 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 b4c83a1fa..90739a882 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 78f603de1..da3d8308a 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}, -- cgit 1.4.1