[3.0] ac7ced6 Allow backends to start with if, include or else

Federico G. Schwindt fgsch at lodoss.net
Wed Mar 5 17:59:45 CET 2014


commit ac7ced62b57e050a678a179d0701afdb83238366
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Wed Mar 5 15:58:32 2014 +0000

    Allow backends to start with if, include or else
    
    Cherry pick changes from master to allow it.
    
    Fixes: #1439

diff --git a/bin/varnishtest/tests/v00016.vtc b/bin/varnishtest/tests/v00016.vtc
index 691cc56..b3bbbf2 100644
--- a/bin/varnishtest/tests/v00016.vtc
+++ b/bin/varnishtest/tests/v00016.vtc
@@ -97,3 +97,15 @@ varnish v1 -vcl {
 	backend b { .host = "127.0.0.1"; }
 	sub vcl_hash { if (2 == 3) { } }
 }
+
+varnish v1 -vcl {
+	backend if0 { .host = "127.0.0.1"; }
+}
+
+varnish v1 -vcl {
+	backend include0 { .host = "127.0.0.1"; }
+}
+
+varnish v1 -vcl {
+	backend else0 { .host = "127.0.0.1"; }
+}
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index fde8bb2..84ad6d2 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 4bc29c7..1bd88d6 100644
--- a/lib/libvcl/vcc_compile.c
+++ b/lib/libvcl/vcc_compile.c
@@ -439,7 +439,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 4a242e5..ea86b47 100644
--- a/lib/libvcl/vcc_parse.c
+++ b/lib/libvcl/vcc_parse.c
@@ -88,37 +88,47 @@ 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, ";");
 }
 
 /*--------------------------------------------------------------------
@@ -148,9 +158,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;
@@ -168,11 +175,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