r2886 - trunk/varnish-cache/lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Mon Jul 7 20:21:06 CEST 2008


Author: phk
Date: 2008-07-07 20:21:06 +0200 (Mon, 07 Jul 2008)
New Revision: 2886

Modified:
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
   trunk/varnish-cache/lib/libvcl/vcc_parse.c
   trunk/varnish-cache/lib/libvcl/vcc_token_defs.h
Log:
Redo toplevel parser to use table.



Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-07-07 18:02:06 UTC (rev 2885)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-07-07 18:21:06 UTC (rev 2886)
@@ -159,13 +159,6 @@
 			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 @@
 			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_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_tnames[T_NEQ] = "!=";
 	vcl_tnames[T_SHL] = "<<";
 	vcl_tnames[T_SHR] = ">>";
-	vcl_tnames[T_SUB] = "sub";
 	vcl_tnames[VAR] = "VAR";
 }
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2008-07-07 18:02:06 UTC (rev 2885)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2008-07-07 18:21:06 UTC (rev 2886)
@@ -69,10 +69,6 @@
 	include 
 
 	if else elseif elsif
-
-	sub
-
-	acl
 }
 
 # Non-word tokens

Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c	2008-07-07 18:02:06 UTC (rev 2885)
+++ trunk/varnish-cache/lib/libvcl/vcc_parse.c	2008-07-07 18:21:06 UTC (rev 2886)
@@ -552,19 +552,27 @@
  *	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 @@
 		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);

Modified: trunk/varnish-cache/lib/libvcl/vcc_token_defs.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_token_defs.h	2008-07-07 18:02:06 UTC (rev 2885)
+++ trunk/varnish-cache/lib/libvcl/vcc_token_defs.h	2008-07-07 18:21:06 UTC (rev 2886)
@@ -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




More information about the varnish-commit mailing list