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.} { ...@@ -84,9 +84,9 @@ varnish v1 -errvcl {Only http header variables can be unset.} {
sub vcl_fetch { unset beresp.do_gzip; } 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"; } backend b { .host = "127.0.0.1"; }
sub vcl_recv { ban (if); } sub vcl_recv { ban (<<); }
} }
varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} { varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
...@@ -104,7 +104,7 @@ varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} { ...@@ -104,7 +104,7 @@ varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
sub vcl_recv { kluf ; } 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"; } backend b { .host = "127.0.0.1"; }
sub vcl_error { synthetic if "foo"; } sub vcl_error { synthetic << "foo"; }
} }
...@@ -62,11 +62,6 @@ tokens = { ...@@ -62,11 +62,6 @@ tokens = {
"T_MUL": "*=", "T_MUL": "*=",
"T_DIV": "/=", "T_DIV": "/=",
"T_NOMATCH": "!~", "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 # Single char tokens, for convenience on one line
None: "{}()*+-/%><=;!&.|~,", None: "{}()*+-/%><=;!&.|~,",
......
...@@ -435,7 +435,7 @@ vcc_resolve_includes(struct vcc *tl) ...@@ -435,7 +435,7 @@ vcc_resolve_includes(struct vcc *tl)
struct source *sp; struct source *sp;
VTAILQ_FOREACH(t, &tl->tokens, list) { VTAILQ_FOREACH(t, &tl->tokens, list) {
if (t->tok != T_INCLUDE) if (t->tok != ID || !vcc_IdIs(t, "include"))
continue; continue;
t1 = VTAILQ_NEXT(t, list); t1 = VTAILQ_NEXT(t, list);
......
...@@ -84,37 +84,48 @@ static void ...@@ -84,37 +84,48 @@ static void
vcc_IfStmt(struct vcc *tl) vcc_IfStmt(struct vcc *tl)
{ {
SkipToken(tl, T_IF); SkipToken(tl, ID);
Fb(tl, 1, "if "); Fb(tl, 1, "if ");
vcc_Conditional(tl); vcc_Conditional(tl);
ERRCHK(tl); ERRCHK(tl);
L(tl, vcc_Compound(tl)); L(tl, vcc_Compound(tl));
ERRCHK(tl); ERRCHK(tl);
while (1) { while (tl->t->tok == ID) {
switch (tl->t->tok) { if (vcc_IdIs(tl->t, "else")) {
case T_ELSE:
vcc_NextToken(tl); vcc_NextToken(tl);
if (tl->t->tok != T_IF) { if (tl->t->tok == '{') {
Fb(tl, 1, "else\n"); Fb(tl, 1, "else\n");
L(tl, vcc_Compound(tl)); L(tl, vcc_Compound(tl));
ERRCHK(tl); ERRCHK(tl);
return; return;
} }
/* FALLTHROUGH */ if (tl->t->tok != ID || !vcc_IdIs(tl->t, "if")) {
case T_ELSEIF: VSB_printf(tl->sb,
case T_ELSIF: "'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 "); Fb(tl, 1, "else if ");
vcc_NextToken(tl); vcc_NextToken(tl);
vcc_Conditional(tl); vcc_Conditional(tl);
ERRCHK(tl); ERRCHK(tl);
L(tl, vcc_Compound(tl)); L(tl, vcc_Compound(tl));
ERRCHK(tl); ERRCHK(tl);
} else {
break; break;
default:
C(tl, ";");
return;
} }
} }
C(tl, ";");
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
...@@ -144,9 +155,6 @@ vcc_Compound(struct vcc *tl) ...@@ -144,9 +155,6 @@ vcc_Compound(struct vcc *tl)
case '{': case '{':
vcc_Compound(tl); vcc_Compound(tl);
break; break;
case T_IF:
vcc_IfStmt(tl);
break;
case '}': case '}':
vcc_NextToken(tl); vcc_NextToken(tl);
tl->indent -= INDENT; tl->indent -= INDENT;
...@@ -170,11 +178,16 @@ vcc_Compound(struct vcc *tl) ...@@ -170,11 +178,16 @@ vcc_Compound(struct vcc *tl)
tl->err = 1; tl->err = 1;
return; return;
case ID: case ID:
i = vcc_ParseAction(tl); if (vcc_IdIs(tl->t, "if")) {
ERRCHK(tl); vcc_IfStmt(tl);
if (i) {
SkipToken(tl, ';');
break; break;
} else {
i = vcc_ParseAction(tl);
ERRCHK(tl);
if (i) {
SkipToken(tl, ';');
break;
}
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
default: 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