From 46e32de3501d170887d8d91bda62030e1f89d058 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 7 Jan 2016 16:01:01 +0100 Subject: [PATCH] improved handling of extra arguments in DiscardParser --- components/compiler/discardparser.cpp | 25 +++++++++++++++++++++++++ components/compiler/discardparser.hpp | 7 ++++++- components/compiler/exprparser.cpp | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/compiler/discardparser.cpp b/components/compiler/discardparser.cpp index da114fb3dd..0e7c4718cb 100644 --- a/components/compiler/discardparser.cpp +++ b/components/compiler/discardparser.cpp @@ -14,6 +14,9 @@ namespace Compiler { if (mState==StartState || mState==CommaState || mState==MinusState) { + if (isEmpty()) + mTokenLoc = loc; + start(); return false; } @@ -25,6 +28,9 @@ namespace Compiler { if (mState==StartState || mState==CommaState || mState==MinusState) { + if (isEmpty()) + mTokenLoc = loc; + start(); return false; } @@ -37,6 +43,9 @@ namespace Compiler { if (mState==StartState || mState==CommaState) { + if (isEmpty()) + mTokenLoc = loc; + start(); return false; } @@ -48,12 +57,22 @@ namespace Compiler { if (code==Scanner::S_comma && mState==StartState) { + if (isEmpty()) + mTokenLoc = loc; + + start(); + mState = CommaState; return true; } if (code==Scanner::S_minus && (mState==StartState || mState==CommaState)) { + if (isEmpty()) + mTokenLoc = loc; + + start(); + mState = MinusState; return true; } @@ -64,6 +83,12 @@ namespace Compiler void DiscardParser::reset() { mState = StartState; + mTokenLoc = TokenLoc(); Parser::reset(); } + + const TokenLoc& DiscardParser::getTokenLoc() const + { + return mTokenLoc; + } } diff --git a/components/compiler/discardparser.hpp b/components/compiler/discardparser.hpp index bee8a87bb2..2a7ed5544d 100644 --- a/components/compiler/discardparser.hpp +++ b/components/compiler/discardparser.hpp @@ -2,6 +2,7 @@ #define COMPILER_DISCARDPARSER_H_INCLUDED #include "parser.hpp" +#include "tokenloc.hpp" namespace Compiler { @@ -14,6 +15,7 @@ namespace Compiler }; State mState; + TokenLoc mTokenLoc; public: @@ -38,8 +40,11 @@ namespace Compiler virtual void reset(); ///< Reset parser to clean state. + + /// Returns TokenLoc object for value. If no value has been parsed, the TokenLoc + /// object will be default initialised. + const TokenLoc& getTokenLoc() const; }; } #endif - diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index 37c20527ef..7c61ad0ee5 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -832,7 +832,7 @@ namespace Compiler if (discardParser.isEmpty()) break; else - getErrorHandler().warning("Ignoring extra argument", mTokenLoc); + getErrorHandler().warning("Ignoring extra argument", discardParser.getTokenLoc()); } else if (*iter=='j') {