improved handling of extra arguments in StringParser

drop
Marc Zinnschlag 9 years ago
parent 210c77968a
commit f9607a47b3

@ -789,6 +789,7 @@ namespace Compiler
stringParser.setOptional (true); stringParser.setOptional (true);
if (*iter=='c') stringParser.smashCase(); if (*iter=='c') stringParser.smashCase();
if (*iter=='x') stringParser.discard();
scanner.scan (stringParser); scanner.scan (stringParser);
if ((optional || *iter=='x') && stringParser.isEmpty()) if ((optional || *iter=='x') && stringParser.isEmpty())
@ -805,7 +806,8 @@ namespace Compiler
++optionalCount; ++optionalCount;
} }
else else
getErrorHandler().warning("Ignoring extra argument", mTokenLoc); getErrorHandler().warning ("Ignoring extra argument",
stringParser.getTokenLoc());
} }
else if (*iter=='X') else if (*iter=='X')
{ {

@ -13,7 +13,7 @@
namespace Compiler namespace Compiler
{ {
StringParser::StringParser (ErrorHandler& errorHandler, const Context& context, Literals& literals) 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) if (mState==StartState || mState==CommaState)
{ {
start(); start();
mTokenLoc = loc;
if (!mDiscard)
{
if (mSmashCase) if (mSmashCase)
Generator::pushString (mCode, mLiterals, Misc::StringUtils::lowerCase (name)); Generator::pushString (mCode, mLiterals, Misc::StringUtils::lowerCase (name));
else else
Generator::pushString (mCode, mLiterals, name); Generator::pushString (mCode, mLiterals, name);
}
return false; return false;
} }
@ -75,6 +80,8 @@ namespace Compiler
mState = StartState; mState = StartState;
mCode.clear(); mCode.clear();
mSmashCase = false; mSmashCase = false;
mTokenLoc = TokenLoc();
mDiscard = false;
Parser::reset(); Parser::reset();
} }
@ -82,4 +89,14 @@ namespace Compiler
{ {
mSmashCase = true; mSmashCase = true;
} }
const TokenLoc& StringParser::getTokenLoc() const
{
return mTokenLoc;
}
void StringParser::discard()
{
mDiscard = true;
}
} }

@ -6,6 +6,7 @@
#include <components/interpreter/types.hpp> #include <components/interpreter/types.hpp>
#include "parser.hpp" #include "parser.hpp"
#include "tokenloc.hpp"
namespace Compiler namespace Compiler
{ {
@ -22,6 +23,8 @@ namespace Compiler
State mState; State mState;
std::vector<Interpreter::Type_Code> mCode; std::vector<Interpreter::Type_Code> mCode;
bool mSmashCase; bool mSmashCase;
TokenLoc mTokenLoc;
bool mDiscard;
public: public:
@ -48,6 +51,14 @@ namespace Compiler
void reset(); void reset();
///< Reset parser to clean state (this includes the smashCase function). ///< 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();
}; };
} }

Loading…
Cancel
Save