5 #ifndef JODA_CHOOSE_ACTIONS_H
6 #define JODA_CHOOSE_ACTIONS_H
8 #include "../grammar/Grammar.h"
9 #include "../states/States.h"
20 template <
typename Input>
22 if (state.
valProv.first ==
nullptr) {
23 std::string
pointer = in.string();
24 state.
valProv.first = std::make_unique<joda::query::PointerProvider>(
28 if (state.
valProv.second ==
nullptr) {
29 std::string
pointer = in.string();
30 state.
valProv.second = std::make_unique<joda::query::PointerProvider>(
39 static inline std::string
unescape(
const std::string &s) {
41 std::string::const_iterator it = s.begin();
42 while (it != s.end()) {
44 if (c ==
'\\' && it != s.end()) {
64 template <
typename Input>
66 std::string str = in.string();
68 auto unescaped = unescape(str.substr(1, str.size() - 2));
70 if (state.
valProv.first ==
nullptr) {
72 std::make_unique<joda::query::StringProvider>(unescaped);
75 if (state.
valProv.second ==
nullptr) {
77 std::make_unique<joda::query::StringProvider>(unescaped);
85 template <
typename Input>
87 std::string str = in.string();
88 bool b = str ==
"true";
97 if (state.
valProv.first ==
nullptr) {
98 state.
valProv.first = std::make_unique<joda::query::BoolProvider>(b);
101 if (state.
valProv.second ==
nullptr) {
102 state.
valProv.second = std::make_unique<joda::query::BoolProvider>(b);
110 template <
typename Input>
112 std::string str = in.string();
114 std::unique_ptr<joda::query::IValueProvider> ival;
116 bool try_unisgned =
false;
117 bool try_double =
false;
120 int64_t i = std::stol(str);
121 ival = std::make_unique<joda::query::Int64Provider>(i);
122 }
catch (std::out_of_range &e) {
124 }
catch (std::exception &e) {
130 u_int64_t i = std::stoul(str);
131 ival = std::make_unique<joda::query::UInt64Provider>(i);
132 }
catch (std::exception &e) {
138 double i = std::stod(str);
139 ival = std::make_unique<joda::query::DoubleProvider>(i);
140 }
catch (std::exception &e) {
144 DCHECK(ival !=
nullptr);
146 if (state.
valProv.first ==
nullptr) {
147 state.
valProv.first = std::move(ival);
150 if (state.
valProv.second ==
nullptr) {
151 state.
valProv.second = std::move(ival);
159 template <
typename Input>
161 std::string str = in.string();
163 if (str.size() == 1) {
167 if (str.size() == 2) {
177 template <
typename Input>
179 std::string str = in.string();
181 if (str.size() == 1) {
185 if (str.size() == 2) {
195 template <
typename Input>
197 std::string str = in.string();
199 assert(str.size() == 2);
214 template <
typename Input>
216 if (state.
valProv.first ==
nullptr) {
217 assert(
false &&
"There has to be at least one value");
221 std::unique_ptr<joda::query::Predicate> pred =
nullptr;
223 if (state.
valProv.second ==
nullptr) {
225 assert(state.
comp ==
NONE &&
"If not 'NONE' something went wrong");
226 pred = std::make_unique<joda::query::ValToPredicate>(
227 std::move(state.
valProv.first));
230 switch (state.
comp) {
232 pred = std::make_unique<joda::query::ComparePredicate>(
233 std::move(state.
valProv.first),
234 std::move(state.
valProv.second),
true,
false);
237 pred = std::make_unique<joda::query::ComparePredicate>(
238 std::move(state.
valProv.first),
239 std::move(state.
valProv.second),
true,
true);
242 pred = std::make_unique<joda::query::ComparePredicate>(
243 std::move(state.
valProv.first),
244 std::move(state.
valProv.second),
false,
false);
247 pred = std::make_unique<joda::query::ComparePredicate>(
248 std::move(state.
valProv.first),
249 std::move(state.
valProv.second),
false,
true);
252 pred = std::make_unique<joda::query::EqualizePredicate>(
253 std::move(state.
valProv.first),
254 std::move(state.
valProv.second),
true);
257 pred = std::make_unique<joda::query::EqualizePredicate>(
258 std::move(state.
valProv.first),
259 std::move(state.
valProv.second),
false);
262 assert(
false &&
"May not happen");
268 state.
valProv.second =
nullptr;
271 throw tao::pegtl::parse_error(
"These values cannot be compared. ",
274 throw tao::pegtl::parse_error(
275 "These values cannot be compared for (un)equality.", in);
279 throw tao::pegtl::parse_error(e.
what(), in);
281 assert(pred !=
nullptr);
283 state.
preds.top().second.push_back(std::move(pred));
290 template <
typename Input>
292 std::string str = in.string();
294 auto it = std::find_if(str.begin(), str.end(),
295 std::not1(std::ptr_fun(::isspace)));
296 if (it != str.end()) {
299 assert(state.
preds.top().second.back() !=
nullptr);
300 auto tmp = std::make_unique<joda::query::NegatePredicate>(
301 std::move(state.
preds.top().second.back()));
302 state.
preds.top().second.back() = std::move(tmp);
310 template <
typename Input>
312 assert(!state.
preds.empty());
313 assert(state.
preds.top().first ==
AND);
314 auto pair = std::move(state.
preds.top());
316 assert(!pair.second.empty());
317 std::unique_ptr<joda::query::Predicate> tmpPtr =
nullptr;
318 if (pair.second.size() > 1) {
319 for (
int i = pair.second.size() - 1; i >= 0; --i) {
320 if (tmpPtr ==
nullptr)
321 tmpPtr = std::move(pair.second[i]);
323 auto andPtr = std::make_unique<joda::query::AndPredicate>(
324 std::move(pair.second[i]), std::move(tmpPtr));
325 tmpPtr = std::move(andPtr);
329 tmpPtr = std::move(pair.second.front());
330 assert(!state.
preds.empty());
331 state.
preds.top().second.push_back(std::move(tmpPtr));
336 template <
typename Input>
338 assert(!state.
preds.empty());
339 assert(state.
preds.top().first ==
OR);
340 auto pair = std::move(state.
preds.top());
342 assert(!pair.second.empty());
343 std::unique_ptr<joda::query::Predicate> tmpPtr =
nullptr;
344 if (pair.second.size() > 1) {
345 for (
int i = pair.second.size() - 1; i >= 0; --i) {
346 if (tmpPtr ==
nullptr)
347 tmpPtr = std::move(pair.second[i]);
349 auto andPtr = std::make_unique<joda::query::OrPredicate>(
350 std::move(pair.second[i]), std::move(tmpPtr));
351 tmpPtr = std::move(andPtr);
355 tmpPtr = std::move(pair.second.front());
356 assert(!state.
preds.empty());
357 state.
preds.top().second.push_back(std::move(tmpPtr));
363 template <
typename Input>
368 template <
typename Input>
370 state.
preds.emplace(std::make_pair(
371 AND, std::vector<std::unique_ptr<joda::query::Predicate>>()));
376 template <
typename Input>
378 state.
preds.emplace(std::make_pair(
379 OR, std::vector<std::unique_ptr<joda::query::Predicate>>()));
384 template <
typename Input>
386 state.
preds.emplace(std::make_pair(
387 BASE, std::vector<std::unique_ptr<joda::query::Predicate>>()));
Definition: ComparePredicate.h:16
Definition: EqualizePredicate.h:16
Definition: IValueProvider.h:46
virtual const char * what() const
Definition: IValueProvider.h:49
@ LTE
Definition: Query_State.h:38
@ GTE
Definition: Query_State.h:38
@ NEQU
Definition: Query_State.h:38
@ GT
Definition: Query_State.h:38
@ NONE
Definition: Query_State.h:38
@ LT
Definition: Query_State.h:38
@ EQU
Definition: Query_State.h:38
@ BASE
Definition: Query_State.h:39
@ AND
Definition: Query_State.h:39
@ OR
Definition: Query_State.h:39
Definition: Literals.h:142
Definition: Literals.h:137
Definition: Literals.h:65
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:311
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:369
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:86
static bool apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:215
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:196
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:385
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:160
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:178
static bool apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:111
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:337
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:377
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:21
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:364
static std::string unescape(const std::string &s)
Definition: Choose_Actions.h:39
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:65
static void apply(const Input &in, chooseState &state)
Definition: Choose_Actions.h:291
Definition: Choose_State.h:13
Comparison comp
Definition: Choose_State.h:61
std::pair< std::unique_ptr< joda::query::IValueProvider >, std::unique_ptr< joda::query::IValueProvider > > valProv
Definition: Choose_State.h:60
predStack preds
Definition: Choose_State.h:57
Definition: Literals.h:122
Definition: Literals.h:90
Definition: Literals.h:150
Definition: Literals.h:85
Definition: Literals.h:87
Definition: Literals.h:43
Definition: Literals.h:148
Definition: Literals.h:145
Definition: Literals.h:27
Definition: Literals.h:151
Definition: Literals.h:57
Definition: Literals.h:135