Skip to content

Commit

Permalink
Rename parser to parser_text and add parser_json
Browse files Browse the repository at this point in the history
Signed-off-by: Kunlin Yu <[email protected]>
  • Loading branch information
kunlinyu committed Jan 5, 2025
1 parent 7355119 commit ea90589
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 36 deletions.
30 changes: 0 additions & 30 deletions include/cql2cpp/cql2_parser.h

This file was deleted.

29 changes: 29 additions & 0 deletions include/cql2cpp/cql2_parser_json.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* File Name: cql2_parser_json.h
*
* Copyright (c) 2024 IndoorSpatial
*
* Author: Kunlin Yu <[email protected]>
* Create Date: 2024/12/19
*
*/

#pragma once

#include "ast_node.h"

namespace cql2cpp {

class Cql2ParserJson {
private:
AstNodePtr root_;

public:
Cql2ParserJson() {}

bool parse() { return true; }

AstNodePtr root() const { return root_; }
};

} // namespace cql2cpp
36 changes: 36 additions & 0 deletions include/cql2cpp/cql2_parser_text.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* File Name: cql2_parser_text.h
*
* Copyright (c) 2024 IndoorSpatial
*
* Author: Kunlin Yu <[email protected]>
* Create Date: 2024/12/19
*
*/

#pragma once

#include <FlexLexer.h>
#include <glog/logging.h>

#include <cql2_parser_base.hh>

namespace cql2cpp {

class Cql2ParserText : public Cql2ParserBase {
private:
AstNodePtr root_;

public:
Cql2ParserText() : Cql2ParserBase(&root_) {}

void error(const std::string& msg) override {
LOG(ERROR) << "Cql2ParserText Error: " << msg << std::endl;
}

int parse() override { return Cql2ParserBase::parse(); }

AstNodePtr root() const { return root_; }
};

} // namespace cql2cpp
12 changes: 6 additions & 6 deletions include/cql2cpp/cql2cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include "ast_node.h"
#include "cql2_lexer.h"
#include "cql2_parser.h"
#include "cql2_parser_text.h"
#include "evaluator.h"
#include "feature_source.h"
#include "global_yylex.h"
Expand Down Expand Up @@ -60,7 +60,7 @@ class Cql2Cpp {
if (not Parse(cql2_query, &root, &error_msg_)) return false;

// Prepare evaluator
cql2cpp::ValueT value;
ValueT value;

// Loop over all features
for (const auto& [fs, f] : feature_source_2_type_) {
Expand All @@ -87,13 +87,13 @@ class Cql2Cpp {
if (not Parse(cql2_query, &root, error_msg)) return false;

// Evaluate
cql2cpp::ValueT value;
ValueT value;
if (evaluator_.Evaluate(root, &fs, &value) &&
std::holds_alternative<bool>(value)) {
*result = std::get<bool>(value);
if (dot != nullptr) {
std::stringstream ss;
cql2cpp::Tree2Dot::GenerateDot(ss, root);
Tree2Dot::GenerateDot(ss, root);
*dot = ss.str();
}
return true;
Expand All @@ -111,7 +111,7 @@ class Cql2Cpp {

// to dot
std::stringstream ss;
cql2cpp::Tree2Dot::GenerateDot(ss, root);
Tree2Dot::GenerateDot(ss, root);
*dot = ss.str();

return true;
Expand All @@ -129,7 +129,7 @@ class Cql2Cpp {

cql2cpp::AstNode::set_ostream(&oss);

Cql2Parser parser;
Cql2ParserText parser;
int ret = parser.parse();
if (error_msg != nullptr) *error_msg = oss.str();
if (ret == 0) {
Expand Down

0 comments on commit ea90589

Please sign in to comment.