Commit fceb93d4 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Redo toplevel parser to use table.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2886 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e5054a03
......@@ -159,13 +159,6 @@ vcl_fixed_token(const char *p, const char **q)
return ('>');
}
return (0);
case 'a':
if (p[0] == 'a' && p[1] == 'c' && p[2] == 'l'
&& !isvar(p[3])) {
*q = p + 3;
return (T_ACL);
}
return (0);
case 'e':
if (p[0] == 'e' && p[1] == 'l' && p[2] == 's' &&
p[3] == 'i' && p[4] == 'f' && !isvar(p[5])) {
......@@ -196,13 +189,6 @@ vcl_fixed_token(const char *p, const char **q)
return (T_IF);
}
return (0);
case 's':
if (p[0] == 's' && p[1] == 'u' && p[2] == 'b'
&& !isvar(p[3])) {
*q = p + 3;
return (T_SUB);
}
return (0);
case '{':
if (p[0] == '{') {
*q = p + 1;
......@@ -265,7 +251,6 @@ vcl_init_tnames(void)
vcl_tnames[CSTR] = "CSTR";
vcl_tnames[EOI] = "EOI";
vcl_tnames[ID] = "ID";
vcl_tnames[T_ACL] = "acl";
vcl_tnames[T_CAND] = "&&";
vcl_tnames[T_COR] = "||";
vcl_tnames[T_DEC] = "--";
......@@ -285,7 +270,6 @@ vcl_init_tnames(void)
vcl_tnames[T_NEQ] = "!=";
vcl_tnames[T_SHL] = "<<";
vcl_tnames[T_SHR] = ">>";
vcl_tnames[T_SUB] = "sub";
vcl_tnames[VAR] = "VAR";
}
......
......@@ -69,10 +69,6 @@ set keywords {
include
if else elseif elsif
sub
acl
}
# Non-word tokens
......
......@@ -552,19 +552,27 @@ Function(struct tokenlist *tl)
* End of input
*/
typedef void parse_f(struct tokenlist *tl);
static struct toplev {
const char *name;
parse_f *func;
} toplev[] = {
{ "acl", vcc_Acl },
{ "sub", Function },
{ "backend", vcc_ParseBackend },
{ "director", vcc_ParseDirector },
{ NULL, NULL }
};
void
vcc_Parse(struct tokenlist *tl)
{
struct toplev *tp;
while (tl->t->tok != EOI) {
ERRCHK(tl);
switch (tl->t->tok) {
case T_ACL:
vcc_Acl(tl);
break;
case T_SUB:
Function(tl);
break;
case CSRC:
Fc(tl, 0, "%.*s\n",
tl->t->e - (tl->t->b + 4), tl->t->b + 2);
......@@ -573,18 +581,25 @@ vcc_Parse(struct tokenlist *tl)
case EOI:
break;
case ID:
if (vcc_IdIs(tl->t, "backend")) {
vcc_ParseBackend(tl);
for (tp = toplev; tp->name != NULL; tp++) {
if (!vcc_IdIs(tl->t, tp->name))
continue;
tp->func(tl);
break;
}
if (vcc_IdIs(tl->t, "director")) {
vcc_ParseDirector(tl);
if (tp->name != NULL)
break;
}
/* FALLTHROUGH */
default:
vsb_printf(tl->sb,
"Expected 'acl', 'sub' or 'backend', found ");
vsb_printf(tl->sb, "Expected one of\n\t");
for (tp = toplev; tp->name != NULL; tp++) {
if (tp[1].name == NULL)
vsb_printf(tl->sb, " or ");
vsb_printf(tl->sb, "'%s'", tp->name);
if (tp[1].name != NULL)
vsb_printf(tl->sb, ", ");
}
vsb_printf(tl->sb, "\nFound: ");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
......
......@@ -12,25 +12,23 @@
#define T_ELSE 130
#define T_ELSEIF 131
#define T_ELSIF 132
#define T_SUB 133
#define T_ACL 134
#define T_INC 135
#define T_DEC 136
#define T_CAND 137
#define T_COR 138
#define T_LEQ 139
#define T_EQ 140
#define T_NEQ 141
#define T_GEQ 142
#define T_SHR 143
#define T_SHL 144
#define T_INCR 145
#define T_DECR 146
#define T_MUL 147
#define T_DIV 148
#define ID 149
#define VAR 150
#define CNUM 151
#define CSTR 152
#define EOI 153
#define CSRC 154
#define T_INC 133
#define T_DEC 134
#define T_CAND 135
#define T_COR 136
#define T_LEQ 137
#define T_EQ 138
#define T_NEQ 139
#define T_GEQ 140
#define T_SHR 141
#define T_SHL 142
#define T_INCR 143
#define T_DECR 144
#define T_MUL 145
#define T_DIV 146
#define ID 147
#define VAR 148
#define CNUM 149
#define CSTR 150
#define EOI 151
#define CSRC 152
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