zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Parse error (lack thereof) on incomplete loops
Date: Fri, 5 Oct 2018 18:47:01 -0700	[thread overview]
Message-ID: <CAH+w=7auLdphdcLBsKFsEqyRE0Ug6o+13TYOVx-KO3g9Z2QP2Q@mail.gmail.com> (raw)
In-Reply-To: <20181005091435eucas1p26edaafb362de339b01c3cb5780fbd108~aq5QQQ6pF1496014960eucas1p2g@eucas1p2.samsung.com>

On Fri, Oct 5, 2018 at 2:14 AM Peter Stephenson
<p.stephenson@samsung.com> wrote:
>
> The original expression is parsed as
>
> {
>   while {
>     false
>     while false; do
>     done
>     }; do
>   done
> }
>
> which is an infinite loop because of the point above.  [...]  However,
> apart from that there's nothing new [...]  The only new feature is that all
> the "do ... done" clause has become optional if it's possible to infer
> there's nothing there.  That seems to me entirely consistent.

I would contend that the point of SHORT_LOOPS is not to be able to
omit the loop body, it's to be able to abbreviate the syntax that
delimits the loop conditions and separates them from the loop body.
But of what possible use, for example, is { repeat 5 } which this
"accidental feature" allows?  Or { select foo } or { for x } ?  And if
{ for x } is allowed, why is { for x in z } an error, particularly if
you're arguing that it's obvious the "do-done" is meant to be empty?
Why should it have to be { for x in z; } when a trailing semicolon is
not required in other brace expressions?

> Without a "do" while doesn't know where the expression ends.  That's
> fundamental to how SHORT_LOOPS works

No it isn't.  The documentation explicitly says:

  For the if, while and until commands, in both these cases the test part
  of the loop must also be suitably delimited, such as by `[[ ... ]]' or
  `(( ... )), else the end of the test will not be recognized.

"Both these cases" refers to:
#1 - sublist is of the form `{ list }'
#2 - the SHORT_LOOPS option is set

So you don't get to claim that SHORT_LOOPS is intended to except you
from that restriction.  The "]]" or "))" tell while where the
expression ends.

In none of the examples given in this thread so far has the test
expression been delimited that way.

  parent reply	other threads:[~2018-10-06  1:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20181004154947epcas4p2441e109a2c4e060bf39f0f6925e98241@epcas4p2.samsung.com>
2018-10-04 15:49 ` Bart Schaefer
2018-10-04 16:31   ` Peter Stephenson
2018-10-04 20:04     ` Marc Chantreux
2018-10-04 20:37       ` Bart Schaefer
2018-10-05  6:04         ` Marc Chantreux
2018-10-04 20:34     ` Bart Schaefer
2018-10-05  9:14       ` Peter Stephenson
2018-10-05 13:26         ` Daniel Shahaf
2018-10-05 13:47           ` Peter Stephenson
2018-10-05 17:04             ` Daniel Shahaf
2018-10-06  1:47         ` Bart Schaefer [this message]
2018-10-06 11:15           ` Peter Stephenson
2018-10-06 11:55             ` Peter Stephenson
2018-10-06 18:21           ` Peter Stephenson
2018-10-07  3:51             ` Bart Schaefer
2018-10-07 18:16               ` Bart Schaefer
2018-10-08 10:07               ` 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='CAH+w=7auLdphdcLBsKFsEqyRE0Ug6o+13TYOVx-KO3g9Z2QP2Q@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=p.stephenson@samsung.com \
    --cc=zsh-workers@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).