zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-users@zsh.org
Subject: When is a pre-command assignment syntactically valid?
Date: Wed, 6 Dec 2017 23:23:05 +0000	[thread overview]
Message-ID: <20171206232305.naro27of6abrk4y3@tarpaulin.shahaf.local2> (raw)

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


             reply	other threads:[~2017-12-06 23:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-06 23:23 Daniel Shahaf [this message]
2017-12-07  1:57 ` Bart Schaefer

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=20171206232305.naro27of6abrk4y3@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --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).