From 8f0ab29a9f5d9c5d44dcbd5b50e82949e52fbe27 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 5 Sep 2013 15:47:38 +0200 Subject: [PATCH] allow the use of keywords for strings without quotation marks --- apps/opencs/model/filter/parser.cpp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/filter/parser.cpp b/apps/opencs/model/filter/parser.cpp index 8567e0a95..8f4fcb70c 100644 --- a/apps/opencs/model/filter/parser.cpp +++ b/apps/opencs/model/filter/parser.cpp @@ -49,19 +49,31 @@ namespace CSMFilter Token (Type type = Type_None); + Token (Type type, const std::string& string); + ///< Non-string type that can also be interpreted as a string. + Token (const std::string& string); Token (double number); operator bool() const; + + bool isString() const; }; Token::Token (Type type) : mType (type) {} + Token::Token (Type type, const std::string& string) : mType (type), mString (string) {} + Token::Token (const std::string& string) : mType (Type_String), mString (string) {} Token::Token (double number) : mType (Type_Number), mNumber (number) {} + bool Token::isString() const + { + return mType==Type_String || mType>=Type_Keyword_True; + } + Token::operator bool() const { return mType!=Type_None; @@ -182,7 +194,7 @@ CSMFilter::Token CSMFilter::Parser::checkKeywords (const Token& token) for (int i=0; sKeywords[i]; ++i) if (sKeywords[i]==string || (string.size()==1 && sKeywords[i][0]==string[0])) - return Token (static_cast (i+Token::Type_Keyword_True)); + return Token (static_cast (i+Token::Type_Keyword_True), token.mString); return token; } @@ -351,7 +363,7 @@ boost::shared_ptr CSMFilter::Parser::parseText() if (static_cast (token.mNumber)==token.mNumber) columnId = static_cast (token.mNumber); } - else if (token.mType==Token::Type_String) + else if (token.isString()) { columnId = CSMWorld::Columns::getId (token.mString); } @@ -373,7 +385,7 @@ boost::shared_ptr CSMFilter::Parser::parseText() // parse text pattern token = getNextToken(); - if (token.mType!=Token::Type_String) + if (!token.isString()) { error(); return boost::shared_ptr(); @@ -415,7 +427,7 @@ boost::shared_ptr CSMFilter::Parser::parseValue() if (static_cast (token.mNumber)==token.mNumber) columnId = static_cast (token.mNumber); } - else if (token.mType==Token::Type_String) + else if (token.isString()) { columnId = CSMWorld::Columns::getId (token.mString); } @@ -561,6 +573,8 @@ bool CSMFilter::Parser::parse (const std::string& filter, bool allowPredefined) return true; } + // We do not use isString() here, because there could be a pre-defined filter with an ID that is + // equal a filter keyword. else if (token.mType==Token::Type_String && allowPredefined) { if (getNextToken()!=Token (Token::Type_EOS))