[master] 45af976 Discontinue words as fixed tokens ('if', 'else' etc) and use ID's instead.

Poul-Henning Kamp phk at varnish-cache.org
Mon Feb 11 13:43:31 CET 2013


commit 45af9764189ec55f0626a44ff64df7bef5d87d41
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 11 12:42:29 2013 +0000

    Discontinue words as fixed tokens ('if', 'else' etc) and use ID's instead.
    
    Fixes #1259

diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index 6fe35fb..7bc0b05 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -84,9 +84,9 @@ varnish v1 -errvcl {Only http header variables can be unset.} {
 	sub vcl_fetch { unset beresp.do_gzip; }
 }
 
-varnish v1 -errvcl {Unknown token 'if' when looking for STRING} {
+varnish v1 -errvcl {Unknown token '<<' when looking for STRING} {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv { ban (if); }
+	sub vcl_recv { ban (<<); }
 }
 
 varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
@@ -104,7 +104,7 @@ varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
 	sub vcl_recv { kluf ; }
 }
 
-varnish v1 -errvcl {Unknown token 'if' when looking for STRING_LIST} {
+varnish v1 -errvcl {Unknown token '<<' when looking for STRING_LIST} {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_error { synthetic if "foo"; }
+	sub vcl_error { synthetic << "foo"; }
 }
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 2064b82..a12f296 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -62,11 +62,6 @@ tokens = {
 	"T_MUL":	"*=",
 	"T_DIV":	"/=",
 	"T_NOMATCH":	"!~",
-	"T_INCLUDE":	"include",
-	"T_IF":		"if",
-	"T_ELSEIF":	"elseif",
-	"T_ELSIF":	"elsif",
-	"T_ELSE":	"else",
 
 	# Single char tokens, for convenience on one line
 	None:		"{}()*+-/%><=;!&.|~,",
diff --git a/lib/libvcl/vcc_compile.c b/lib/libvcl/vcc_compile.c
index 318c1b9..e585e67 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -435,7 +435,7 @@ vcc_resolve_includes(struct vcc *tl)
 	struct source *sp;
 
 	VTAILQ_FOREACH(t, &tl->tokens, list) {
-		if (t->tok != T_INCLUDE)
+		if (t->tok != ID || !vcc_IdIs(t, "include"))
 			continue;
 
 		t1 = VTAILQ_NEXT(t, list);
diff --git a/lib/libvcl/vcc_parse.c b/lib/libvcl/vcc_parse.c
index da50811..f656cbd 100644
--- a/lib/libvcl/vcc_parse.c
+++ b/lib/libvcl/vcc_parse.c
@@ -84,37 +84,48 @@ static void
 vcc_IfStmt(struct vcc *tl)
 {
 
-	SkipToken(tl, T_IF);
+	SkipToken(tl, ID);
 	Fb(tl, 1, "if ");
 	vcc_Conditional(tl);
 	ERRCHK(tl);
 	L(tl, vcc_Compound(tl));
 	ERRCHK(tl);
-	while (1) {
-		switch (tl->t->tok) {
-		case T_ELSE:
+	while (tl->t->tok == ID) {
+		if (vcc_IdIs(tl->t, "else")) {
 			vcc_NextToken(tl);
-			if (tl->t->tok != T_IF) {
+			if (tl->t->tok == '{') {
 				Fb(tl, 1, "else\n");
 				L(tl, vcc_Compound(tl));
 				ERRCHK(tl);
 				return;
 			}
-			/* FALLTHROUGH */
-		case T_ELSEIF:
-		case T_ELSIF:
+			if (tl->t->tok != ID || !vcc_IdIs(tl->t, "if")) {
+				VSB_printf(tl->sb,
+				    "'else' must be followed by 'if' or '{'\n");
+				vcc_ErrWhere(tl, tl->t);
+				return;
+			}
+			Fb(tl, 1, "else if ");
+			vcc_NextToken(tl);
+			vcc_Conditional(tl);
+			ERRCHK(tl);
+			L(tl, vcc_Compound(tl));
+			ERRCHK(tl);
+			
+		} else if (vcc_IdIs(tl->t, "elseif") ||
+		     vcc_IdIs(tl->t, "elsif") ||
+		     vcc_IdIs(tl->t, "elif")) {
 			Fb(tl, 1, "else if ");
 			vcc_NextToken(tl);
 			vcc_Conditional(tl);
 			ERRCHK(tl);
 			L(tl, vcc_Compound(tl));
 			ERRCHK(tl);
+		} else {
 			break;
-		default:
-			C(tl, ";");
-			return;
 		}
 	}
+	C(tl, ";");
 }
 
 /*--------------------------------------------------------------------
@@ -144,9 +155,6 @@ vcc_Compound(struct vcc *tl)
 		case '{':
 			vcc_Compound(tl);
 			break;
-		case T_IF:
-			vcc_IfStmt(tl);
-			break;
 		case '}':
 			vcc_NextToken(tl);
 			tl->indent -= INDENT;
@@ -170,11 +178,16 @@ vcc_Compound(struct vcc *tl)
 			tl->err = 1;
 			return;
 		case ID:
-			i = vcc_ParseAction(tl);
-			ERRCHK(tl);
-			if (i) {
-				SkipToken(tl, ';');
+			if (vcc_IdIs(tl->t, "if")) {
+				vcc_IfStmt(tl);
 				break;
+			} else {
+				i = vcc_ParseAction(tl);
+				ERRCHK(tl);
+				if (i) {
+					SkipToken(tl, ';');
+					break;
+				}
 			}
 			/* FALLTHROUGH */
 		default:



More information about the varnish-commit mailing list