18 {
19 unsigned int start_sub(i);
20
21 std::unique_ptr<RegionLogicalOperation> new_region = std::make_unique<RegionLogicalOperation>();
22 bool currect_inverse(false);
24
26 int start_element(i);
27 switch (input[i]) {
28
29 case '[': {
30 std::string element;
31 int start_element(i);
33 element.push_back(input[i]);
34 if (input[i] == ']') break;
35 }
36 if (i ==
input.size()) {
37 log << MSG::WARNING <<
"Missing ']' at end of input! Started here:" <<
endmsg;
39 return nullptr;
40 }
41 std::unique_ptr<RegionElement> reg_el = std::make_unique<RegionElement>();
42
43 if (!reg_el->Initialize(element)) {
45 return nullptr;
46 }
47
48 if (!new_region->AddRegion(std::move(reg_el), currect_inverse)) {
49 log << MSG::WARNING <<
"Missing operator!" <<
endmsg;
51 return nullptr;
52 }
53 currect_inverse = false;
54 break;
55 }
56
57 case '(': {
59 if (i >=
input.size()) {
60 log << MSG::WARNING <<
"'(' at end of input!" <<
endmsg;
62 return nullptr;
63 }
64 std::unique_ptr<RegionSelectorBase> second_region{
process_region(input, i,
true)};
65 if (!second_region) { return nullptr; }
66 if (!new_region->AddRegion(std::move(second_region), currect_inverse)) {
67 log << MSG::WARNING <<
"Missing operator!" <<
endmsg;
69 return nullptr;
70 }
71 currect_inverse = false;
72 break;
73 }
74
75 case '!': {
76 if (currect_inverse) {
77 log << MSG::WARNING <<
"Surplus '!'" <<
endmsg;
79 return nullptr;
80 }
81 currect_inverse = true;
82 break;
83 }
84
85 case '&':
86 case '|': {
87 bool next_op(input[i] == '|');
88 if (!new_region->AddOperator(next_op)) {
89 log << MSG::WARNING <<
"Unexpected operator!" <<
endmsg;
91 return nullptr;
92 }
93 break;
94 }
95
96 case ')': {
97 if (new_region->SurplusOperator()) {
98 log << MSG::WARNING <<
"Surplus operator" <<
endmsg;
100 return nullptr;
101 }
102 if (is_in_braces) { return new_region; }
103 log << MSG::WARNING <<
"Unexpected ')'" <<
endmsg;
105 return nullptr;
106 }
107
108 case ' ':
109 case '\t':
110 case '\n':
111 break;
112
113 default:
114 log << MSG::WARNING <<
"Syntax Error" <<
endmsg;
116 return nullptr;
117 }
118 }
119
120 if (is_in_braces) {
121 log << MSG::WARNING <<
"Missing ')'" <<
endmsg;
123 return nullptr;
124 }
125 if (new_region->SurplusOperator()) {
126 log << MSG::WARNING <<
"Surplus operator" <<
endmsg;
128 return nullptr;
129 }
130 return new_region;
131 }
static void print_position(const std::string &input, const unsigned int &position, MsgStream *msgStr)