about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2014-09-26 14:07:43 +0100
committerPeter Stephenson <pws@zsh.org>2014-09-26 14:07:43 +0100
commitd19d9c1eff7dfe341c8412e310015919ef7729d7 (patch)
tree4f50953e5fb1c48a1baadc122763d98fbaa782d6
parentb9ee56e5b72605553475669117701c659d276f29 (diff)
downloadzsh-d19d9c1eff7dfe341c8412e310015919ef7729d7.tar.gz
zsh-d19d9c1eff7dfe341c8412e310015919ef7729d7.tar.xz
zsh-d19d9c1eff7dfe341c8412e310015919ef7729d7.zip
33242: tokens following if, for, repeat, while aren't in command position
-rw-r--r--ChangeLog4
-rw-r--r--Src/parse.c16
2 files changed, 18 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b494144b0..59789aefc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2014-09-26  Peter Stephenson  <p.stephenson@samsung.com>
 
+	* 33242: Src/parse.c: don't treat tokens immediately following
+	end of shell constructs for, while, repeat, if as being in
+	command position.
+
 	* Wieland Hoffmann: 33252: Completion/Unix/Command/_notmuch:
 	complete more subcommands.
 
diff --git a/Src/parse.c b/Src/parse.c
index 5f1303f1c..3633417fe 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -997,17 +997,20 @@ par_for(int *complex)
 	par_save_list(complex);
 	if (tok != DONE)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (tok == INBRACE) {
 	zshlex();
 	par_save_list(complex);
 	if (tok != OUTBRACE)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (csh || isset(CSHJUNKIELOOPS)) {
 	par_save_list(complex);
 	if (tok != ZEND)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (unset(SHORTLOOPS)) {
 	YYERRORV(oecused);
@@ -1186,9 +1189,12 @@ par_if(int *complex)
     for (;;) {
 	xtok = tok;
 	cmdpush(xtok == IF ? CS_IF : CS_ELIF);
-	zshlex();
-	if (xtok == FI)
+	if (xtok == FI) {
+	    incmdpos = 0;
+	    zshlex();
 	    break;
+	}
+	zshlex();
 	if (xtok == ELSE)
 	    break;
 	while (tok == SEPER)
@@ -1229,6 +1235,7 @@ par_if(int *complex)
 		YYERRORV(oecused);
 	    }
 	    ecbuf[pp] = WCB_IF(type, ecused - 1 - pp);
+	    /* command word (else) allowed to follow immediately */
 	    zshlex();
 	    incmdpos = 1;
 	    if (tok == SEPER)
@@ -1266,6 +1273,7 @@ par_if(int *complex)
 		YYERRORV(oecused);
 	    }
 	}
+	incmdpos = 0;
 	ecbuf[pp] = WCB_IF(WC_IF_ELSE, ecused - 1 - pp);
 	zshlex();
 	cmdpop();
@@ -1296,12 +1304,14 @@ par_while(int *complex)
 	par_save_list(complex);
 	if (tok != DONE)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (tok == INBRACE) {
 	zshlex();
 	par_save_list(complex);
 	if (tok != OUTBRACE)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (isset(CSHJUNKIELOOPS)) {
 	par_save_list(complex);
@@ -1340,12 +1350,14 @@ par_repeat(int *complex)
 	par_save_list(complex);
 	if (tok != DONE)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (tok == INBRACE) {
 	zshlex();
 	par_save_list(complex);
 	if (tok != OUTBRACE)
 	    YYERRORV(oecused);
+	incmdpos = 0;
 	zshlex();
     } else if (isset(CSHJUNKIELOOPS)) {
 	par_save_list(complex);