-
Notifications
You must be signed in to change notification settings - Fork 0
/
TSQueryExpression.cpp
96 lines (78 loc) · 1.79 KB
/
TSQueryExpression.cpp
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
#include "TSQueryExpression.h"
namespace DB
{
namespace TSQuery
{
std::string TSQueryAST::queryOperatorTypeToString(const QueryOperatorType & type)
{
switch (type)
{
case QueryOperatorType::OP_OR:
return " | " ;
case QueryOperatorType::OP_AND:
return " & " ;
case QueryOperatorType::OP_NOT:
return " ! " ;
default:
return "error";
}
}
TSQueryAST::TSQueryAST(
QueryOperand query_operand_)
: type(QueryItermType::QI_VAL)
, left(nullptr)
, right(nullptr)
, query_operator(QueryOperatorType::OP_UNKNOWN)
, query_operand(std::move(query_operand_))
{
}
TSQueryAST::TSQueryAST(
QueryOperator query_operator_,
TSQueryASTPtr left_)
: type(QueryItermType::QI_OPR)
, left(std::move(left_))
, right(nullptr)
, query_operator(std::move(query_operator_))
, query_operand("")
{
if ( query_operator.type != QueryOperatorType::OP_NOT)
{
// TODO
throw;
}
}
TSQueryAST::TSQueryAST(
QueryOperator query_operator_,
TSQueryASTPtr left_,
TSQueryASTPtr right_)
: type(QueryItermType::QI_OPR)
, left(std::move(left_))
, right(std::move(right_))
, query_operator(std::move(query_operator_))
, query_operand("")
{
}
std::string TSQueryAST::toString() const
{
if (type == QueryItermType::QI_VAL)
{
return " " + query_operand.val + " ";
}
else
{
std::string result;
result = " ( " + queryOperatorTypeToString(query_operator.type);
if ( left != nullptr)
{
result += left->toString();
}
if ( right != nullptr)
{
result += right->toString();
}
result += " ) ";
return result;
}
}
}
}