Commit 45af9764 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Discontinue words as fixed tokens ('if', 'else' etc) and use ID's instead.

Fixes #1259
parent 8a73d957
......@@ -84,9 +84,9 @@ varnish v1 -errvcl {Only http header variables can be unset.} {
sub vcl_fetch { unset beresp.do_gzip; }
}
varnish v1 -errvcl {Unknown token 'if' when looking for STRING} {
varnish v1 -errvcl {Unknown token '<<' when looking for STRING} {
backend b { .host = "127.0.0.1"; }
sub vcl_recv { ban (if); }
sub vcl_recv { ban (<<); }
}
varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
......@@ -104,7 +104,7 @@ varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
sub vcl_recv { kluf ; }
}
varnish v1 -errvcl {Unknown token 'if' when looking for STRING_LIST} {
varnish v1 -errvcl {Unknown token '<<' when looking for STRING_LIST} {
backend b { .host = "127.0.0.1"; }
sub vcl_error { synthetic if "foo"; }
sub vcl_error { synthetic << "foo"; }
}
......@@ -62,11 +62,6 @@ tokens = {
"T_MUL": "*=",
"T_DIV": "/=",
"T_NOMATCH": "!~",
"T_INCLUDE": "include",
"T_IF": "if",
"T_ELSEIF": "elseif",
"T_ELSIF": "elsif",
"T_ELSE": "else",
# Single char tokens, for convenience on one line
None: "{}()*+-/%><=;!&.|~,",
......
......@@ -435,7 +435,7 @@ vcc_resolve_includes(struct vcc *tl)
struct source *sp;
VTAILQ_FOREACH(t, &tl->tokens, list) {
if (t->tok != T_INCLUDE)
if (t->tok != ID || !vcc_IdIs(t, "include"))
continue;
t1 = VTAILQ_NEXT(t, list);
......
......@@ -84,37 +84,48 @@ static void
vcc_IfStmt(struct vcc *tl)
{
SkipToken(tl, T_IF);
SkipToken(tl, ID);
Fb(tl, 1, "if ");
vcc_Conditional(tl);
ERRCHK(tl);
L(tl, vcc_Compound(tl));
ERRCHK(tl);
while (1) {
switch (tl->t->tok) {
case T_ELSE:
while (tl->t->tok == ID) {
if (vcc_IdIs(tl->t, "else")) {
vcc_NextToken(tl);
if (tl->t->tok != T_IF) {
if (tl->t->tok == '{') {
Fb(tl, 1, "else\n");
L(tl, vcc_Compound(tl));
ERRCHK(tl);
return;
}
/* FALLTHROUGH */
case T_ELSEIF:
case T_ELSIF:
if (tl->t->tok != ID || !vcc_IdIs(tl->t, "if")) {
VSB_printf(tl->sb,
"'else' must be followed by 'if' or '{'\n");
vcc_ErrWhere(tl, tl->t);
return;
}
Fb(tl, 1, "else if ");
vcc_NextToken(tl);
vcc_Conditional(tl);
ERRCHK(tl);
L(tl, vcc_Compound(tl));
ERRCHK(tl);
} else if (vcc_IdIs(tl->t, "elseif") ||
vcc_IdIs(tl->t, "elsif") ||
vcc_IdIs(tl->t, "elif")) {
Fb(tl, 1, "else if ");
vcc_NextToken(tl);
vcc_Conditional(tl);
ERRCHK(tl);
L(tl, vcc_Compound(tl));
ERRCHK(tl);
} else {
break;
default:
C(tl, ";");
return;
}
}
C(tl, ";");
}
/*--------------------------------------------------------------------
......@@ -144,9 +155,6 @@ vcc_Compound(struct vcc *tl)
case '{':
vcc_Compound(tl);
break;
case T_IF:
vcc_IfStmt(tl);
break;
case '}':
vcc_NextToken(tl);
tl->indent -= INDENT;
......@@ -170,11 +178,16 @@ vcc_Compound(struct vcc *tl)
tl->err = 1;
return;
case ID:
i = vcc_ParseAction(tl);
ERRCHK(tl);
if (i) {
SkipToken(tl, ';');
if (vcc_IdIs(tl->t, "if")) {
vcc_IfStmt(tl);
break;
} else {
i = vcc_ParseAction(tl);
ERRCHK(tl);
if (i) {
SkipToken(tl, ';');
break;
}
}
/* FALLTHROUGH */
default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment