Skip to content

Commit

Permalink
add match3/4 -- and fix some test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AEsir777 committed Sep 11, 2023
1 parent 510d804 commit 9fc716b
Show file tree
Hide file tree
Showing 10 changed files with 1,732 additions and 1,105 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ tools/python_api/test/test_PYTHON_CSV.csv

# antlr4 jar
scripts/antlr4/antlr4.jar
# .antlr
src/antlr4/.antlr/

# macOS
.DS_Store
Expand Down
6 changes: 2 additions & 4 deletions src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ oC_SingleQuery
oC_SinglePartQuery
: ( oC_ReadingClause SP? )* oC_Return
| ( ( oC_ReadingClause SP? )* oC_UpdatingClause ( SP? oC_UpdatingClause )* ( SP? oC_Return )? )
| ( oC_ReadingClause SP? )* { notifyQueryNotConcludeWithReturn($ctx->start); }
| ( oC_ReadingClause SP? )+ { notifyQueryNotConcludeWithReturn($ctx->start); }
;

oC_MultiPartQuery
Expand Down Expand Up @@ -722,9 +722,7 @@ WHITESPACE
;

Comment
: ( '/*' ( Comment_1 | ( '*' Comment_2 ) )* '*/' )
| ( '--' ( Comment_3 )* CR? ( LF | EOF ) )
;
: ( '/*' ( Comment_1 | ( '*' Comment_2 ) )* '*/' ) ;

oC_LeftArrowHead
: '<'
Expand Down
23 changes: 14 additions & 9 deletions src/parser/transform/transform_graph_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,21 @@ std::unique_ptr<RelPattern> Transformer::transformRelationshipPattern(
CypherParser::OC_RelationshipPatternContext& ctx) {
auto relDetail = ctx.oC_RelationshipDetail();
auto variable = std::string();
if (relDetail->oC_Variable()) {
variable = transformVariable(*relDetail->oC_Variable());
}
auto relTypes = std::vector<std::string>{};
if (relDetail->oC_RelationshipTypes()) {
relTypes = transformRelTypes(*relDetail->oC_RelationshipTypes());
}
auto properties = std::vector<std::pair<std::string, std::unique_ptr<ParsedExpression>>>{};
if (relDetail->kU_Properties()) {
properties = transformProperties(*relDetail->kU_Properties());

if (relDetail) {
if (relDetail->oC_Variable()) {
variable = transformVariable(*relDetail->oC_Variable());
}
if (relDetail->oC_RelationshipTypes()) {
relTypes = transformRelTypes(*relDetail->oC_RelationshipTypes());
}
if (relDetail->kU_Properties()) {
properties = transformProperties(*relDetail->kU_Properties());
}
}

ArrowDirection arrowDirection;
if (ctx.oC_LeftArrowHead()) {
arrowDirection = ArrowDirection::LEFT;
Expand All @@ -94,9 +98,10 @@ std::unique_ptr<RelPattern> Transformer::transformRelationshipPattern(
} else {
arrowDirection = ArrowDirection::BOTH;
}

auto relType = QueryRelType::NON_RECURSIVE;
std::unique_ptr<RecursiveRelPatternInfo> recursiveInfo;
if (relDetail->oC_RangeLiteral()) {
if (relDetail && relDetail->oC_RangeLiteral()) {
if (relDetail->oC_RangeLiteral()->ALL()) {
relType = QueryRelType::ALL_SHORTEST;
} else if (relDetail->oC_RangeLiteral()->SHORTEST()) {
Expand Down
2 changes: 1 addition & 1 deletion test/test_files/copy/copy_to.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Binder exception: Cannot find property non_prop for a.
-LOG Non-Query command
-STATEMENT COPY (EXPLAIN MATCH (p:person) RETURN p.ID) TO "test.csv"
---- error
Parser exception: Query must conclude with RETURN clause (line: 1, offset: 6)
Parser exception: mismatched input 'EXPLAIN' expecting {CALL, OPTIONAL, MATCH, UNWIND, CREATE, MERGE, SET, DELETE, WITH, RETURN} (line: 1, offset: 6)
"COPY (EXPLAIN MATCH (p:person) RETURN p.ID) TO "test.csv""
^^^^^^^

Expand Down
2 changes: 1 addition & 1 deletion test/test_files/exceptions/parser/syntax_error.test
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Parser exception: Query must conclude with RETURN clause (line: 1, offset: 0)
-CASE QueryNotConcludeWithReturn2
-STATEMENT MATCH (a:person) WITH *;
---- error
Parser exception: Query must conclude with RETURN clause (line: 1, offset: 23)
Parser exception: mismatched input ';' expecting {CALL, OPTIONAL, MATCH, UNWIND, CREATE, MERGE, SET, DELETE, WITH, RETURN, SP} (line: 1, offset: 23)
"MATCH (a:person) WITH *;"
^

Expand Down
Loading

0 comments on commit 9fc716b

Please sign in to comment.