* Multi-line conditionals (Re: Sourcing bash completion files)
[not found] ` <5684E4B2.8000100@gmx.com>
@ 2015-12-31 19:31 ` Bart Schaefer
2015-12-31 22:12 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Bart Schaefer @ 2015-12-31 19:31 UTC (permalink / raw)
To: zsh-workers
On Dec 31, 3:17am, Eric Cook wrote:
}
} that error is due to [[ not being able to span across lines.
Hmm, I'm relatively sure [[ is supposed to be able to span lines.
There are a number of places where
while (tok == SEPER)
condlex();
appears, but apparently not enough of them. Also it's a bit tricky
because of course [ ... ] mustn't span lines.
diff --git a/Src/parse.c b/Src/parse.c
index 83ba396..6949b13 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2348,7 +2348,9 @@ par_cond_2(void)
* We fall through here on any non-numeric infix operator
* or any other time there are at least two arguments.
*/
- }
+ } else
+ while (tok == SEPER)
+ condlex();
if (tok == BANG) {
/*
* In "test" compatibility mode, "! -a ..." and "! -o ..."
@@ -2385,7 +2387,7 @@ par_cond_2(void)
/* Check first argument for [[ STRING ]] re-interpretation */
if (s1 /* tok != DOUTBRACK && tok != DAMPER && tok != DBAR */
&& tok != LEXERR && (!dble || n_testargs)) {
- condlex();
+ do condlex(); while (tok == SEPER && condlex != testlex);
return par_cond_double(dupstring("-n"), s1);
} else
YYERROR(ecused);
@@ -2398,14 +2400,16 @@ par_cond_2(void)
* checked it does have a string representation).
*/
tok = STRING;
- }
+ } else
+ while (tok == SEPER && condlex != testlex)
+ condlex();
if (tok == INANG || tok == OUTANG) {
enum lextok xtok = tok;
- condlex();
+ do condlex(); while (tok == SEPER && condlex != testlex);
if (tok != STRING)
YYERROR(ecused);
s3 = tokstr;
- condlex();
+ do condlex(); while (tok == SEPER && condlex != testlex);
ecadd(WCB_COND((xtok == INANG ? COND_STRLT : COND_STRGTR), 0));
ecstr(s1);
ecstr(s3);
@@ -2428,11 +2432,11 @@ par_cond_2(void)
if (!n_testargs)
dble = (s2 && *s2 == '-' && !s2[2]);
incond++; /* parentheses do globbing */
- condlex();
+ do condlex(); while (tok == SEPER && condlex != testlex);
incond--; /* parentheses do grouping */
if (tok == STRING && !dble) {
s3 = tokstr;
- condlex();
+ do condlex(); while (tok == SEPER && condlex != testlex);
if (tok == STRING) {
LinkList l = newlinklist();
@@ -2441,7 +2445,7 @@ par_cond_2(void)
while (tok == STRING) {
addlinknode(l, tokstr);
- condlex();
+ do condlex(); while (tok == SEPER && condlex != testlex);
}
return par_cond_multi(s1, l);
} else
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Multi-line conditionals (Re: Sourcing bash completion files)
2015-12-31 19:31 ` Multi-line conditionals (Re: Sourcing bash completion files) Bart Schaefer
@ 2015-12-31 22:12 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2015-12-31 22:12 UTC (permalink / raw)
To: zsh-workers
On Dec 31, 11:31am, Bart Schaefer wrote:
}
} There are a number of places where
}
} while (tok == SEPER)
} condlex();
}
} appears, but apparently not enough of them. Also it's a bit tricky
} because of course [ ... ] mustn't span lines.
Also it should be an error to use ';' as the separator here. This patch
applies on top of the previous one.
There probably ought to be (and perhaps is) a cleaner way to handle
this than testing *zshlextext, because we did know at one point that
tok == NEWLINE, but that was clobbered by assigning tok = SEPER and
tokstr has never been set.
diff --git a/Src/parse.c b/Src/parse.c
index 6949b13..4829e3a 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2252,6 +2252,8 @@ void (*condlex) _((void)) = zshlex;
* cond : cond_1 { SEPER } [ DBAR { SEPER } cond ]
*/
+#define COND_SEP() (tok == SEPER && condlex != testlex && *zshlextext != ';')
+
/**/
static int
par_cond(void)
@@ -2259,11 +2261,11 @@ par_cond(void)
int p = ecused, r;
r = par_cond_1();
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
if (tok == DBAR) {
condlex();
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
ecispace(p, 1);
par_cond();
@@ -2284,11 +2286,11 @@ par_cond_1(void)
int r, p = ecused;
r = par_cond_2();
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
if (tok == DAMPER) {
condlex();
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
ecispace(p, 1);
par_cond_1();
@@ -2349,7 +2351,7 @@ par_cond_2(void)
* or any other time there are at least two arguments.
*/
} else
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
if (tok == BANG) {
/*
@@ -2368,10 +2370,10 @@ par_cond_2(void)
int r;
condlex();
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
r = par_cond();
- while (tok == SEPER)
+ while (COND_SEP())
condlex();
if (tok != OUTPAR)
YYERROR(ecused);
@@ -2387,7 +2389,7 @@ par_cond_2(void)
/* Check first argument for [[ STRING ]] re-interpretation */
if (s1 /* tok != DOUTBRACK && tok != DAMPER && tok != DBAR */
&& tok != LEXERR && (!dble || n_testargs)) {
- do condlex(); while (tok == SEPER && condlex != testlex);
+ do condlex(); while (COND_SEP());
return par_cond_double(dupstring("-n"), s1);
} else
YYERROR(ecused);
@@ -2401,15 +2403,15 @@ par_cond_2(void)
*/
tok = STRING;
} else
- while (tok == SEPER && condlex != testlex)
+ while (COND_SEP())
condlex();
if (tok == INANG || tok == OUTANG) {
enum lextok xtok = tok;
- do condlex(); while (tok == SEPER && condlex != testlex);
+ do condlex(); while (COND_SEP());
if (tok != STRING)
YYERROR(ecused);
s3 = tokstr;
- do condlex(); while (tok == SEPER && condlex != testlex);
+ do condlex(); while (COND_SEP());
ecadd(WCB_COND((xtok == INANG ? COND_STRLT : COND_STRGTR), 0));
ecstr(s1);
ecstr(s3);
@@ -2432,11 +2434,11 @@ par_cond_2(void)
if (!n_testargs)
dble = (s2 && *s2 == '-' && !s2[2]);
incond++; /* parentheses do globbing */
- do condlex(); while (tok == SEPER && condlex != testlex);
+ do condlex(); while (COND_SEP());
incond--; /* parentheses do grouping */
if (tok == STRING && !dble) {
s3 = tokstr;
- do condlex(); while (tok == SEPER && condlex != testlex);
+ do condlex(); while (COND_SEP());
if (tok == STRING) {
LinkList l = newlinklist();
@@ -2445,7 +2447,7 @@ par_cond_2(void)
while (tok == STRING) {
addlinknode(l, tokstr);
- do condlex(); while (tok == SEPER && condlex != testlex);
+ do condlex(); while (COND_SEP());
}
return par_cond_multi(s1, l);
} else
--
Barton E. Schaefer
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-12-31 22:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20151230232254.GC12070@drscott.swordarmor.fr>
[not found] ` <151230173658.ZM9725@torch.brasslantern.com>
[not found] ` <5684E4B2.8000100@gmx.com>
2015-12-31 19:31 ` Multi-line conditionals (Re: Sourcing bash completion files) Bart Schaefer
2015-12-31 22:12 ` Bart Schaefer
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).