JODA  0.13.1 (59b41972)
JSON On-Demand Analysis
As_Actions.h
Go to the documentation of this file.
1 //
2 // Created by Nico on 08/05/2019.
3 //
4 
5 #ifndef JODA_AS_ACTIONS_H
6 #define JODA_AS_ACTIONS_H
7 
8 #include "../grammar/Grammar.h"
9 #include "../states/States.h"
10 
16 
17 template <>
19  static void apply0(asState &state) {
20  if (state.fun == NOPROJ) state.fun = valProvProj;
21  }
22 };
23 template <>
25  static void apply0(asState &state) {
26  assert(state.fun == NOPROJ);
27  state.fun = arrFlatProj;
28  }
29 };
30 
31 template <>
33  template <typename Input>
34  static void apply(const Input &in, asState &state) {
35  assert(state.fun == NOPROJ);
36  if (!state.projs.empty())
37  throw tao::pegtl::parse_error("'*' has to be the first projection", in);
38  state.fun = allCopyProj;
39  }
40 };
41 
42 template <>
44  template <typename Input>
45  static void apply(const Input &in, asState &state) {
46  assert(state.fun == NOPROJ || state.fun == arrFlatProj);
47  if (state.fun == NOPROJ) state.fun = valProvProj;
48  std::string pointer = in.string();
49  state.putValProv(std::make_unique<joda::query::PointerProvider>(
50  pointer.substr(1, pointer.size() - 2)));
51  }
52 };
53 
54 template <>
56  template <typename Input>
57  static void apply(const Input &in, asState &state) {
58  assert(state.toPointer.empty());
59  std::string pointer = in.string();
60  state.toPointer = pointer.substr(1, pointer.size() - 2);
61  }
62 };
63 
64 template <>
66  static void apply0(asState &state) {
67  switch (state.fun) {
68  case NOPROJ:
69  DCHECK(state.valprov == nullptr);
70  state.projs.push_back(
71  std::make_unique<joda::query::DeletePointerProjector>(
72  state.toPointer));
73  break;
74  case arrFlatProj:
75  state.setprojs.push_back(
76  std::make_unique<joda::query::FlattenProjector>(
77  state.toPointer, std::move(state.valprov)));
78  break;
79  case valProvProj: {
80  assert(state.valprov != nullptr);
81  auto *pProv =
82  dynamic_cast<joda::query::PointerProvider *>(state.valprov.get());
83  if (state.toPointer == "" && pProv != nullptr &&
84  pProv->toString() == "''") {
85  state.projs.push_back(
86  std::make_unique<joda::query::PointerCopyProject>("", ""));
87  state.valprov = nullptr;
88  } else {
89  state.projs.push_back(
90  std::make_unique<joda::query::ValueProviderProjector>(
91  state.toPointer, std::move(state.valprov)));
92  }
93 
94  break;
95  }
96  case allCopyProj:
97  DCHECK(state.valprov == nullptr);
98  DCHECK(state.toPointer.empty());
99  state.projs.push_back(
100  std::make_unique<joda::query::PointerCopyProject>("", ""));
101  break;
102  }
103  state.toPointer.clear();
104  state.fun = NOPROJ;
105  assert(state.toPointer.empty());
106  assert(state.fun == NOPROJ);
107  assert(state.valprov == nullptr);
108  }
109 };
110 
111 } // namespace joda::queryparsing::grammar
112 #endif // JODA_AS_ACTIONS_H
Definition: PointerProvider.h:17
@ NOPROJ
Definition: As_State.h:15
@ allCopyProj
Definition: As_State.h:15
@ arrFlatProj
Definition: As_State.h:15
@ valProvProj
Definition: As_State.h:15
static void apply0(asState &state)
Definition: As_Actions.h:19
static void apply(const Input &in, asState &state)
Definition: As_Actions.h:45
static void apply(const Input &in, asState &state)
Definition: As_Actions.h:34
static void apply0(asState &state)
Definition: As_Actions.h:25
static void apply0(asState &state)
Definition: As_Actions.h:66
static void apply(const Input &in, asState &state)
Definition: As_Actions.h:57
Definition: As_State.h:17
std::vector< std::unique_ptr< joda::query::ISetProjector > > setprojs
Definition: As_State.h:51
bool putValProv(std::unique_ptr< joda::query::IValueProvider > &&val)
Definition: As_State.h:36
projFun fun
Definition: As_State.h:48
std::string toPointer
Definition: As_State.h:47
std::unique_ptr< joda::query::IValueProvider > valprov
Definition: As_State.h:49
std::vector< std::unique_ptr< joda::query::IProjector > > projs
Definition: As_State.h:50
Definition: Literals.h:27