UDQParser.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify it under the terms
7 of the GNU General Public License as published by the Free Software
8 Foundation, either version 3 of the License, or (at your option) any later
9 version.
10
11 OPM is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along with
16 OPM. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19
20#ifndef UDQPARSER_HPP
21#define UDQPARSER_HPP
22
23#include <string>
24#include <vector>
25
26#ifdef _MSC_VER
27#include <BaseTsd.h>
28typedef SSIZE_T ssize_t;
29#endif
30
35
36namespace Opm {
37
38class ParseContext;
39class ErrorGuard;
40
42 UDQParseNode(UDQTokenType type_arg, const std::string& value_arg, const std::vector<std::string>& selector_arg) :
43 type(type_arg),
44 value(value_arg),
45 selector(selector_arg)
46 {
47 if (type_arg == UDQTokenType::ecl_expr)
48 this->var_type = UDQ::targetType(value_arg, selector_arg);
49 }
50
51
52 UDQParseNode(UDQTokenType type_arg, const std::string& value_arg) :
53 UDQParseNode(type_arg, value_arg, {})
54 {}
55
56
57 // Implicit converting constructor.
58 UDQParseNode(UDQTokenType type_arg) : UDQParseNode(type_arg, "")
59 {}
60
63 std::vector<std::string> selector;
65};
66
67
68class UDQParser {
69public:
70 static UDQASTNode parse(const UDQParams& udq_params, UDQVarType target_type, const std::string& target_var, const std::vector<std::string>& tokens, const ParseContext& parseContext, ErrorGuard& errors);
71
72private:
73 UDQParser(const UDQParams& udq_params1, const std::vector<std::string>& tokens1) :
74 udq_params(udq_params1),
75 udqft(UDQFunctionTable(udq_params)),
76 tokens(tokens1)
77 {}
78
79 UDQASTNode parse_cmp();
80 UDQASTNode parse_add();
81 UDQASTNode parse_factor();
82 UDQASTNode parse_mul();
83 UDQASTNode parse_pow();
84
85 UDQParseNode current() const;
86 UDQParseNode next();
87 UDQTokenType get_type(const std::string& arg) const;
88 std::size_t current_size() const;
89 bool empty() const;
90
91 const UDQParams& udq_params;
92 UDQFunctionTable udqft;
93 std::vector<std::string> tokens;
94 ssize_t current_pos = -1;
95};
96
97
98}
99
100#endif
const char *const string
Definition: cJSON.h:170
Definition: ErrorGuard.hpp:29
Definition: ParseContext.hpp:84
Definition: UDQASTNode.hpp:36
Definition: UDQFunctionTable.hpp:31
Definition: UDQParams.hpp:31
Definition: UDQParser.hpp:68
static UDQASTNode parse(const UDQParams &udq_params, UDQVarType target_type, const std::string &target_var, const std::vector< std::string > &tokens, const ParseContext &parseContext, ErrorGuard &errors)
UDQVarType targetType(const std::string &keyword, const std::vector< std::string > &selector)
Definition: A.hpp:4
UDQVarType
Definition: UDQEnums.hpp:59
UDQTokenType
Definition: UDQEnums.hpp:74
Definition: UDQParser.hpp:41
UDQVarType var_type
Definition: UDQParser.hpp:64
std::string value
Definition: UDQParser.hpp:62
UDQTokenType type
Definition: UDQParser.hpp:61
UDQParseNode(UDQTokenType type_arg)
Definition: UDQParser.hpp:58
std::vector< std::string > selector
Definition: UDQParser.hpp:63
UDQParseNode(UDQTokenType type_arg, const std::string &value_arg, const std::vector< std::string > &selector_arg)
Definition: UDQParser.hpp:42
UDQParseNode(UDQTokenType type_arg, const std::string &value_arg)
Definition: UDQParser.hpp:52