Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Parse error (lack thereof) on incomplete loops



So ... I've been looking through the git history of Doc/Zsh/grammar.yo ...

On Sat, Oct 6, 2018 at 11:21 AM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> On Fri, 5 Oct 2018 18:47:01 -0700
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >   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.
>
> Looked at this a bit more and I have fairly major doubts about the
> documentation (although I don't mean about the intention suggested by
> Bart which does seem reaonsble).

   2001-07-05  Peter Stephenson  <pws@xxxxxxx>

  +       * 15264: Doc/Zsh/grammar.yo: improve description of use of
  +       variant complex command forms to avoid confusing the present
  +       writer.
  +

So apparently you've had doubts about this for a long time.

>   The short versions below only work if var(sublist) is of the form `tt({)
>   var(list) tt(})' or if the tt(SHORT_LOOPS) option is set.

This appears to be a reference to
  item(tt(if) var(list) var(sublist))
and similar doc of "for", "repeat", and "select".

These also have the "{ list }" forms documented separately so I don't
know why the "sublist" form of while and until was never made explicit
(see guess at it below).

> so maybe that "{ list }" should really be "sublist"?

Or the form should just be added for congruence with the doc of the
other complex commands.  If they'd all been there separately in the
first place, the sentence about "var(sublist) is of the form ..."
might never have been needed.  It's also quite likely (I haven't dug
into this in the Src commits) that "while" and "until" originally did
NOT work with only a sublist and that they do is another accidental
feature from some even earlier parser change.

> It's also not clearly (or at all?  I can't see it) documented that you
> only get the SHORT_LOOPS effect if there's no delimiter --- if you stick
> one in it looks like a normal command list which it'll just go on parsing.

True that this is not called out, but implicitly from the grammar:
var(list) var(sep) var(sublist) matches a production yielding
var(list), so if there is a var(sep) then the var(list) isn't done
yet.  You have to have a grammatically concluded var(list) as the
conditional before you can tack on a var(sublist) as the body.

> Perhapse someone who may have to be Bart (I can't say I consider myself
> an expert in this having only just found out what's going on and I can't
> say anyone else is likely to, either) should suggest some words of
> wisdom to document SHORT_LOOPS as separate text rather than as part of
> the variant syntax section?  I don't mind writing this up.

I may have time to take a stab at this tomorrow, can't promise.  Maybe
the above is a start.  I also don't presently have a computer with
"yum" installed/working.



Messages sorted by: Reverse Date, Date, Thread, Author