ActionParser.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
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef ACTION_PARSER_HPP
21#define ACTION_PARSER_HPP
22
23#include <vector>
24#include <string>
25
26#ifdef _MSC_VER
27#include <BaseTsd.h>
28typedef SSIZE_T ssize_t;
29#endif
30
33
34namespace Opm {
35
36namespace Action {
37
38struct ParseNode {
39 ParseNode(TokenType type_arg, const std::string& value_arg) :
40 type(type_arg),
41 value(value_arg)
42 {}
43
44 // Implicit converting constructor.
45 ParseNode(TokenType type_arg) : ParseNode(type_arg, "")
46 {}
47
48
51};
52
53
54
55class Parser {
56public:
57 static Action::ASTNode parse(const std::vector<std::string>& tokens);
58 static TokenType get_type(const std::string& arg);
59 static FuncType get_func(const std::string& arg);
60
61private:
62 explicit Parser(const std::vector<std::string>& tokens);
63
64 ParseNode current() const;
65 ParseNode next();
66 size_t pos() const;
67 Action::ASTNode parse_cmp();
68 Action::ASTNode parse_op();
69 Action::ASTNode parse_left();
70 Action::ASTNode parse_right();
71 Action::ASTNode parse_and();
72 Action::ASTNode parse_or();
73
74 const std::vector<std::string>& tokens;
75 ssize_t current_pos = -1;
76};
77
78
79}
80}
81#endif
const char *const string
Definition: cJSON.h:170
Definition: ASTNode.hpp:13
Definition: ActionParser.hpp:55
static FuncType get_func(const std::string &arg)
static Action::ASTNode parse(const std::vector< std::string > &tokens)
static TokenType get_type(const std::string &arg)
Action
Definition: InputErrorAction.hpp:36
Definition: A.hpp:4
TokenType
Definition: ActionValue.hpp:7
FuncType
Definition: ActionValue.hpp:24
Definition: ActionParser.hpp:38
ParseNode(TokenType type_arg)
Definition: ActionParser.hpp:45
ParseNode(TokenType type_arg, const std::string &value_arg)
Definition: ActionParser.hpp:39
std::string value
Definition: ActionParser.hpp:50
TokenType type
Definition: ActionParser.hpp:49