/* 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 . */ #ifndef OPM_PARSER_HPP #define OPM_PARSER_HPP #include #include #include #include #include #include #include #include #include #include namespace Opm { struct ParserState; /// 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: Parser(bool addDefault = true); /// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned. DeckPtr parseFile(const std::string &dataFile, bool strictParsing=true) const; DeckPtr parseString(const std::string &data, bool strictParsing=true) const; /// Method to add ParserKeyword instances, these holding type and size information about the keywords and their data. void addKeyword(ParserKeywordConstPtr parserKeyword); bool dropKeyword(const std::string& keyword); bool canParseKeyword( const std::string& keyword) const; ParserKeywordConstPtr getKeyword(const std::string& keyword) const; std::vector getAllKeywords () const; void loadKeywords(const Json::JsonObject& jsonKeywords); bool loadKeywordFromFile(const boost::filesystem::path& configFile); void loadKeywordsFromDirectory(const boost::filesystem::path& directory , bool recursive = true, bool onlyALLCAPS8Files = true); size_t size() const; void applyUnitsToDeck(DeckPtr deck) const; private: std::map m_parserKeywords; std::map m_wildCardKeywords; bool hasKeyword(const std::string& keyword) const; bool hasWildCardKeyword(const std::string& keyword) const; ParserKeywordConstPtr matchingKeyword(const std::string& keyword) const; bool tryParseKeyword(std::shared_ptr parserState) const; bool parseStream(std::shared_ptr parserState) const; RawKeywordPtr createRawKeyword(const std::string& keywordString, std::shared_ptr parserState) const; void addDefaultKeywords(); boost::filesystem::path getIncludeFilePath(std::shared_ptr parserState, std::string path) const; boost::filesystem::path getRootPathFromFile(const boost::filesystem::path &inputDataFile) const; std::string doSpecialHandlingForTitleKeyword(std::string line, std::shared_ptr parserState) const; }; typedef std::shared_ptr ParserPtr; typedef std::shared_ptr ParserConstPtr; } // namespace Opm #endif /* PARSER_H */