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])) {
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;
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] = "--";
vcl_tnames[T_NEQ] = "!=";
vcl_tnames[T_SHL] = "<<";
vcl_tnames[T_SHR] = ">>";
- vcl_tnames[T_SUB] = "sub";
vcl_tnames[VAR] = "VAR";
}
* 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);
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);