diff --git a/components/compiler/exprparser.cpp b/components/compiler/exprparser.cpp index c739048a6..37c20527e 100644 --- a/components/compiler/exprparser.cpp +++ b/components/compiler/exprparser.cpp @@ -789,6 +789,7 @@ namespace Compiler stringParser.setOptional (true); if (*iter=='c') stringParser.smashCase(); + if (*iter=='x') stringParser.discard(); scanner.scan (stringParser); if ((optional || *iter=='x') && stringParser.isEmpty()) @@ -805,7 +806,8 @@ namespace Compiler ++optionalCount; } else - getErrorHandler().warning("Ignoring extra argument", mTokenLoc); + getErrorHandler().warning ("Ignoring extra argument", + stringParser.getTokenLoc()); } else if (*iter=='X') { diff --git a/components/compiler/stringparser.cpp b/components/compiler/stringparser.cpp index f8798eccd..8041b0f02 100644 --- a/components/compiler/stringparser.cpp +++ b/components/compiler/stringparser.cpp @@ -13,7 +13,7 @@ namespace Compiler { StringParser::StringParser (ErrorHandler& errorHandler, const Context& context, Literals& literals) - : Parser (errorHandler, context), mLiterals (literals), mState (StartState), mSmashCase (false) + : Parser (errorHandler, context), mLiterals (literals), mState (StartState), mSmashCase (false), mDiscard (false) { } @@ -24,10 +24,15 @@ namespace Compiler if (mState==StartState || mState==CommaState) { start(); - if (mSmashCase) - Generator::pushString (mCode, mLiterals, Misc::StringUtils::lowerCase (name)); - else - Generator::pushString (mCode, mLiterals, name); + mTokenLoc = loc; + + if (!mDiscard) + { + if (mSmashCase) + Generator::pushString (mCode, mLiterals, Misc::StringUtils::lowerCase (name)); + else + Generator::pushString (mCode, mLiterals, name); + } return false; } @@ -75,6 +80,8 @@ namespace Compiler mState = StartState; mCode.clear(); mSmashCase = false; + mTokenLoc = TokenLoc(); + mDiscard = false; Parser::reset(); } @@ -82,4 +89,14 @@ namespace Compiler { mSmashCase = true; } + + const TokenLoc& StringParser::getTokenLoc() const + { + return mTokenLoc; + } + + void StringParser::discard() + { + mDiscard = true; + } } diff --git a/components/compiler/stringparser.hpp b/components/compiler/stringparser.hpp index 52469128f..72dab0580 100644 --- a/components/compiler/stringparser.hpp +++ b/components/compiler/stringparser.hpp @@ -6,6 +6,7 @@ #include #include "parser.hpp" +#include "tokenloc.hpp" namespace Compiler { @@ -22,6 +23,8 @@ namespace Compiler State mState; std::vector mCode; bool mSmashCase; + TokenLoc mTokenLoc; + bool mDiscard; public: @@ -48,6 +51,14 @@ namespace Compiler void reset(); ///< Reset parser to clean state (this includes the smashCase function). + + /// Returns TokenLoc object for string. If no string has been parsed, the TokenLoc + /// object will be default initialised. + const TokenLoc& getTokenLoc() const; + + /// If parsing a string, do not add it to the literal table and do not create code + /// for it. + void discard(); }; }