2013-03-18 13:40:14 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2013 Statoil ASA.
|
|
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
2013-03-14 12:07:33 +01:00
|
|
|
*/
|
2013-03-18 13:40:14 +01:00
|
|
|
|
2013-12-06 16:11:56 +01:00
|
|
|
#ifndef OPM_PARSER_HPP
|
|
|
|
|
#define OPM_PARSER_HPP
|
2013-03-14 12:07:33 +01:00
|
|
|
#include <string>
|
2014-01-08 11:20:31 +01:00
|
|
|
#include <map>
|
2013-03-18 15:59:57 +01:00
|
|
|
#include <fstream>
|
2013-12-02 13:07:01 +01:00
|
|
|
#include <memory>
|
2013-03-14 12:07:33 +01:00
|
|
|
|
2013-12-06 14:18:05 +01:00
|
|
|
#include <boost/filesystem.hpp>
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
2013-07-30 14:10:07 +02:00
|
|
|
#include <opm/json/JsonObject.hpp>
|
|
|
|
|
|
2013-05-06 09:48:29 +02:00
|
|
|
#include <opm/parser/eclipse/RawDeck/RawKeyword.hpp>
|
2013-05-30 10:11:12 +02:00
|
|
|
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
2013-06-20 15:30:37 +02:00
|
|
|
#include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
|
2013-03-14 12:07:33 +01:00
|
|
|
|
2013-03-18 15:59:57 +01:00
|
|
|
namespace Opm {
|
|
|
|
|
|
2013-12-06 15:27:05 +01:00
|
|
|
struct ParserState;
|
2013-12-06 14:18:05 +01:00
|
|
|
|
2013-05-06 12:13:49 +02:00
|
|
|
/// The hub of the parsing process.
|
|
|
|
|
/// An input file in the eclipse data format is specified, several steps of parsing is performed
|
|
|
|
|
/// and the semantically parsed result is returned.
|
|
|
|
|
|
|
|
|
|
class Parser {
|
|
|
|
|
public:
|
2013-09-14 22:39:43 +02:00
|
|
|
Parser(bool addDefault = true);
|
2013-05-06 12:13:49 +02:00
|
|
|
|
|
|
|
|
/// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned.
|
2015-01-16 14:51:57 +01:00
|
|
|
DeckPtr parseFile(const std::string &dataFile) const;
|
|
|
|
|
DeckPtr parseString(const std::string &data) const;
|
|
|
|
|
DeckPtr parseStream(std::shared_ptr<std::istream> inputStream) const;
|
2013-08-11 12:36:16 +02:00
|
|
|
|
2013-06-20 15:30:37 +02:00
|
|
|
/// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data.
|
2014-06-27 16:42:54 +02:00
|
|
|
void addParserKeyword(ParserKeywordConstPtr parserKeyword);
|
|
|
|
|
bool dropParserKeyword(const std::string& parserKeywordName);
|
2015-02-06 13:03:44 +01:00
|
|
|
ParserKeywordConstPtr getKeyword(const std::string& name) const;
|
2014-07-01 16:57:07 +02:00
|
|
|
|
2014-09-02 17:26:07 +02:00
|
|
|
bool isRecognizedKeyword( const std::string& deckKeywordName) const;
|
2014-07-01 16:57:07 +02:00
|
|
|
ParserKeywordConstPtr getParserKeywordFromDeckName(const std::string& deckKeywordName) const;
|
|
|
|
|
std::vector<std::string> getAllDeckNames () const;
|
2013-12-06 14:18:05 +01:00
|
|
|
|
2013-07-31 11:30:21 +02:00
|
|
|
void loadKeywords(const Json::JsonObject& jsonKeywords);
|
2013-08-19 22:37:48 +02:00
|
|
|
bool loadKeywordFromFile(const boost::filesystem::path& configFile);
|
2013-08-21 12:50:21 +02:00
|
|
|
|
2014-06-11 16:28:48 +02:00
|
|
|
void loadKeywordsFromDirectory(const boost::filesystem::path& directory , bool recursive = true);
|
2013-12-14 10:28:49 +01:00
|
|
|
void applyUnitsToDeck(DeckPtr deck) const;
|
2014-06-27 16:42:54 +02:00
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Returns the approximate number of recognized keywords in decks
|
|
|
|
|
*
|
|
|
|
|
* This is an approximate number because regular expresions are disconsidered.
|
|
|
|
|
*/
|
|
|
|
|
size_t size() const;
|
|
|
|
|
|
2014-07-01 16:57:07 +02:00
|
|
|
/*!
|
|
|
|
|
* \brief Returns whether the parser knows about an keyword with a given internal
|
|
|
|
|
* name.
|
|
|
|
|
*/
|
|
|
|
|
bool hasInternalKeyword(const std::string& internalKeywordName) const;
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Retrieve a ParserKeyword object given an internal keyword name.
|
|
|
|
|
*/
|
|
|
|
|
ParserKeywordConstPtr getParserKeywordFromInternalName(const std::string& internalKeywordName) const;
|
|
|
|
|
|
2013-05-06 12:13:49 +02:00
|
|
|
private:
|
2014-06-27 16:42:54 +02:00
|
|
|
// associative map of the parser internal name and the corresponding ParserKeyword object
|
|
|
|
|
std::map<std::string, ParserKeywordConstPtr> m_internalParserKeywords;
|
|
|
|
|
// associative map of deck names and the corresponding ParserKeyword object
|
|
|
|
|
std::map<std::string, ParserKeywordConstPtr> m_deckParserKeywords;
|
|
|
|
|
// associative map of the parser internal names and the corresponding
|
|
|
|
|
// ParserKeyword object for keywords which match a regular expression
|
2013-12-01 09:28:14 +01:00
|
|
|
std::map<std::string, ParserKeywordConstPtr> m_wildCardKeywords;
|
|
|
|
|
|
2013-12-06 14:18:05 +01:00
|
|
|
bool hasWildCardKeyword(const std::string& keyword) const;
|
2013-12-01 09:28:14 +01:00
|
|
|
ParserKeywordConstPtr matchingKeyword(const std::string& keyword) const;
|
|
|
|
|
|
2013-12-06 14:18:05 +01:00
|
|
|
bool tryParseKeyword(std::shared_ptr<ParserState> parserState) const;
|
2014-10-17 16:43:13 +02:00
|
|
|
bool parseState(std::shared_ptr<ParserState> parserState) const;
|
2013-12-06 14:18:05 +01:00
|
|
|
RawKeywordPtr createRawKeyword(const std::string& keywordString, std::shared_ptr<ParserState> parserState) const;
|
2013-09-14 21:44:20 +02:00
|
|
|
void addDefaultKeywords();
|
2013-12-06 15:27:05 +01:00
|
|
|
|
2014-02-21 12:56:20 +01:00
|
|
|
boost::filesystem::path getIncludeFilePath(std::shared_ptr<ParserState> parserState, std::string path) const;
|
2013-12-06 15:27:05 +01:00
|
|
|
boost::filesystem::path getRootPathFromFile(const boost::filesystem::path &inputDataFile) const;
|
2014-01-28 10:01:11 +01:00
|
|
|
std::string doSpecialHandlingForTitleKeyword(std::string line, std::shared_ptr<ParserState> parserState) const;
|
2013-05-06 12:13:49 +02:00
|
|
|
};
|
|
|
|
|
|
2013-12-06 14:18:05 +01:00
|
|
|
|
2013-12-02 13:07:01 +01:00
|
|
|
typedef std::shared_ptr<Parser> ParserPtr;
|
|
|
|
|
typedef std::shared_ptr<const Parser> ParserConstPtr;
|
2013-03-18 15:59:57 +01:00
|
|
|
} // namespace Opm
|
2013-03-21 15:37:40 +01:00
|
|
|
#endif /* PARSER_H */
|
2013-03-14 12:07:33 +01:00
|
|
|
|