This repository was archived by the owner on Jan 12, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTSQueryExpression.h
More file actions
109 lines (85 loc) · 2.33 KB
/
TSQueryExpression.h
File metadata and controls
109 lines (85 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#pragma once
#include <cstddef>
#include <string>
#include <memory>
#include <vector>
namespace DB
{
namespace TSQuery
{
class TSQueryAST;
using TSQueryASTPtr = const TSQueryAST *;
class TSQueryAST
{
public:
enum class QueryItermType
{
QI_VAL = 1,
QI_OPR = 2
};
enum class QueryOperatorType
{
OP_OR = 1, // |
OP_AND = 2, // &
OP_NOT = 3, // !
OP_UNKNOWN = 99
};
static std::string queryOperatorTypeToString(const QueryOperatorType & type);
struct QueryOperator
{
QueryOperatorType type;
QueryOperator(const QueryOperatorType & type_): type(type_) {};
};
struct QueryOperand
{
std::string val;
QueryOperand(const std::string * val_): val(*val_) {};
QueryOperand(const std::string & val_): val(val_) {};
};
std::string toString() const;
private:
QueryItermType type;
TSQueryASTPtr left;
TSQueryASTPtr right;
QueryOperator query_operator;
QueryOperand query_operand;
// TSQueryAST only can create by TSqueryContext to avoid memory leak
TSQueryAST(QueryOperand query_operand_);
TSQueryAST(QueryOperator query_operator_, TSQueryASTPtr left_);
TSQueryAST(QueryOperator query_operator_, TSQueryASTPtr left_, TSQueryASTPtr right_);
friend class TSqueryContext;
};
class TSqueryContext
{
public:
~TSqueryContext()
{
for( size_t i = 0 ; i < expressions.size() ; i++)
{
delete expressions[i];
}
expressions.clear();
}
inline TSQueryASTPtr getNewTSQueryAST(const TSQueryAST::QueryOperand & query_operand_)
{
TSQueryASTPtr exp = new TSQueryAST(query_operand_);
expressions.push_back(exp);
return exp;
}
inline TSQueryASTPtr getNewTSQueryAST(const TSQueryAST::QueryOperator & query_operator_, TSQueryASTPtr left_)
{
TSQueryASTPtr exp = new TSQueryAST(query_operator_, left_);
expressions.push_back(exp);
return exp;
}
inline TSQueryASTPtr getNewTSQueryAST(const TSQueryAST::QueryOperator & query_operator_, TSQueryASTPtr left_, TSQueryASTPtr right_)
{
TSQueryASTPtr exp = new TSQueryAST(query_operator_, left_, right_);
expressions.push_back(exp);
return exp;
}
private:
std::vector<TSQueryASTPtr> expressions;
};
}
}