From 506d407ec01200b4aeb911f6380efe5441d7cf21 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 7 Jul 2008 18:21:06 +0000 Subject: [PATCH] Redo toplevel parser to use table. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2886 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvcl/vcc_fixed_token.c | 16 ------- .../lib/libvcl/vcc_gen_fixed_token.tcl | 4 -- varnish-cache/lib/libvcl/vcc_parse.c | 41 ++++++++++++------ varnish-cache/lib/libvcl/vcc_token_defs.h | 42 +++++++++---------- 4 files changed, 48 insertions(+), 55 deletions(-) diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 237622e0..85b715f1 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -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"; } diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index 2e1551a0..2362f2c3 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -69,10 +69,6 @@ set keywords { include if else elseif elsif - - sub - - acl } # Non-word tokens diff --git a/varnish-cache/lib/libvcl/vcc_parse.c b/varnish-cache/lib/libvcl/vcc_parse.c index 5861dbb5..69f88853 100644 --- a/varnish-cache/lib/libvcl/vcc_parse.c +++ b/varnish-cache/lib/libvcl/vcc_parse.c @@ -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); diff --git a/varnish-cache/lib/libvcl/vcc_token_defs.h b/varnish-cache/lib/libvcl/vcc_token_defs.h index a45dc0b6..d417655a 100644 --- a/varnish-cache/lib/libvcl/vcc_token_defs.h +++ b/varnish-cache/lib/libvcl/vcc_token_defs.h @@ -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 -- 2.39.5