Moved parseState out of Parser; source-file only
This function is not an obvious member of Parser, as it is just as reliant on ParserState which is source-file private to Parser. Moves to source file only, without externally-visible private symbol table entry.
This commit is contained in:
@@ -328,6 +328,31 @@ namespace Opm {
|
||||
parseContext.handleError( errorKey , msg.str() );
|
||||
}
|
||||
|
||||
static boost::filesystem::path getIncludeFilePath(ParserState& parserState, std::string path)
|
||||
{
|
||||
const std::string pathKeywordPrefix("$");
|
||||
const std::string validPathNameCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
||||
|
||||
size_t positionOfPathName = path.find(pathKeywordPrefix);
|
||||
|
||||
if ( positionOfPathName != std::string::npos) {
|
||||
std::string stringStartingAtPathName = path.substr(positionOfPathName+1);
|
||||
size_t cutOffPosition = stringStartingAtPathName.find_first_not_of(validPathNameCharacters);
|
||||
std::string stringToFind = stringStartingAtPathName.substr(0, cutOffPosition);
|
||||
std::string stringToReplace = parserState.pathMap.at(stringToFind);
|
||||
boost::replace_all(path, pathKeywordPrefix + stringToFind, stringToReplace);
|
||||
}
|
||||
|
||||
boost::filesystem::path includeFilePath(path);
|
||||
|
||||
if (includeFilePath.is_relative())
|
||||
includeFilePath = parserState.rootPath / includeFilePath;
|
||||
|
||||
return includeFilePath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::shared_ptr< RawKeyword > createRawKeyword( const string_view& kw, ParserState& parserState, const Parser& parser ) {
|
||||
auto keywordString = ParserKeyword::getDeckName( kw );
|
||||
|
||||
@@ -447,28 +472,59 @@ namespace Opm {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool parseState( ParserState& parserState, const Parser& parser ) {
|
||||
|
||||
static boost::filesystem::path getIncludeFilePath(ParserState& parserState, std::string path)
|
||||
{
|
||||
const std::string pathKeywordPrefix("$");
|
||||
const std::string validPathNameCharacters("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
||||
while( !parserState.done() ) {
|
||||
|
||||
size_t positionOfPathName = path.find(pathKeywordPrefix);
|
||||
parserState.rawKeyword.reset();
|
||||
|
||||
if ( positionOfPathName != std::string::npos) {
|
||||
std::string stringStartingAtPathName = path.substr(positionOfPathName+1);
|
||||
size_t cutOffPosition = stringStartingAtPathName.find_first_not_of(validPathNameCharacters);
|
||||
std::string stringToFind = stringStartingAtPathName.substr(0, cutOffPosition);
|
||||
std::string stringToReplace = parserState.pathMap.at(stringToFind);
|
||||
boost::replace_all(path, pathKeywordPrefix + stringToFind, stringToReplace);
|
||||
const bool streamOK = tryParseKeyword( parserState, parser );
|
||||
if( !parserState.rawKeyword && !streamOK )
|
||||
continue;
|
||||
|
||||
if (parserState.rawKeyword->getKeywordName() == Opm::RawConsts::end)
|
||||
return true;
|
||||
|
||||
if (parserState.rawKeyword->getKeywordName() == Opm::RawConsts::endinclude) {
|
||||
parserState.input_stack.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parserState.rawKeyword->getKeywordName() == Opm::RawConsts::paths) {
|
||||
for( const auto& record : *parserState.rawKeyword ) {
|
||||
std::string pathName = readValueToken<std::string>(record.getItem(0));
|
||||
std::string pathValue = readValueToken<std::string>(record.getItem(1));
|
||||
parserState.pathMap.emplace( pathName, pathValue );
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parserState.rawKeyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
auto& firstRecord = parserState.rawKeyword->getFirstRecord( );
|
||||
std::string includeFileAsString = readValueToken<std::string>(firstRecord.getItem(0));
|
||||
boost::filesystem::path includeFile = getIncludeFilePath( parserState, includeFileAsString );
|
||||
|
||||
parserState.loadFile( includeFile );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( parser.isRecognizedKeyword( parserState.rawKeyword->getKeywordName() ) ) {
|
||||
const auto& kwname = parserState.rawKeyword->getKeywordName();
|
||||
const auto* parserKeyword = parser.getParserKeywordFromDeckName( kwname );
|
||||
parserState.deck->addKeyword( parserKeyword->parse( parserState.parseContext, parserState.rawKeyword ) );
|
||||
} else {
|
||||
DeckKeyword deckKeyword( parserState.rawKeyword->getKeywordName(), false );
|
||||
const std::string msg = "The keyword " + parserState.rawKeyword->getKeywordName() + " is not recognized";
|
||||
deckKeyword.setLocation( parserState.rawKeyword->getFilename(),
|
||||
parserState.rawKeyword->getLineNR());
|
||||
parserState.deck->addKeyword( std::move( deckKeyword ) );
|
||||
parserState.deck->getMessageContainer().warning(
|
||||
parserState.current_path().string(), msg, parserState.line() );
|
||||
}
|
||||
}
|
||||
|
||||
boost::filesystem::path includeFilePath(path);
|
||||
|
||||
if (includeFilePath.is_relative())
|
||||
includeFilePath = parserState.rootPath / includeFilePath;
|
||||
|
||||
return includeFilePath;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -489,7 +545,7 @@ namespace Opm {
|
||||
Deck * Parser::newDeckFromFile(const std::string &dataFileName, const ParseContext& parseContext) const {
|
||||
std::shared_ptr<ParserState> parserState = std::make_shared<ParserState>(parseContext);
|
||||
parserState->openRootFile( dataFileName );
|
||||
parseState(parserState);
|
||||
parseState( *parserState, *this );
|
||||
applyUnitsToDeck(*parserState->deck);
|
||||
|
||||
return parserState->deck;
|
||||
@@ -499,7 +555,7 @@ namespace Opm {
|
||||
std::shared_ptr<ParserState> parserState = std::make_shared<ParserState>(parseContext);
|
||||
parserState->loadString( data );
|
||||
|
||||
parseState(parserState);
|
||||
parseState( *parserState, *this );
|
||||
applyUnitsToDeck(*parserState->deck);
|
||||
|
||||
return parserState->deck;
|
||||
@@ -611,59 +667,6 @@ std::vector<std::string> Parser::getAllDeckNames () const {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
bool Parser::parseState(std::shared_ptr<ParserState> parserState) const {
|
||||
|
||||
while( !parserState->done() ) {
|
||||
|
||||
parserState->rawKeyword.reset();
|
||||
|
||||
const bool streamOK = tryParseKeyword( *parserState, *this );
|
||||
if( !parserState->rawKeyword && !streamOK )
|
||||
continue;
|
||||
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::end)
|
||||
return true;
|
||||
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::endinclude) {
|
||||
parserState->input_stack.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::paths) {
|
||||
for( const auto& record : *parserState->rawKeyword ) {
|
||||
std::string pathName = readValueToken<std::string>(record.getItem(0));
|
||||
std::string pathValue = readValueToken<std::string>(record.getItem(1));
|
||||
parserState->pathMap.emplace( pathName, pathValue );
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (parserState->rawKeyword->getKeywordName() == Opm::RawConsts::include) {
|
||||
auto& firstRecord = parserState->rawKeyword->getFirstRecord( );
|
||||
std::string includeFileAsString = readValueToken<std::string>(firstRecord.getItem(0));
|
||||
boost::filesystem::path includeFile = getIncludeFilePath(*parserState, includeFileAsString);
|
||||
|
||||
parserState->loadFile( includeFile );
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isRecognizedKeyword(parserState->rawKeyword->getKeywordName())) {
|
||||
const auto* parserKeyword = getParserKeywordFromDeckName(parserState->rawKeyword->getKeywordName());
|
||||
parserState->deck->addKeyword( parserKeyword->parse(parserState->parseContext , parserState->rawKeyword ) );
|
||||
} else {
|
||||
DeckKeyword deckKeyword(parserState->rawKeyword->getKeywordName(), false);
|
||||
const std::string msg = "The keyword " + parserState->rawKeyword->getKeywordName() + " is not recognized";
|
||||
deckKeyword.setLocation(parserState->rawKeyword->getFilename(),
|
||||
parserState->rawKeyword->getLineNR());
|
||||
parserState->deck->addKeyword( std::move( deckKeyword ) );
|
||||
parserState->deck->getMessageContainer().warning( parserState->current_path().string(), msg, parserState->line() );
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Parser::loadKeywords(const Json::JsonObject& jsonKeywords) {
|
||||
if (jsonKeywords.is_array()) {
|
||||
|
||||
@@ -39,7 +39,6 @@ namespace Opm {
|
||||
class Deck;
|
||||
class ParseContext;
|
||||
class RawKeyword;
|
||||
struct ParserState;
|
||||
|
||||
/// The hub of the parsing process.
|
||||
/// An input file in the eclipse data format is specified, several steps of parsing is performed
|
||||
@@ -114,7 +113,6 @@ namespace Opm {
|
||||
bool hasWildCardKeyword(const std::string& keyword) const;
|
||||
const ParserKeyword* matchingKeyword(const string_view& keyword) const;
|
||||
|
||||
bool parseState(std::shared_ptr<ParserState> parserState) const;
|
||||
void addDefaultKeywords();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user