Fixed: else was alloed even without if strictly preceding it

Sat, 25 Aug 2012 03:53:10 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sat, 25 Aug 2012 03:53:10 +0300
changeset 57
96f60ca748a0
parent 56
384c5605bda9
child 58
bc9317d1b9c9

Fixed: else was alloed even without if strictly preceding it

parser.cxx file | annotate | diff | comparison | revisions
--- a/parser.cxx	Sat Aug 25 03:40:36 2012 +0300
+++ b/parser.cxx	Sat Aug 25 03:53:10 2012 +0300
@@ -67,6 +67,7 @@
 bool g_GotMainLoop = false;
 unsigned int g_BlockStackCursor = 0;
 DataBuffer* g_IfExpression = NULL;
+bool g_CanElse = false;
 
 // ============================================================================
 // Main parser code. Begins read of the script file, checks the syntax of it
@@ -78,6 +79,12 @@
 		memset (&blockstack[i], 0, sizeof (BlockInformation));
 	
 	while (Next()) {
+		// Check if else is potentically valid
+		if (!token.compare ("else") && !g_CanElse)
+			ParserError ("else without preceding if");
+		if (token.compare ("else") != 0)
+			g_CanElse = false;
+		
 		// ============================================================
 		if (!token.compare ("state")) {
 			MUST_TOPLEVEL
@@ -488,6 +495,9 @@
 				case BLOCKTYPE_IF:
 					// Adjust the closing mark.
 					w->MoveMark (SCOPE(0).mark1);
+					
+					// We're returning from if, thus else can be next
+					g_CanElse = true;
 					break;
 				case BLOCKTYPE_ELSE:
 					// else instead uses mark1 for itself (so if expression

mercurial