zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: <zsh-workers@zsh.org>
Subject: Re: Parse error (lack thereof) on incomplete loops
Date: Thu, 4 Oct 2018 17:31:56 +0100	[thread overview]
Message-ID: <20181004163158eucas1p234a045be013b5463d8db44314ed217dc~adN28lJmq0822408224eucas1p2F@eucas1p2.samsung.com> (raw)
In-Reply-To: <CAH+w=7awbwDuX2RXcB7pK6Hhbi8fjs=NvwkTAEGmY7gvNpLCqA@mail.gmail.com>

On Thu, 2018-10-04 at 08:49 -0700, Bart Schaefer wrote:
> This went by in a zsh-users thread so it may have been missed:

Not sure who the additional audience is...

> % { while false
> cursh while> }
> %
> 
> This indicates a parsing problem in 5.6, because in 5.0:
> 
> % { while false
> cursh while> }
> zsh: parse error near `}'

It affects for, repeat, until and if, too, and isn't hard to turn back
into a parse error.  Patch attached, though I'm not going to apply it
at
the moment.

However, I'm very far from convinced this is actually a bug.  If you
turn off SHORT_LOOPS you'll find you get the error back; the
alternative loop syntax is defined in such a woolly fashion perhaps you
actually can get away with this.  The short-loop user is probably
primed
to notice such things as that there's no following command so it'll
just
do nothing.

I'm therefore inclined to leave it alone since the SHORT_LOOPS user
(Marc) is perfectly happy with it and a lot of us avoid the alternative
syntax like the plague.

diff --git a/Src/parse.c b/Src/parse.c
index 83383f1..a96cdcb 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -446,12 +446,17 @@ ecstrcode(char *s)
         par_list(C); \
         if (eu == ecused) ecadd(WCB_END()); \
     } while (0)
-#define par_save_list1(C) \
-    do { \
-        int eu = ecused; \
-        par_list1(C); \
-        if (eu == ecused) ecadd(WCB_END()); \
-    } while (0)
+
+/**/
+static int
+par_save_list1(int *cmplx)
+{
+    int eu = ecused;
+    int ret = par_list1(cmplx);
+    if (eu == ecused)
+	ecadd(WCB_END());
+    return ret;
+}
 
 
 /**/
@@ -766,7 +771,7 @@ par_list(int *cmplx)
 }
 
 /**/
-static void
+static int
 par_list1(int *cmplx)
 {
     int p = ecadd(0), c = 0;
@@ -774,8 +779,11 @@ par_list1(int *cmplx)
     if (par_sublist(&c)) {
 	set_list_code(p, (Z_SYNC | Z_END), c);
 	*cmplx |= c;
-    } else
+	return 1;
+    } else {
 	ecused--;
+	return 0;
+    }
 }
 
 /*
@@ -1151,8 +1159,8 @@ par_for(int *cmplx)
 	zshlex();
     } else if (unset(SHORTLOOPS)) {
 	YYERRORV(oecused);
-    } else
-	par_save_list1(cmplx);
+    } else if (!par_save_list1(cmplx))
+	YYERRORV(oecused);
 
     ecbuf[p] = (sel ?
 		WCB_SELECT(type, ecused - 1 - p) :
@@ -1439,7 +1447,8 @@ par_if(int *cmplx)
 	} else {
 	    cmdpop();
 	    cmdpush(nc);
-	    par_save_list1(cmplx);
+	    if (!par_save_list1(cmplx))
+		YYERRORV(oecused);
 	    ecbuf[pp] = WCB_IF(type, ecused - 1 - pp);
 	    incmdpos = 1;
 	    break;
@@ -1512,8 +1521,8 @@ par_while(int *cmplx)
 	zshlex();
     } else if (unset(SHORTLOOPS)) {
 	YYERRORV(oecused);
-    } else
-	par_save_list1(cmplx);
+    } else if (!par_save_list1(cmplx))
+	YYERRORV(oecused);
 
     ecbuf[p] = WCB_WHILE(type, ecused - 1 - p);
 }
@@ -1561,8 +1570,8 @@ par_repeat(int *cmplx)
 	zshlex();
     } else if (unset(SHORTLOOPS)) {
 	YYERRORV(oecused);
-    } else
-	par_save_list1(cmplx);
+    } else if (!par_save_list1(cmplx))
+	YYERRORV(oecused);
 
     ecbuf[p] = WCB_REPEAT(ecused - 1 - p);
 }



  reply	other threads:[~2018-10-04 16:32 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 [this message]
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
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='20181004163158eucas1p234a045be013b5463d8db44314ed217dc~adN28lJmq0822408224eucas1p2F@eucas1p2.samsung.com' \
    --to=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).