Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ${(z)} parsing of multiple array assignments
- X-seq: zsh-users 24580
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: ${(z)} parsing of multiple array assignments
- Date: Sun, 29 Dec 2019 20:55:12 +0000
- In-reply-to: <20191223173115.bvhwbpfmqgqhngle@tarpaulin.shahaf.local2>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20191223173115.bvhwbpfmqgqhngle@tarpaulin.shahaf.local2>
On Mon, 2019-12-23 at 17:31 +0000, Daniel Shahaf wrote:
> In the following two cases, why are the assignments to $b
> parsed differently to the assignments to $a?
>
> % pz() { print -rl -- ${(qqqq)${(z)1}} }
>
> % pz 'a=() b=()'
> $'a=('
> $')'
> $'b='
> $'()'
>
> % pz 'a=(foo) b=(bar)'
> $'a=('
> $'foo'
> $')'
> $'b=(bar)'
Unless I'm missing some trick, bufferwords() is the function where we
need to update any parser state --- ctxtlex() is too low level for that,
it just handles the next token given the current state. So it's
probably something like this. Will need a new test adding.
Presumably the commenting out of ENVSTRING in ctxtlex() means we stay in
incmdpos in that case --- as this is just a single word assignment that
probably handles that case OK.
pws
diff --git a/Src/hist.c b/Src/hist.c
index 74116e82f..37cba4579 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -3321,6 +3321,7 @@ bufferwords(LinkList list, char *buf, int *index, int flags)
int owb = wb, owe = we, oadx = addedx, onc = nocomments;
int ona = noaliases, ocs = zlemetacs, oll = zlemetall;
int forloop = 0, rcquotes = opts[RCQUOTES];
+ int envarray = 0;
char *p, *addedspaceptr;
if (!list)
@@ -3404,6 +3405,14 @@ bufferwords(LinkList list, char *buf, int *index, int flags)
ctxtlex();
if (tok == ENDINPUT || tok == LEXERR)
break;
+ /*
+ * After an array assignment, return to the initial
+ * start-of-command state. There could be a second ENVARRAY.
+ */
+ if (tok == OUTPAR && envarray) {
+ incmdpos = 1;
+ envarray = 0;
+ }
if (tok == FOR) {
/*
* The way for (( expr1 ; expr2; expr3 )) is parsed is:
@@ -3441,6 +3450,7 @@ bufferwords(LinkList list, char *buf, int *index, int flags)
switch (tok) {
case ENVARRAY:
p = dyncat(tokstr, "=(");
+ envarray = 1;
break;
case DINPAR:
Messages sorted by:
Reverse Date,
Date,
Thread,
Author