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