ParseMode::PARSE_EXTRA_DATA
Extra elements in the input record are handled with ParseMode::handleError() with the new error mode PARSE_EXTRA_DATA.
This commit is contained in:
@@ -68,6 +68,7 @@ Generator/KeywordGenerator.cpp
|
||||
Generator/KeywordLoader.cpp )
|
||||
|
||||
set( build_parser_source
|
||||
Parser/ParseMode.cpp
|
||||
Parser/ParserEnums.cpp
|
||||
Parser/ParserKeyword.cpp
|
||||
Parser/ParserRecord.cpp
|
||||
@@ -77,6 +78,7 @@ Parser/ParserFloatItem.cpp
|
||||
Parser/ParserDoubleItem.cpp
|
||||
Parser/ParserStringItem.cpp
|
||||
${generator_source}
|
||||
${log_source}
|
||||
)
|
||||
|
||||
set (state_source
|
||||
@@ -276,7 +278,7 @@ Utility/EndscaleWrapper.hpp
|
||||
Utility/ScalecrsWrapper.hpp)
|
||||
|
||||
add_library(buildParser STATIC ${rawdeck_source} ${build_parser_source} ${deck_source} ${unit_source} ${generator_source})
|
||||
target_link_libraries(buildParser opmjson ${Boost_LIBRARIES})
|
||||
target_link_libraries(buildParser opmjson ${Boost_LIBRARIES} ${ERT_LIBRARIES})
|
||||
|
||||
#-----------------------------------------------------------------
|
||||
# This section manages the generation of C++ code for the default keywords.
|
||||
|
||||
@@ -118,10 +118,11 @@ BOOST_AUTO_TEST_CASE(StringsWithSpaceOK) {
|
||||
ParserStringItemPtr itemString(new ParserStringItem(std::string("STRINGITEM1")));
|
||||
ParserRecordPtr record1(new ParserRecord());
|
||||
RawRecordPtr rawRecord(new Opm::RawRecord(" ' VALUE ' /"));
|
||||
ParseMode parseMode;
|
||||
record1->addItem( itemString );
|
||||
|
||||
|
||||
DeckRecordConstPtr deckRecord = record1->parse( rawRecord );
|
||||
DeckRecordConstPtr deckRecord = record1->parse( parseMode , rawRecord );
|
||||
BOOST_CHECK_EQUAL(" VALUE " , deckRecord->getItem(0)->getString(0));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ namespace Opm {
|
||||
addKey(PARSE_RANDOM_TEXT);
|
||||
addKey(PARSE_RANDOM_SLASH);
|
||||
addKey(PARSE_MISSING_DIMS_KEYWORD);
|
||||
addKey(PARSE_EXTRA_DATA);
|
||||
addKey(UNSUPPORTED_SCHEDULE_GEO_MODIFIER);
|
||||
addKey(UNSUPPORTED_COMPORD_TYPE);
|
||||
addKey(UNSUPPORTED_INITIAL_THPRES);
|
||||
@@ -207,11 +208,12 @@ namespace Opm {
|
||||
const std::string ParseMode::PARSE_RANDOM_TEXT = "PARSE_RANDOM_TEXT";
|
||||
const std::string ParseMode::PARSE_RANDOM_SLASH = "PARSE_RANDOM_SLASH";
|
||||
const std::string ParseMode::PARSE_MISSING_DIMS_KEYWORD = "PARSE_MISSING_DIMS_KEYWORD";
|
||||
const std::string ParseMode::PARSE_EXTRA_DATA = "PARSE_EXTRA_DATA";
|
||||
|
||||
const std::string ParseMode::UNSUPPORTED_SCHEDULE_GEO_MODIFIER = "UNSUPPORTED_SCHEDULE_GEO_MODIFIER";
|
||||
const std::string ParseMode::UNSUPPORTED_COMPORD_TYPE = "UNSUPPORTED_COMPORD_TYPE";
|
||||
const std::string ParseMode::UNSUPPORTED_INITIAL_THPRES = "UNSUPPORTED_INITIAL_THPRES";
|
||||
|
||||
|
||||
const std::string ParseMode::INTERNAL_ERROR_UNINITIALIZED_THPRES = "INTERNAL_ERROR_UNINITIALIZED_THPRES";
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,16 @@ namespace Opm {
|
||||
*/
|
||||
const static std::string PARSE_MISSING_DIMS_KEYWORD;
|
||||
|
||||
/*
|
||||
If the number of elements in the input record exceeds the
|
||||
number of items in the keyword configuration this error
|
||||
situation will be triggered. Many keywords end with several
|
||||
ECLIPSE300 only items - in some cases we have omitted those
|
||||
items in the Json configuration; that will typically trigger
|
||||
this error situation when encountering an ECLIPSE300 deck.
|
||||
*/
|
||||
const static std::string PARSE_EXTRA_DATA;
|
||||
|
||||
/*
|
||||
Some property modfiers can be modified in the Schedule
|
||||
section; this effectively means that Eclipse supports time
|
||||
|
||||
@@ -376,7 +376,7 @@ namespace Opm {
|
||||
|
||||
if (isRecognizedKeyword(parserState->rawKeyword->getKeywordName())) {
|
||||
ParserKeywordConstPtr parserKeyword = getParserKeywordFromDeckName(parserState->rawKeyword->getKeywordName());
|
||||
DeckKeywordPtr deckKeyword = parserKeyword->parse(parserState->rawKeyword);
|
||||
DeckKeywordPtr deckKeyword = parserKeyword->parse(parserState->parseMode , parserState->rawKeyword);
|
||||
deckKeyword->setParserKeyword(parserKeyword);
|
||||
parserState->deck->addKeyword(deckKeyword);
|
||||
} else {
|
||||
|
||||
@@ -524,7 +524,7 @@ namespace Opm {
|
||||
return m_deckNames.end();
|
||||
}
|
||||
|
||||
DeckKeywordPtr ParserKeyword::parse(RawKeywordConstPtr rawKeyword) const {
|
||||
DeckKeywordPtr ParserKeyword::parse(const ParseMode& parseMode , RawKeywordConstPtr rawKeyword) const {
|
||||
if (rawKeyword->isFinished()) {
|
||||
DeckKeywordPtr keyword(new DeckKeyword(rawKeyword->getKeywordName()));
|
||||
keyword->setLocation(rawKeyword->getFilename(), rawKeyword->getLineNR());
|
||||
@@ -534,7 +534,7 @@ namespace Opm {
|
||||
auto rawRecord = rawKeyword->getRecord(i);
|
||||
if(m_records.size() > 0) {
|
||||
std::shared_ptr <ParserRecord> record = getRecord(i);
|
||||
DeckRecordConstPtr deckRecord = record->parse(rawRecord);
|
||||
DeckRecordConstPtr deckRecord = record->parse(parseMode , rawRecord);
|
||||
keyword->addRecord(deckRecord);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserFloatItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseMode.hpp>
|
||||
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
@@ -99,7 +100,7 @@ namespace Opm {
|
||||
SectionNameSet::const_iterator validSectionNamesBegin() const;
|
||||
SectionNameSet::const_iterator validSectionNamesEnd() const;
|
||||
|
||||
DeckKeywordPtr parse(RawKeywordConstPtr rawKeyword) const;
|
||||
DeckKeywordPtr parse(const ParseMode& parseMode , RawKeywordConstPtr rawKeyword) const;
|
||||
enum ParserKeywordSizeEnum getSizeType() const;
|
||||
const std::pair<std::string,std::string>& getSizeDefinitionPair() const;
|
||||
bool isDataKeyword() const;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseMode.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
|
||||
@@ -113,7 +114,7 @@ namespace Opm {
|
||||
}
|
||||
}
|
||||
|
||||
DeckRecordConstPtr ParserRecord::parse(RawRecordPtr rawRecord) const {
|
||||
DeckRecordConstPtr ParserRecord::parse(const ParseMode& parseMode , RawRecordPtr rawRecord) const {
|
||||
std::string recordBeforeParsing = rawRecord->getRecordString();
|
||||
DeckRecordPtr deckRecord(new DeckRecord());
|
||||
for (size_t i = 0; i < size(); i++) {
|
||||
@@ -121,11 +122,13 @@ namespace Opm {
|
||||
DeckItemPtr deckItem = parserItem->scan(rawRecord);
|
||||
deckRecord->addItem(deckItem);
|
||||
}
|
||||
const size_t recordSize = rawRecord->size();
|
||||
if (recordSize > 0)
|
||||
throw std::invalid_argument("The RawRecord for keyword \"" + rawRecord->getKeywordName() + "\" in file\"" + rawRecord->getFileName() + "\" contained " +
|
||||
boost::lexical_cast<std::string>(recordSize) +
|
||||
" too many items according to the spec. RawRecord was: " + recordBeforeParsing);
|
||||
|
||||
if (rawRecord->size() > 0) {
|
||||
std::string msg = "The RawRecord for keyword \"" + rawRecord->getKeywordName() + "\" in file\"" + rawRecord->getFileName() + "\" contained " +
|
||||
std::to_string(rawRecord->size()) +
|
||||
" too many items according to the spec. RawRecord was: " + recordBeforeParsing;
|
||||
parseMode.handleError(ParseMode::PARSE_EXTRA_DATA , msg);
|
||||
}
|
||||
|
||||
return deckRecord;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParseMode.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckRecord.hpp>
|
||||
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace Opm {
|
||||
void addDataItem(ParserItemConstPtr item);
|
||||
ParserItemConstPtr get(size_t index) const;
|
||||
ParserItemConstPtr get(const std::string& itemName) const;
|
||||
DeckRecordConstPtr parse(RawRecordPtr rawRecord) const;
|
||||
DeckRecordConstPtr parse(const ParseMode& parseMode , RawRecordPtr rawRecord) const;
|
||||
bool isDataRecord() const;
|
||||
bool equal(const ParserRecord& other) const;
|
||||
bool hasDimension() const;
|
||||
|
||||
@@ -249,3 +249,23 @@ BOOST_AUTO_TEST_CASE( test_constructor_with_values) {
|
||||
BOOST_CHECK_EQUAL( parseMode.get(ParseMode::UNSUPPORTED_INITIAL_THPRES) , InputError::WARN );
|
||||
BOOST_CHECK_EQUAL( parseMode.get(ParseMode::UNSUPPORTED_COMPORD_TYPE) , InputError::WARN );
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_too_much_data ) {
|
||||
const char * deckString =
|
||||
"RUNSPEC\n"
|
||||
"DIMENS\n"
|
||||
" 10 10 10 10 /n"
|
||||
"\n";
|
||||
|
||||
ParseMode parseMode;
|
||||
Parser parser;
|
||||
|
||||
|
||||
parseMode.update(ParseMode::PARSE_EXTRA_DATA , InputError::THROW_EXCEPTION );
|
||||
BOOST_CHECK_THROW( parser.parseString( deckString , parseMode ) , std::invalid_argument);
|
||||
|
||||
parseMode.update(ParseMode::PARSE_EXTRA_DATA , InputError::IGNORE );
|
||||
auto deck = parser.parseString( deckString , parseMode );
|
||||
}
|
||||
|
||||
@@ -393,13 +393,14 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) {
|
||||
std::shared_ptr<ParserRecord> record = std::make_shared<ParserRecord>();
|
||||
ParserIntItemConstPtr item(new ParserIntItem(std::string("ITEM") , ALL));
|
||||
RawKeywordPtr rawkeyword(new RawKeyword( tabdimsKeyword->getName() , "FILE" , 10U , 1));
|
||||
ParseMode parseMode;
|
||||
|
||||
BOOST_CHECK_EQUAL( Raw::FIXED , rawkeyword->getSizeType());
|
||||
rawkeyword->addRawRecordString("/");
|
||||
record->addItem(item);
|
||||
tabdimsKeyword->addRecord( record );
|
||||
|
||||
DeckKeywordConstPtr deckKeyword = tabdimsKeyword->parse( rawkeyword );
|
||||
DeckKeywordConstPtr deckKeyword = tabdimsKeyword->parse( parseMode , rawkeyword );
|
||||
BOOST_REQUIRE_EQUAL( 1U , deckKeyword->size());
|
||||
|
||||
DeckRecordConstPtr deckRecord = deckKeyword->getRecord(0);
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define BOOST_TEST_MODULE ParserTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/ParseMode.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserEnums.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserRecord.hpp>
|
||||
#include <opm/parser/eclipse/Parser/ParserItem.hpp>
|
||||
@@ -126,14 +127,16 @@ static ParserRecordPtr createSimpleParserRecord() {
|
||||
BOOST_AUTO_TEST_CASE(parse_validRecord_noThrow) {
|
||||
ParserRecordPtr record = createSimpleParserRecord();
|
||||
RawRecordPtr rawRecord(new RawRecord("100 443 /"));
|
||||
ParseMode parseMode;
|
||||
rawRecord->dump();
|
||||
BOOST_CHECK_NO_THROW(record->parse(rawRecord));
|
||||
BOOST_CHECK_NO_THROW(record->parse(parseMode , rawRecord));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) {
|
||||
ParserRecordPtr record = createSimpleParserRecord();
|
||||
RawRecordPtr rawRecord(new RawRecord("100 443 /"));
|
||||
DeckRecordConstPtr deckRecord = record->parse(rawRecord);
|
||||
ParseMode parseMode;
|
||||
DeckRecordConstPtr deckRecord = record->parse(parseMode , rawRecord);
|
||||
BOOST_CHECK_EQUAL(2U, deckRecord->size());
|
||||
}
|
||||
|
||||
@@ -165,7 +168,8 @@ static ParserRecordPtr createMixedParserRecord() {
|
||||
BOOST_AUTO_TEST_CASE(parse_validMixedRecord_noThrow) {
|
||||
ParserRecordPtr record = createMixedParserRecord();
|
||||
RawRecordPtr rawRecord(new RawRecord("1 2 10.0 20.0 4 90.0 /"));
|
||||
BOOST_CHECK_NO_THROW(record->parse(rawRecord));
|
||||
ParseMode parseMode;
|
||||
BOOST_CHECK_NO_THROW(record->parse(parseMode , rawRecord));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) {
|
||||
@@ -297,6 +301,7 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) {
|
||||
ParserIntItemConstPtr itemI(new ParserIntItem("I", SINGLE));
|
||||
ParserIntItemConstPtr itemJ(new ParserIntItem("J", SINGLE));
|
||||
ParserIntItemConstPtr itemK(new ParserIntItem("K", SINGLE));
|
||||
ParseMode parseMode;
|
||||
|
||||
parserRecord->addItem(itemI);
|
||||
parserRecord->addItem(itemJ);
|
||||
@@ -304,13 +309,13 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) {
|
||||
|
||||
|
||||
RawRecordPtr rawRecord(new RawRecord("3 3 3 /"));
|
||||
BOOST_CHECK_NO_THROW(parserRecord->parse(rawRecord));
|
||||
BOOST_CHECK_NO_THROW(parserRecord->parse(parseMode , rawRecord));
|
||||
|
||||
RawRecordPtr rawRecordOneExtra(new RawRecord("3 3 3 4 /"));
|
||||
BOOST_CHECK_THROW(parserRecord->parse(rawRecordOneExtra), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(parserRecord->parse(parseMode , rawRecordOneExtra), std::invalid_argument);
|
||||
|
||||
RawRecordPtr rawRecordForgotRecordTerminator(new RawRecord("3 3 3 \n 4 4 4 /"));
|
||||
BOOST_CHECK_THROW(parserRecord->parse(rawRecordForgotRecordTerminator), std::invalid_argument);
|
||||
BOOST_CHECK_THROW(parserRecord->parse(parseMode , rawRecordForgotRecordTerminator), std::invalid_argument);
|
||||
|
||||
}
|
||||
|
||||
@@ -325,11 +330,13 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) {
|
||||
parserRecord->addItem(itemJ);
|
||||
parserRecord->addItem(itemK);
|
||||
|
||||
ParseMode parseMode;
|
||||
RawRecordPtr rawRecord(new RawRecord("3 3 /"));
|
||||
// no default specified for the third item, record can be parsed just fine but trying
|
||||
// to access the data will raise an exception...
|
||||
DeckRecordConstPtr record;
|
||||
BOOST_CHECK_NO_THROW(record = parserRecord->parse(rawRecord));
|
||||
|
||||
BOOST_CHECK_NO_THROW(record = parserRecord->parse(parseMode , rawRecord));
|
||||
BOOST_CHECK_NO_THROW(record->getItem(2));
|
||||
BOOST_CHECK_THROW(record->getItem(2)->getInt(0), std::out_of_range);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user