# HG changeset patch # User Teemu Piippo # Date 1345855990 -10800 # Node ID 96f60ca748a0106a41170ea6c50a060e3e6dbf5b # Parent 384c5605bda98467f014db03d8209d2104e25c50 Fixed: else was alloed even without if strictly preceding it diff -r 384c5605bda9 -r 96f60ca748a0 parser.cxx --- 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