]> err.no Git - varnish/commitdiff
Redo toplevel parser to use table.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Jul 2008 18:21:06 +0000 (18:21 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Jul 2008 18:21:06 +0000 (18:21 +0000)
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
varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
varnish-cache/lib/libvcl/vcc_parse.c
varnish-cache/lib/libvcl/vcc_token_defs.h

index 237622e0ad81983c1050df0e2c6ecc7586ab66d1..85b715f1292688fbd4d6edb5b52ef4a993cc13dd 100644 (file)
@@ -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";
 }
 
index 2e1551a01f29fd5240b2c806e3199b322f2caad6..2362f2c365df02cb6adadf9e9aa2411cea2c8b51 100755 (executable)
@@ -69,10 +69,6 @@ set keywords {
        include 
 
        if else elseif elsif
-
-       sub
-
-       acl
 }
 
 # Non-word tokens
index 5861dbb5d60e77e1abd20919bb0e50525d5bd7ea..69f88853453a6d23b7ffc6512cb4c22b40e939f6 100644 (file)
@@ -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);
index a45dc0b694fdfa55054996f62a9068e4ee953bfd..d417655a918558eafac2e6c495fc91accacaf97e 100644 (file)
 #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