Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] (?) typeset array[position=index]=value



On Mon, May 31, 2021 at 11:18 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Wed, May 5, 2021 at 4:45 AM Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> > [typeset] chokes on lvalue='array[n=1]' or
> > lvalue='assoc[keywith=characters]'
>
> Hmm, I wonder if that should be considered a bug.

This copies (tweaked for context) the code from parse.c at line 2006
or thereabouts.

All tests still pass, but as you can see from the comment this is not
yet handling x+=y which there doesn't seem to be any reason for
typeset NOT to support; I think it would require only another flag in
struct asgment, but I haven't attempted that.

Commentary?

diff --git a/Src/builtin.c b/Src/builtin.c
index a16fddcb7..148c56952 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -1933,10 +1933,11 @@ getasg(char ***argvp, LinkList assigns)
     asg.flags = 0;

     /* search for `=' */
-    for (; *s && *s != '='; s++);
+    for (; *s && *s != '[' && *s != '=' /* && *s != '+' */; s++);
+    if (s > asg.name && *s == '[') skipparens('[', ']', &s);

     /* found `=', so return with a value */
-    if (*s) {
+    if (*s && *s == '=') {
     *s = '\0';
     asg.value.scalar = s + 1;
     } else {




Messages sorted by: Reverse Date, Date, Thread, Author