diff --git a/include/cql2cpp/cql2_parser_json.h b/include/cql2cpp/cql2_parser_json.h index f990dc1..4b55ea5 100644 --- a/include/cql2cpp/cql2_parser_json.h +++ b/include/cql2cpp/cql2_parser_json.h @@ -10,6 +10,8 @@ #pragma once +#include + #include "ast_node.h" namespace cql2cpp { @@ -21,9 +23,47 @@ class Cql2ParserJson { public: Cql2ParserJson() {} - bool parse() { return true; } + AstNodePtr parse(const geos_nlohmann::json& j) { + AstNodePtr node; + std::vector children; + if (parse(j, &node, &children)) + for (const auto& child_j : children) { + AstNodePtr child_node = parse(child_j); + if (child_node != nullptr) + node->append(child_node); + else + return nullptr; + } + + return node; + } AstNodePtr root() const { return root_; } + + private: + bool parse(const geos_nlohmann::json& j, AstNodePtr* node, + std::vector* children); +}; + +class JsonParser { + public: + virtual bool detect(const geos_nlohmann::json& j) = 0; + virtual bool parse(const geos_nlohmann::json& j, AstNodePtr* node, + std::vector* children) = 0; +}; + +class JsonParserOperator : public JsonParser { + public: + JsonParserOperator() {} + + bool detect(const geos_nlohmann::json& j) override { + return j.contains("op"); + } + + bool parse(const geos_nlohmann::json& j, AstNodePtr* node, + std::vector* children) override { + return false; + } }; } // namespace cql2cpp