From cbce1a1b7c10e315f51163c5b75ae2f5e5f598e3 Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Wed, 19 Sep 2018 22:44:09 +0300 Subject: [PATCH] Ignore the rest of the line after else (bug #3006) --- CHANGELOG.md | 1 + components/compiler/controlparser.cpp | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a00f4d72..6f6586511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Bug #2969: Scripted items can stack Bug #2987: Editor: some chance and AI data fields can overflow + Bug #3006: 'else if' operator breaks script compilation Bug #3282: Unintended behaviour when assigning F3 and Windows keys Bug #3623: Fix HiDPI on Windows Bug #3733: Normal maps are inverted on mirrored UVs diff --git a/components/compiler/controlparser.cpp b/components/compiler/controlparser.cpp index b202467db..6f9fad35f 100644 --- a/components/compiler/controlparser.cpp +++ b/components/compiler/controlparser.cpp @@ -179,6 +179,14 @@ namespace Compiler scanner.scan (mLineParser); return true; } + else if (mState==IfElseJunkState) + { + getErrorHandler().warning ("Ignoring extra text after else", loc); + SkipParser skip (getErrorHandler(), getContext()); + scanner.scan (skip); + mState = IfElseBodyState; + return true; + } return Parser::parseName (name, loc, scanner); } @@ -207,8 +215,7 @@ namespace Compiler return true; } } - else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState || - mState==IfElseJunkState) + else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState) { if (parseIfBody (keyword, loc, scanner)) return true; @@ -218,6 +225,14 @@ namespace Compiler if ( parseWhileBody (keyword, loc, scanner)) return true; } + else if (mState==IfElseJunkState) + { + getErrorHandler().warning ("Ignoring extra text after else", loc); + SkipParser skip (getErrorHandler(), getContext()); + scanner.scan (skip); + mState = IfElseBodyState; + return true; + } return Parser::parseKeyword (keyword, loc, scanner); } @@ -250,8 +265,9 @@ namespace Compiler default: ; } } - else if (code==Scanner::S_open && mState==IfElseJunkState) + else if (mState==IfElseJunkState) { + getErrorHandler().warning ("Ignoring extra text after else", loc); SkipParser skip (getErrorHandler(), getContext()); scanner.scan (skip); mState = IfElseBodyState;