From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: ${(z)} parsing of multiple array assignments
Date: Sun, 29 Dec 2019 20:55:12 +0000 [thread overview]
Message-ID: <7b7a941ddc3c20bea6a6b69b1e7ac35d827f320d.camel@ntlworld.com> (raw)
In-Reply-To: <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:
next prev parent reply other threads:[~2019-12-29 20:56 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-23 17:31 Daniel Shahaf
2019-12-24 20:34 ` Phil Pennock
2019-12-24 23:16 ` Sebastian Gniazdowski
2019-12-29 20:55 ` Peter Stephenson [this message]
2019-12-29 23:45 ` Peter Stephenson
2019-12-30 18:13 ` Daniel Shahaf
2019-12-30 18:21 ` Daniel Shahaf
2019-12-30 22:37 ` Peter Stephenson
2019-12-30 23:46 ` Daniel Shahaf
2019-12-31 11:58 ` Daniel Shahaf
2019-12-31 18:35 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7b7a941ddc3c20bea6a6b69b1e7ac35d827f320d.camel@ntlworld.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).