also eat keywords containing lowercase letters

The Norne deck actually exhibits this atrocity in form of the
'fluxnum' keyword in the file 'INCLUDE/PETRO/FLUXNUM_0704.prop'.

I don't know if Eclipse cares about the case of the keywords, but
opm-parser currently does for sure. (If Eclipse turns out to be
case-insensitive, the easiest fix for us is to just make all keywords
ALL_UPPERCASE...)
This commit is contained in:
Andreas Lauser 2014-09-01 21:00:51 +02:00 committed by Joakim Hove
parent 7955ea5dac
commit 382d449ebb
5 changed files with 16 additions and 12 deletions

View File

@ -160,9 +160,8 @@ namespace Opm {
}
bool Parser::isRecognizedKeyword(const std::string& deckKeywordName) const {
if (!ParserKeyword::validDeckName(deckKeywordName)) {
if (!ParserKeyword::validDeckName(deckKeywordName, /*acceptLowerCase=*/true))
return false;
}
if (m_deckParserKeywords.count(deckKeywordName) > 0)
return true;
@ -310,8 +309,8 @@ namespace Opm {
"The keyword " + parserState->rawKeyword->getKeywordName() + " is ignored - this might potentially affect the results");
} else {
DeckKeywordPtr deckKeyword(new DeckKeyword(parserState->rawKeyword->getKeywordName(), false));
deckKeyword->setLocation(parserState->rawKeyword->getFilename(),
parserState->rawKeyword->getLineNR());
deckKeyword->setLocation(parserState->rawKeyword->getFilename(),
parserState->rawKeyword->getLineNR());
parserState->deck->addKeyword(deckKeyword);
parserState->parserLog.addWarning(parserState->dataFile.string(),
parserState->rawKeyword->getLineNR(),

View File

@ -202,11 +202,11 @@ namespace Opm {
}
bool ParserKeyword::validNameStart(const std::string& name) {
bool ParserKeyword::validNameStart(const std::string& name, bool acceptLowerCaseLetters) {
if (name.length() > ParserConst::maxKeywordLength)
return false;
if (!isupper(name[0]))
if (!isupper(name[0]) && !(acceptLowerCaseLetters && islower(name[0])))
return false;
return true;
@ -241,13 +241,14 @@ namespace Opm {
return result;
}
bool ParserKeyword::validDeckName(const std::string& name) {
if (!validNameStart(name))
bool ParserKeyword::validDeckName(const std::string& name, bool acceptLowerCaseLetters) {
if (!validNameStart(name, acceptLowerCaseLetters))
return false;
for (size_t i = 1; i < name.length(); i++) {
char c = name[i];
if (!isupper(c) &&
!(acceptLowerCaseLetters && islower(c)) &&
!isdigit(c) &&
c != '-' &&
c != '_' &&

View File

@ -106,7 +106,7 @@ namespace Opm {
static std::string getDeckName(const std::string& rawString);
static bool validInternalName(const std::string& name);
static bool validDeckName(const std::string& name);
static bool validDeckName(const std::string& name, bool acceptLowerCaseLetters = false);
bool hasMatchRegex() const;
void setMatchRegex(const std::string& deckNameRegexp);
bool matches(const std::string& deckKeywordName) const;
@ -162,7 +162,7 @@ namespace Opm {
ParserKeywordActionEnum m_action;
std::string m_Description;
static bool validNameStart(const std::string& name);
static bool validNameStart(const std::string& name, bool acceptLowerCaseLetters);
void initDeckNames( const Json::JsonObject& jsonConfig );
void initSectionNames( const Json::JsonObject& jsonConfig );
void initMatchRegex( const Json::JsonObject& jsonObject );

View File

@ -138,7 +138,7 @@ namespace Opm {
}
bool RawKeyword::isValidKeyword(const std::string& keywordCandidate) {
return ParserKeyword::validDeckName(keywordCandidate);
return ParserKeyword::validDeckName(keywordCandidate, /*acceptLowerCase=*/true);
}

View File

@ -62,7 +62,11 @@ BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialWhitespaceInKeywordThrows) {
}
BOOST_AUTO_TEST_CASE(constructor_mixedCaseName_throws) {
BOOST_CHECK_THROW(RawKeyword("Test", Raw::SLASH_TERMINATED , "FILE" , 10U), std::invalid_argument);
// raw keywords may be lower-case even if this is not allowed in valid deck
// names... (this will produce a warning if the deck is checked.)
RawKeyword("Test", Raw::SLASH_TERMINATED , "FILE" , 10U);
RawKeyword("test", Raw::SLASH_TERMINATED , "FILE" , 10U);
BOOST_CHECK_THROW(RawKeyword keyword("1test", Raw::SLASH_TERMINATED , "FILE" , 10U), std::invalid_argument);
}
BOOST_AUTO_TEST_CASE(RawKeywordSetKeywordInitialTabInKeywordThrows) {