* When is a pre-command assignment syntactically valid?
@ 2017-12-06 23:23 Daniel Shahaf
2017-12-07 1:57 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2017-12-06 23:23 UTC (permalink / raw)
To: zsh-users
In z-sy-h we're trying to determine in what circumstances an assignment is
valid before a command.¹
Empirically, when an assignment is followed by one of the reserved words
«((» «[[» «(» «{» «!»
a parse error results, but when an assignment is followed by the name of a
command, builtin, or function, execution succeeds. It doesn't seem to matter
whether the assigned parameter is a scalar or an array. (Of course, setting
an array in front of an external command, as in «a=(foo bar) /bin/true», isn't
necessarily _useful_ — barring 'typeset -T' and hooks — but it's syntactically
valid, which is z-sy-h's concern.)
So, I think the rule is: "reserved words may not be preceded by parameter
assignments". Is that accurate?
Thanks,
Daniel
P.S. Incidentally, I can see how it might be useful to allow assignments before
some of these constructs (e.g., «foo=bar (subshell; commands;)»), but I'm not
advocating for that; I'm just trying to grok the status quo so z-sy-h can
support it.
¹ https://github.com/zsh-users/zsh-syntax-highlighting/issues/461
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: When is a pre-command assignment syntactically valid?
2017-12-06 23:23 When is a pre-command assignment syntactically valid? Daniel Shahaf
@ 2017-12-07 1:57 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2017-12-07 1:57 UTC (permalink / raw)
To: Daniel Shahaf; +Cc: Zsh Users
On Wed, Dec 6, 2017 at 3:23 PM, Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
> I think the rule is: "reserved words may not be preceded by parameter
> assignments". Is that accurate?
Literally, the rule is "parameter assignments may precede only a
simple command." (In fact the assignment syntax is part of the
definition of simple command syntax.)
Of the set of $reswords from zsh/parameter, "nocorrect" and all of the
aliases for "typeset" may begin a simple command. The rest may not.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-12-07 1:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-06 23:23 When is a pre-command assignment syntactically valid? Daniel Shahaf
2017-12-07 1:57 ` Bart Schaefer
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).