From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Bug in if... then if... parsing
Date: Sun, 6 Mar 2016 14:27:31 -0800 [thread overview]
Message-ID: <160306142731.ZM3208@torch.brasslantern.com> (raw)
Reproducible at least as long ago as zsh-4.2.0.
Consider:
torch% x () {
function> if false
function if> then
function then> x=1
function then> elif true
function elif> then
function elif-then> if :
function elif-then if> else
function else> :
function else> fi
function> }
torch%
Here it is without the PS2 prompts:
x () {
if false
then
x=1
elif true
then
if :
else
:
fi
}
This should be a parse error --
torch% if :
if> else
zsh: parse error near `else'
torch%
-- but instead it's accepted, the parser has somehow implied the
"missing" then/fi with a blank line between:
torch% functions -x4 x
x () {
if false
then
x=1
elif true
then
if :
then
fi
else
:
fi
}
torch%
I was at one point able to get the parser into a state where this caused a
correct structure to syntax error because this weird implicit "fi" doubled
an actual "fi", but it was in the context of a larger function and I lost
it from my terminal scrollback by the time I worked out that it wasn't
something I was doing wrong. It had something to do with "then" appearing
with other code on the same line rather than on a line by itself.
As far as I can tell this only happens when "if" immediately follows "then".
At first I thought the "elif" was also required, but no:
torch% if :
if> then
then> if :
then if> else
else> fi
torch%
next reply other threads:[~2016-03-06 22:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-06 22:27 Bart Schaefer [this message]
2016-03-06 23:05 ` Bart Schaefer
2016-03-07 10:44 ` 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=160306142731.ZM3208@torch.brasslantern.com \
--to=schaefer@brasslantern.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).