From fd665a19941d072b6bdc3a44eab9aa26b74e1f40 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sat, 15 Feb 2014 12:45:50 +0100 Subject: [PATCH] ignore conditions after an else (only works if condition is put in parentheses) --- components/compiler/controlparser.cpp | 15 ++++++++++++--- components/compiler/controlparser.hpp | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/components/compiler/controlparser.cpp b/components/compiler/controlparser.cpp index 58542bd73..aefe6d16d 100644 --- a/components/compiler/controlparser.cpp +++ b/components/compiler/controlparser.cpp @@ -8,6 +8,7 @@ #include "scanner.hpp" #include "generator.hpp" #include "errorhandler.hpp" +#include "skipparser.hpp" namespace Compiler { @@ -71,7 +72,7 @@ namespace Compiler } else if (keyword==Scanner::K_else) { - mState = IfElseBodyState; /// \todo should be IfElseEndState; add an option for that + mState = IfElseJunkState; /// \todo should be IfElseEndState; add an option for that } return true; @@ -207,7 +208,8 @@ namespace Compiler return true; } } - else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState) + else if (mState==IfBodyState || mState==IfElseifBodyState || mState==IfElseBodyState || + mState==IfElseJunkState) { if (parseIfBody (keyword, loc, scanner)) return true; @@ -230,6 +232,7 @@ namespace Compiler case IfEndState: mState = IfBodyState; return true; case IfElseifEndState: mState = IfElseifBodyState; return true; case IfElseEndState: mState = IfElseBodyState; return true; + case IfElseJunkState: mState = IfElseBodyState; return true; case WhileEndState: mState = WhileBodyState; return true; @@ -247,7 +250,13 @@ namespace Compiler default: ; } - + } + else if (code==Scanner::S_open && mState==IfElseJunkState) + { + SkipParser skip (getErrorHandler(), getContext()); + scanner.scan (skip); + mState = IfElseBodyState; + return true; } return Parser::parseSpecial (code, loc, scanner); diff --git a/components/compiler/controlparser.hpp b/components/compiler/controlparser.hpp index 24bc7bec7..1175a0ed5 100644 --- a/components/compiler/controlparser.hpp +++ b/components/compiler/controlparser.hpp @@ -26,7 +26,8 @@ namespace Compiler IfElseEndState, IfElseBodyState, IfEndifState, WhileEndState, WhileBodyState, - WhileEndwhileState + WhileEndwhileState, + IfElseJunkState }; typedef std::vector Codes;