]> err.no Git - varnish/commitdiff
Introduce table based search for actions, and make "set" the first one.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 1 Apr 2007 08:48:08 +0000 (08:48 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 1 Apr 2007 08:48:08 +0000 (08:48 +0000)
This eliminates the need to have the identifier "set" be its own token
rather than being a simple ID.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1297 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/lib/libvcl/vcc_action.c
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 bba28b62e97190473b0a3ae06c9d3a5621c361cc..822795df1b1644a1d7c2d70f3293918b1f1d8878 100644 (file)
 
 /*--------------------------------------------------------------------*/
 
+static void
+parse_set(struct tokenlist *tl)
+{
+       struct var *vp;
+       struct token *at, *vt;
+
+       ExpectErr(tl, VAR);
+       vt = tl->t;
+       vp = FindVar(tl, tl->t, vcc_vars);
+       ERRCHK(tl);
+       assert(vp != NULL);
+       Fb(tl, 1, "%s", vp->lname);
+       vcc_NextToken(tl);
+       switch (vp->fmt) {
+       case INT:
+       case SIZE:
+       case RATE:
+       case TIME:
+       case FLOAT:
+               if (tl->t->tok != '=')
+                       Fb(tl, 0, "%s %c ", vp->rname, *tl->t->b);
+               at = tl->t;
+               vcc_NextToken(tl);
+               switch (at->tok) {
+               case T_MUL:
+               case T_DIV:
+                       Fb(tl, 0, "%g", vcc_DoubleVal(tl));
+                       break;
+               case T_INCR:
+               case T_DECR:
+               case '=':
+                       if (vp->fmt == TIME)
+                               vcc_TimeVal(tl);
+                       else if (vp->fmt == SIZE)
+                               vcc_SizeVal(tl);
+                       else if (vp->fmt == RATE)
+                               vcc_RateVal(tl);
+                       else if (vp->fmt == FLOAT)
+                               Fb(tl, 0, "%g", vcc_DoubleVal(tl));
+                       else {
+                               vsb_printf(tl->sb, "Cannot assign this variable type.\n");
+                               vcc_ErrWhere(tl, vt);
+                               return;
+                       }
+                       break;
+               default:
+                       vsb_printf(tl->sb, "Illegal assignment operator.\n");
+                       vcc_ErrWhere(tl, at);
+                       return;
+               }
+               Fb(tl, 0, ");\n");
+               break;
+#if 0  /* XXX: enable if we find a legit use */
+       case IP:
+               if (tl->t->tok == '=') {
+                       vcc_NextToken(tl);
+                       u = vcc_vcc_IpVal(tl);
+                       Fb(tl, 0, "= %uU; /* %u.%u.%u.%u */\n",
+                           u,
+                           (u >> 24) & 0xff,
+                           (u >> 16) & 0xff,
+                           (u >> 8) & 0xff,
+                           u & 0xff);
+                       break;
+               }
+               vsb_printf(tl->sb, "Illegal assignment operator ");
+               vcc_ErrToken(tl, tl->t);
+               vsb_printf(tl->sb,
+                   " only '=' is legal for IP numbers\n");
+               vcc_ErrWhere(tl, tl->t);
+               return;
+#endif
+       case BACKEND:
+               if (tl->t->tok == '=') {
+                       vcc_NextToken(tl);
+                       vcc_AddRef(tl, tl->t, R_BACKEND);
+                       Fb(tl, 0, "VGC_backend_%.*s", PF(tl->t));
+                       vcc_NextToken(tl);
+                       Fb(tl, 0, ");\n");
+                       break;
+               }
+               vsb_printf(tl->sb, "Illegal assignment operator ");
+               vcc_ErrToken(tl, tl->t);
+               vsb_printf(tl->sb,
+                   " only '=' is legal for backend\n");
+               vcc_ErrWhere(tl, tl->t);
+               return;
+       default:
+               vsb_printf(tl->sb,
+                   "Assignments not possible for '%s'\n", vp->name);
+               vcc_ErrWhere(tl, tl->t);
+               return;
+       }
+}
+
+/*--------------------------------------------------------------------*/
+
+typedef action_f(struct tokenlist *tl);
+
+static struct action_table {
+       const char              *name;
+       action_f                *func;
+} action_table[] = {
+       { "set",        parse_set },
+       { NULL,         NULL }
+};
+
+
 void
 vcc_ParseAction(struct tokenlist *tl)
 {
        unsigned a;
-       struct var *vp;
-       struct token *at, *vt;
+       struct token *at;
+       struct action_table *atp;
 
        at = tl->t;
        vcc_NextToken(tl);
+       if (at->tok == ID) {
+               for(atp = action_table; atp->name != NULL; atp++) {
+                       if (vcc_IdIs(at, atp->name)) {
+                               atp->func(tl);
+                               return;
+                       }
+               }
+       }
        switch (at->tok) {
        case T_NO_NEW_CACHE:
                Fb(tl, 1, "VCL_no_new_cache(sp);\n");
@@ -127,95 +243,6 @@ vcc_ParseAction(struct tokenlist *tl)
                Fb(tl, 0, ", %.*s);\n", PF(tl->t));
                vcc_NextToken(tl);
                return;
-       case T_SET:
-               ExpectErr(tl, VAR);
-               vt = tl->t;
-               vp = FindVar(tl, tl->t, vcc_vars);
-               ERRCHK(tl);
-               assert(vp != NULL);
-               Fb(tl, 1, "%s", vp->lname);
-               vcc_NextToken(tl);
-               switch (vp->fmt) {
-               case INT:
-               case SIZE:
-               case RATE:
-               case TIME:
-               case FLOAT:
-                       if (tl->t->tok != '=')
-                               Fb(tl, 0, "%s %c ", vp->rname, *tl->t->b);
-                       at = tl->t;
-                       vcc_NextToken(tl);
-                       switch (at->tok) {
-                       case T_MUL:
-                       case T_DIV:
-                               Fb(tl, 0, "%g", vcc_DoubleVal(tl));
-                               break;
-                       case T_INCR:
-                       case T_DECR:
-                       case '=':
-                               if (vp->fmt == TIME)
-                                       vcc_TimeVal(tl);
-                               else if (vp->fmt == SIZE)
-                                       vcc_SizeVal(tl);
-                               else if (vp->fmt == RATE)
-                                       vcc_RateVal(tl);
-                               else if (vp->fmt == FLOAT)
-                                       Fb(tl, 0, "%g", vcc_DoubleVal(tl));
-                               else {
-                                       vsb_printf(tl->sb, "Cannot assign this variable type.\n");
-                                       vcc_ErrWhere(tl, vt);
-                                       return;
-                               }
-                               break;
-                       default:
-                               vsb_printf(tl->sb, "Illegal assignment operator.\n");
-                               vcc_ErrWhere(tl, at);
-                               return;
-                       }
-                       Fb(tl, 0, ");\n");
-                       break;
-#if 0  /* XXX: enable if we find a legit use */
-               case IP:
-                       if (tl->t->tok == '=') {
-                               vcc_NextToken(tl);
-                               u = vcc_vcc_IpVal(tl);
-                               Fb(tl, 0, "= %uU; /* %u.%u.%u.%u */\n",
-                                   u,
-                                   (u >> 24) & 0xff,
-                                   (u >> 16) & 0xff,
-                                   (u >> 8) & 0xff,
-                                   u & 0xff);
-                               break;
-                       }
-                       vsb_printf(tl->sb, "Illegal assignment operator ");
-                       vcc_ErrToken(tl, tl->t);
-                       vsb_printf(tl->sb,
-                           " only '=' is legal for IP numbers\n");
-                       vcc_ErrWhere(tl, tl->t);
-                       return;
-#endif
-               case BACKEND:
-                       if (tl->t->tok == '=') {
-                               vcc_NextToken(tl);
-                               vcc_AddRef(tl, tl->t, R_BACKEND);
-                               Fb(tl, 0, "VGC_backend_%.*s", PF(tl->t));
-                               vcc_NextToken(tl);
-                               Fb(tl, 0, ");\n");
-                               break;
-                       }
-                       vsb_printf(tl->sb, "Illegal assignment operator ");
-                       vcc_ErrToken(tl, tl->t);
-                       vsb_printf(tl->sb,
-                           " only '=' is legal for backend\n");
-                       vcc_ErrWhere(tl, tl->t);
-                       return;
-               default:
-                       vsb_printf(tl->sb,
-                           "Assignments not possible for '%s'\n", vp->name);
-                       vcc_ErrWhere(tl, tl->t);
-                       return;
-               }
-               return;
        default:
                vsb_printf(tl->sb, "Expected action, 'if' or '}'\n");
                vcc_ErrWhere(tl, at);
index dc8bdf41541c7bd6ac7e9854773a7b722e26159f..70031da6d30b5bd1cb3e8192b0a51a3dc3c82f22 100644 (file)
@@ -317,11 +317,6 @@ vcl_fixed_token(const char *p, const char **q)
                        *q = p + 3;
                        return (T_SUB);
                }
-               if (p[0] == 's' && p[1] == 'e' && p[2] == 't'
-                    && !isvar(p[3])) {
-                       *q = p + 3;
-                       return (T_SET);
-               }
                return (0);
        case '{':
                if (p[0] == '{') {
@@ -419,7 +414,6 @@ vcl_init_tnames(void)
        vcl_tnames[T_PIPE] = "pipe";
        vcl_tnames[T_PROC] = "proc";
        vcl_tnames[T_REWRITE] = "rewrite";
-       vcl_tnames[T_SET] = "set";
        vcl_tnames[T_SHL] = "<<";
        vcl_tnames[T_SHR] = ">>";
        vcl_tnames[T_SUB] = "sub";
index d96274480e6581830a5ac8c2c4f8d7891aeace02..a01bae8a8eec4a3c2bfa5934cf46de42e483206c 100755 (executable)
@@ -74,7 +74,6 @@ set keywords {
        call
        no_cache
        no_new_cache
-       set
        rewrite
        switch_config
 }
index 84e9b960ed6b50b62eab85ede3cd2d74f563ae98..b01052b67c58339b6b30c7d8cf2d593ff0136baa 100644 (file)
@@ -565,7 +565,15 @@ Backend(struct tokenlist *tl)
        while (1) {
                if (tl->t->tok == '}')
                        break;
-               ExpectErr(tl, T_SET);
+               ExpectErr(tl, ID);
+               if (!vcc_IdIs(tl->t, "set")) {
+                       vsb_printf(tl->sb,
+                           "Expected 'set', found ");
+                       vcc_ErrToken(tl, tl->t);
+                       vsb_printf(tl->sb, " at\n");
+                       vcc_ErrWhere(tl, tl->t);
+                       return;
+               }
                vcc_NextToken(tl);
                ExpectErr(tl, VAR);
                vp = FindVar(tl, tl->t, vcc_be_vars);
index 89d3c811c6ef776dc7f5e327bba2e66faadb0bb0..8d91ba28fe70ca4e0a2c3f25c5208c957451738c 100644 (file)
 #define T_CALL 138
 #define T_NO_CACHE 139
 #define T_NO_NEW_CACHE 140
-#define T_SET 141
-#define T_REWRITE 142
-#define T_SWITCH_CONFIG 143
-#define T_ERROR 144
-#define T_LOOKUP 145
-#define T_HASH 146
-#define T_PIPE 147
-#define T_PASS 148
-#define T_FETCH 149
-#define T_INSERT 150
-#define T_DELIVER 151
-#define T_DISCARD 152
-#define T_INC 153
-#define T_DEC 154
-#define T_CAND 155
-#define T_COR 156
-#define T_LEQ 157
-#define T_EQ 158
-#define T_NEQ 159
-#define T_GEQ 160
-#define T_SHR 161
-#define T_SHL 162
-#define T_INCR 163
-#define T_DECR 164
-#define T_MUL 165
-#define T_DIV 166
-#define ID 167
-#define VAR 168
-#define CNUM 169
-#define CSTR 170
-#define EOI 171
-#define METHOD 172
+#define T_REWRITE 141
+#define T_SWITCH_CONFIG 142
+#define T_ERROR 143
+#define T_LOOKUP 144
+#define T_HASH 145
+#define T_PIPE 146
+#define T_PASS 147
+#define T_FETCH 148
+#define T_INSERT 149
+#define T_DELIVER 150
+#define T_DISCARD 151
+#define T_INC 152
+#define T_DEC 153
+#define T_CAND 154
+#define T_COR 155
+#define T_LEQ 156
+#define T_EQ 157
+#define T_NEQ 158
+#define T_GEQ 159
+#define T_SHR 160
+#define T_SHL 161
+#define T_INCR 162
+#define T_DECR 163
+#define T_MUL 164
+#define T_DIV 165
+#define ID 166
+#define VAR 167
+#define CNUM 168
+#define CSTR 169
+#define EOI 170
+#define METHOD 171