Recognise Extension Keywords Whose Names Exceed Size Limits

This commit adds targeted support for identifying keywords whose
names exceed the maximum compatibility keyword length limit.  This,
in turn, enables seamless recognition of extension keywords such as

  STRESSEQUILNUM

without compromising the parser's ability to identify long keyword
names that match existing keywords in the first eight characters.
For example, the input string 'GUIDERATE' will still match the
keyword 'GUIDERAT' (without the trailing 'E') and will not be
accidentally treated as a SUMMARY section request to output a group
level UDQ vector.
This commit is contained in:
Bård Skaflestad
2023-08-18 14:48:39 +02:00
parent e179bf87dd
commit f14621aeba
2 changed files with 34 additions and 3 deletions

View File

@@ -881,6 +881,13 @@ newRawKeyword(const std::string& deck_name,
return newRawKeyword(parserKeyword, keyword8, parserState, parser);
}
else if (parser.isBaseRecognizedKeyword(deck_name)) {
// Typically an OPM extended keyword such as STRESSEQUILNUM.
parserState.unknown_keyword = false;
const auto& parserKeyword = parser.getParserKeywordFromDeckName(deck_name);
return newRawKeyword(parserKeyword, deck_name, parserState, parser);
}
else {
parserState.parseContext.handleUnknownKeyword(deck_name,
KeywordLocation {

View File

@@ -2354,12 +2354,36 @@ GUIDERATE
/
)";
const auto stressequilnum_string = std::string { R"(RUNSPEC
DIMENS
1 5 2 /
REGIONS
STRESSEQUILNUM
1 1 1 1 1
2 2 2 2 2 /
END
)" };
parseContext.update(ParseContext::PARSE_LONG_KEYWORD, Opm::InputErrorAction::THROW_EXCEPTION);
BOOST_CHECK_THROW(parser.parseString(deck_string, parseContext, errors), OpmInputError);
parseContext.update(ParseContext::PARSE_LONG_KEYWORD, Opm::InputErrorAction::IGNORE);
auto deck = parser.parseString(deck_string, parseContext, errors);
BOOST_CHECK( deck.hasKeyword("GUIDERAT") );
errors.clear();
{
parseContext.update(ParseContext::PARSE_LONG_KEYWORD, Opm::InputErrorAction::IGNORE);
auto deck = parser.parseString(deck_string, parseContext, errors);
BOOST_CHECK( deck.hasKeyword("GUIDERAT") );
}
errors.clear();
{
parseContext.update(ParseContext::PARSE_LONG_KEYWORD, Opm::InputErrorAction::THROW_EXCEPTION);
const auto deck = parser.parseString(stressequilnum_string, parseContext, errors);
BOOST_CHECK_MESSAGE(deck.hasKeyword("STRESSEQUILNUM"),
R"(Long keyword "STRESSEQUILNUM" must be present in input deck)");
}
}
BOOST_AUTO_TEST_CASE(DynamicParser1) {