Subject: Re: bufferwords() lexes a subshell in a shortloop repeat as a string
From: Bart Schaefer <[email-masked]>
To: Daniel Shahaf <[email-masked]>
Cc: Peter Stephenson <[email-masked]>, Zsh hackers list <[email-masked]>
Date: Mon, 18 Jan 2016 20:56:04 -0800
List-Id: Zsh Workers List <zsh-workers.zsh.org>

[Returning to the original topic of this thread ...]

On Sun, Jan 17, 2016 at 6:25 PM, Daniel Shahaf <[email-masked]> wrote:
> What confuses me is that 'repeat 3 (x)' and 'repeat 3; do (x); done' are
> split differently. ;-)
>
> Shouldn't both of them treat the "(x)" the same way [either both of
> them considering it one unit, or both of them considering it three units]?

As Peter said earlier, the (z) flag does nothing but break the string
into syntactic shell words.  With the exception of "for" loops, which
are a weird special case because of "for ((...))", It does NOT
interpret shell keywords to parse any corresponding loop structures.
It knows a little about assignments and redirections but otherwise
reads lexical tokens in their most generic possible context; you can
think of it as having "lex" without "yacc" to drive it.

(z) also does not expand aliases, which means that even if it did
interpret keywords you could trivially break it by aliasing something
else to expand as "repeat" or vice-versa.  (In fact you can already
break the magic "for" parsing the same way.)