diff --git a/query_engine/engine b/query_engine/engine deleted file mode 100755 index 361ca1c2a..000000000 Binary files a/query_engine/engine and /dev/null differ diff --git a/query_engine/query_engine.hpp b/query_engine/query_engine.hpp index a0a99c019..3a6614dc1 100644 --- a/query_engine/query_engine.hpp +++ b/query_engine/query_engine.hpp @@ -21,6 +21,10 @@ using std::endl; class QueryEngine { public: + QueryEngine() + { + } + QueryResult execute(const std::string& query) { auto stripped = stripper.strip(query); @@ -35,7 +39,7 @@ public: private: // TODO: use IoC or something similar - QueryStripper stripper; + QueryStripper stripper{TK_INT, TK_FLOAT, TK_STR}; QueryTraverser traverser; CodeGenerator generator; CodeCompiler compiler; diff --git a/query_engine/query_stripper.hpp b/query_engine/query_stripper.hpp index 155a48653..1bafc0ffc 100644 --- a/query_engine/query_stripper.hpp +++ b/query_engine/query_stripper.hpp @@ -1,27 +1,30 @@ #pragma once #include -#include +#include +#include -#include "cypher/tokenizer/cypher_lexer.hpp" #include "cypher/cypher.h" +#include "cypher/tokenizer/cypher_lexer.hpp" +#include "utils/variadic/variadic.hpp" +template class QueryStripper { public: - // TODO: extract parameters + QueryStripper(Ts&&... strip_types) + : strip_types(std::make_tuple(std::forward(strip_types)...)) {} std::string strip(const std::string& query) { auto tokenizer = lexer.tokenize(query); std::string stripped = ""; int counter = 0; + constexpr auto size = std::tuple_size::value; while (auto token = tokenizer.lookup()) { - // TODO: do this more generic via template metaprogramming - if (token.id == TK_STR || token.id == TK_INT || - token.id == TK_FLOAT) { + if (_or(token.id, strip_types, std::make_index_sequence{})) { stripped += "@" + std::to_string(counter++); } else { stripped += token.value; @@ -31,5 +34,13 @@ public: } private: + std::tuple strip_types; CypherLexer lexer; + + template + bool _or(Value&& value, Tuple&& tuple, std::index_sequence) + { + return or_vargs(std::forward(value), + std::get(std::forward(tuple))...); + } }; diff --git a/utils/variadic/variadic.hpp b/utils/variadic/variadic.hpp new file mode 100644 index 000000000..40f5a54e9 --- /dev/null +++ b/utils/variadic/variadic.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include + +// variadic argument printer + +template +void _print_vargs(std::ostream& s, Head&& head) +{ + s << std::forward(head); +} +template +void _print_vargs(std::ostream& s, Head&& head, Tail&& ...tail) +{ + s << std::forward(head); + _print_vargs(s, std::forward(tail)...); +} +template +void print_vargs(Args&&... args) +{ + _print_vargs(std::cout, std::forward(args)...); +} + +// value equality with any of variadic argument +// example: value == varg[0] OR value == varg[1] OR ... + +template +bool _or_vargs(Value&& value, Head&& head) +{ + return value == head; +} +template +bool _or_vargs(Value&& value, Head&& head, Tail&& ...tail) +{ + return value == head || _or_vargs(std::forward(value), tail...); +} +template +bool or_vargs(Value&& value, Array&&... array) +{ + return _or_vargs(std::forward(value), std::forward(array)...); +}