Skip to content

Commit

Permalink
Finish parsing of IN
Browse files Browse the repository at this point in the history
Signed-off-by: Kunlin Yu <[email protected]>
  • Loading branch information
kunlinyu committed Dec 27, 2024
1 parent 3ce5959 commit e8dd444
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
3 changes: 3 additions & 0 deletions include/cql2cpp/node_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ const std::map<NodeType, std::string> TypeName {
TYPE_2_NAME(IsLikePred)
TYPE_2_NAME(IsBetweenPred)
TYPE_2_NAME(IsInListPred)
TYPE_2_NAME(InList)
TYPE_2_NAME(IsNullPred)
TYPE_2_NAME(SpatialPred)
TYPE_2_NAME(TemporalPred)
TYPE_2_NAME(ArrayPred)
TYPE_2_NAME(PropertyName)
TYPE_2_NAME(Function)
TYPE_2_NAME(ArgumentList)
};

} // namespace cql2cpp
Expand Down
15 changes: 5 additions & 10 deletions include/cql2cpp/tree_dot.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ class Tree2Dot {
public:
static std::string node_name(const AstNode* node) {
if (node->op() != NullOp)
return OpName.at(node->op()) + "(" + value_str(node->value()) + ")";
else if (node->type() == PropertyName)
return std::string("property") + "(" + value_str(node->value()) + ")";
return OpName.at(node->op());
else
return value_str(node->value());
}

static std::string node_value_str(const AstNode* node) {
return value_str(node->value());
return TypeName.at(node->type());
}

static bool GenerateDot(std::ostream& ous, const AstNode* node) {
Expand All @@ -43,8 +37,9 @@ class Tree2Dot {
static bool GenerateDotNode(std::ostream& ous, const AstNode* node) {
if (node == nullptr) return true;

ous << " \"" << node->id() << "\" [label=\"(" << node->id() << ") "
<< node_name(node) << "\"];" << std::endl;
ous << " \"" << node->id() << "\" [label=\"" << node->id() << ". "
<< node_name(node) << "(" << value_str(node->value()) << ")"
<< "\"];" << std::endl;
for (const auto child : node->children()) GenerateDotNode(ous, child);

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/cql2_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

DIGIT [0-9]
ID [a-z][.a-z0-9_\-]*
CHAR_LIT \'.*\'
CHAR_LIT \'[^\']*\'

%%

Expand Down
20 changes: 10 additions & 10 deletions src/cql2_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ using cql2cpp::NameOp;
%type <node> booleanFactor
%type <node> booleanPrimary
%type <node> booleanLiteral
// %type <node> characterExpression
// %type <node> characterClause
%type <node> characterExpression
%type <node> characterClause
%type <node> propertyName
%type <node> predicate
%type <node> comparisonPredicate
Expand Down Expand Up @@ -165,16 +165,16 @@ scalarExpression:
| propertyName
| function
| booleanLiteral
//| characterClause
| characterClause

// characterClause:
// CASEI LPT characterExpression RPT
// | ACCENTI LPT characterExpression RPT
// | CHAR_LIT { std::string s = std::string($1); $$ = new AstNode(s.substr(1, s.size() - 2)); }
characterClause:
CASEI LPT characterExpression RPT { $$ = $3; } // TODO
| ACCENTI LPT characterExpression RPT { $$ = $3; } // TODO
| CHAR_LIT { std::string s = std::string($1); $$ = new AstNode(s.substr(1, s.size() - 2)); }

// characterExpression:
// characterClause
// | propertyName { $$ = $1; }
characterExpression:
characterClause
| propertyName { $$ = $1; }

numericLiteral:
NUMBER_INT { $$ = new AstNode($1); }
Expand Down
4 changes: 4 additions & 0 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
DEFINE_string(cql2_query, "", "cql2 query string");
DEFINE_string(geojson, "", "data set to be queried");
DEFINE_string(dot, "", "generate dot file");
DEFINE_bool(verbose, false, "Enable verbose output");

int main(int argc, char** argv) {
gflags::SetUsageMessage(
Expand All @@ -39,6 +40,9 @@ int main(int argc, char** argv) {
LOG(INFO) << "geojson: " << FLAGS_geojson;
LOG(INFO) << "dot: " << FLAGS_dot;

if (FLAGS_verbose)
cql2cpp::AstNode::set_ostream(&std::cout);

if (FLAGS_cql2_query.empty()) {
LOG(ERROR) << "you should provide cql2_query";
return 0;
Expand Down
1 change: 1 addition & 0 deletions test/indoorjson/in_list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'CONTAINER' IN ('ABC', 'CONTAINER', 'xyz')
7 changes: 4 additions & 3 deletions test/test_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class ParseTest : public testing::Test {
};

// clang-format off
TEST_F(ParseTest, binary ) { EXPECT_TRUE(Parse(case_name_)); } // BBOX
// TEST_F(ParseTest, binlocations) { EXPECT_TRUE(Parse(case_name_)); } // function
// TEST_F(ParseTest, labels ) { EXPECT_TRUE(Parse(case_name_)); } // IN
TEST_F(ParseTest, binary ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, in_list ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, localization) { EXPECT_TRUE(Parse(case_name_)); }
// TEST_F(ParseTest, binlocations) { EXPECT_TRUE(Parse(case_name_)); } // function
// TEST_F(ParseTest, labels ) { EXPECT_TRUE(Parse(case_name_)); }
// clang-format on

0 comments on commit e8dd444

Please sign in to comment.