Skip to content

Commit

Permalink
Support hole of polygon by yyinput() and '(' ')' matching
Browse files Browse the repository at this point in the history
Signed-off-by: Kunlin Yu <[email protected]>
  • Loading branch information
kunlinyu committed Jan 4, 2025
1 parent c40ab80 commit 4735fee
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
17 changes: 14 additions & 3 deletions src/cql2_lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,20 @@ LINESTRING[Z]?"("[0-9. +\-,\n]+")" {
return Cql2ParserBase::token::LINESTRING_WKT;
}

POLYGON[Z]?"(("[0-9. +\-,\n]+"))" {
print("GEOMETRY", yytext);
yylval_->emplace<std::string>() = yytext;
POLYGON[Z]?[ ]?"(" {
std::stringstream ss;
ss << yytext;

size_t parenthesis = 1;
do {
char c = yyinput();;
ss << c;
if (c == '(') parenthesis ++;
if (c == ')') parenthesis --;
} while (parenthesis > 0);
std::string text = ss.str();
print("GEOMETRY", text.c_str());
yylval_->emplace<std::string>() = text;
return Cql2ParserBase::token::POLYGON_WKT;
}

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions test/indoorjson/spatial.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
S_INTERSECTS(geom, POLYGON ((0 0,2 0,2 2,0 2,0 0), (0.5 0.5, 1.5 0.5, 1.5 1.5, 0.5 1.5, 0.5 0.5)))
3 changes: 2 additions & 1 deletion test/test_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ class ParseTest : public testing::Test {
};

// clang-format off
TEST_F(ParseTest, binary ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, bbox ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, is_in_list ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, is_not_in_list) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, localization ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, array ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, binlocations ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, related_bins ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, avg ) { EXPECT_TRUE(Parse(case_name_)); }
TEST_F(ParseTest, spatial ) { EXPECT_TRUE(Parse(case_name_)); }
// TEST_F(ParseTest, labels ) { EXPECT_TRUE(Parse(case_name_)); } // standard unsupported
// clang-format on

0 comments on commit 4735fee

Please sign in to comment.