Skip to content

Commit

Permalink
Fix issue-2984
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Mar 11, 2024
1 parent 8642ccb commit 2397c02
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 179 deletions.
10 changes: 6 additions & 4 deletions scripts/antlr4/Cypher.g4.copy
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ kU_StandaloneCall
CALL : ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ;

kU_CommentOn
: COMMENT SP ON SP TABLE SP oC_SchemaName SP IS SP StringLiteral ;
: COMMENT_ SP ON SP TABLE SP oC_SchemaName SP IS SP StringLiteral ;

COMMENT : ( 'C' | 'c' ) ( 'O' | 'o' ) ( 'M' | 'm' ) ( 'M' | 'm' ) ( 'E' | 'e' ) ( 'N' | 'n' ) ( 'T' | 't' ) ;
COMMENT_ : ( 'C' | 'c' ) ( 'O' | 'o' ) ( 'M' | 'm' ) ( 'M' | 'm' ) ( 'E' | 'e' ) ( 'N' | 'n' ) ( 'T' | 't' ) ;

kU_CreateMacro
: CREATE SP MACRO SP oC_FunctionName SP? '(' SP? kU_PositionalArgs? SP? kU_DefaultArg? ( SP? ',' SP? kU_DefaultArg )* SP? ')' SP AS SP oC_Expression ;
Expand Down Expand Up @@ -754,7 +754,7 @@ oC_SymbolicName

// example of BEGIN and END: TCKWith2.Scenario1
kU_NonReservedKeywords
: COMMENT
: COMMENT_
| COUNT
| NODE
| REL
Expand Down Expand Up @@ -819,7 +819,9 @@ WHITESPACE
;

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

oC_LeftArrowHead
: '<'
Expand Down
10 changes: 6 additions & 4 deletions src/antlr4/Cypher.g4
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ kU_StandaloneCall
CALL : ( 'C' | 'c' ) ( 'A' | 'a' ) ( 'L' | 'l' ) ( 'L' | 'l' ) ;

kU_CommentOn
: COMMENT SP ON SP TABLE SP oC_SchemaName SP IS SP StringLiteral ;
: COMMENT_ SP ON SP TABLE SP oC_SchemaName SP IS SP StringLiteral ;

COMMENT : ( 'C' | 'c' ) ( 'O' | 'o' ) ( 'M' | 'm' ) ( 'M' | 'm' ) ( 'E' | 'e' ) ( 'N' | 'n' ) ( 'T' | 't' ) ;
COMMENT_ : ( 'C' | 'c' ) ( 'O' | 'o' ) ( 'M' | 'm' ) ( 'M' | 'm' ) ( 'E' | 'e' ) ( 'N' | 'n' ) ( 'T' | 't' ) ;

kU_CreateMacro
: CREATE SP MACRO SP oC_FunctionName SP? '(' SP? kU_PositionalArgs? SP? kU_DefaultArg? ( SP? ',' SP? kU_DefaultArg )* SP? ')' SP AS SP oC_Expression ;
Expand Down Expand Up @@ -754,7 +754,7 @@ oC_SymbolicName

// example of BEGIN and END: TCKWith2.Scenario1
kU_NonReservedKeywords
: COMMENT
: COMMENT_
| COUNT
| NODE
| REL
Expand Down Expand Up @@ -819,7 +819,9 @@ WHITESPACE
;

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

oC_LeftArrowHead
: '<'
Expand Down
23 changes: 23 additions & 0 deletions test/test_files/common/comment.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-GROUP CommentTests
-DATASET CSV empty

--

-CASE CommentTest

-STATEMENT RETURN 1; // This is a comment
---- 1
1
-STATEMENT RETURN 1 // This is a comment ;
---- 1
1
-STATEMENT RETURN 1; /* This is a commnet */
---- 1
1
-STATEMENT RETURN 1 /* This is a commnet */ ;
---- 1
1
-STATEMENT /* This is a commnet */
RETURN 1;
---- 1
1
5 changes: 5 additions & 0 deletions test/test_runner/test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ bool TestRunner::checkLogicalPlan(std::unique_ptr<PreparedStatement>& preparedSt
} else if (statement->expectedOk && result->isSuccess()) {
return true;
} else {
if (!preparedStatement->success) {
spdlog::info(
"Query compilation failed with error: {}", preparedStatement->getErrorMessage());
return false;
}
auto planStr = preparedStatement->logicalPlans[planIdx]->toString();
if (checkPlanResult(result, statement, planStr, planIdx)) {
return true;
Expand Down
312 changes: 160 additions & 152 deletions third_party/antlr4_cypher/cypher_lexer.cpp

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions third_party/antlr4_cypher/cypher_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void cypherParserInitialize() {
std::vector<std::string>{
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "CALL", "COMMENT",
"", "", "", "", "", "", "", "", "", "", "", "", "CALL", "COMMENT_",
"MACRO", "GLOB", "COPY", "FROM", "COLUMN", "EXPORT", "IMPORT", "DATABASE",
"NODE", "TABLE", "GROUP", "RDFGRAPH", "DROP", "ALTER", "DEFAULT",
"RENAME", "ADD", "PRIMARY", "KEY", "REL", "TO", "EXPLAIN", "PROFILE",
Expand Down Expand Up @@ -1593,7 +1593,7 @@ CypherParser::KU_CopyFromContext* CypherParser::kU_CopyFrom() {
break;
}

case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -2294,8 +2294,8 @@ CypherParser::KU_CommentOnContext::KU_CommentOnContext(ParserRuleContext *parent
: ParserRuleContext(parent, invokingState) {
}

tree::TerminalNode* CypherParser::KU_CommentOnContext::COMMENT() {
return getToken(CypherParser::COMMENT, 0);
tree::TerminalNode* CypherParser::KU_CommentOnContext::COMMENT_() {
return getToken(CypherParser::COMMENT_, 0);
}

std::vector<tree::TerminalNode *> CypherParser::KU_CommentOnContext::SP() {
Expand Down Expand Up @@ -2346,7 +2346,7 @@ CypherParser::KU_CommentOnContext* CypherParser::kU_CommentOn() {
try {
enterOuterAlt(_localctx, 1);
setState(490);
match(CypherParser::COMMENT);
match(CypherParser::COMMENT_);
setState(491);
match(CypherParser::SP);
setState(492);
Expand Down Expand Up @@ -5358,7 +5358,7 @@ CypherParser::KU_LoadExtensionContext* CypherParser::kU_LoadExtension() {
break;
}

case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -6517,7 +6517,7 @@ CypherParser::KU_LoadFromContext* CypherParser::kU_LoadFrom() {
break;
}

case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -7723,7 +7723,7 @@ CypherParser::OC_ProjectionItemsContext* CypherParser::oC_ProjectionItems() {
case CypherParser::T__5:
case CypherParser::T__7:
case CypherParser::T__25:
case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -8354,7 +8354,7 @@ CypherParser::OC_PatternPartContext* CypherParser::oC_PatternPart() {
setState(1394);
_errHandler->sync(this);
switch (_input->LA(1)) {
case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -12850,7 +12850,7 @@ CypherParser::KU_StructFieldContext* CypherParser::kU_StructField() {
setState(2065);
_errHandler->sync(this);
switch (_input->LA(1)) {
case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -13699,7 +13699,7 @@ CypherParser::OC_PropertyLookupContext* CypherParser::oC_PropertyLookup() {
setState(2214);
_errHandler->sync(this);
switch (_input->LA(1)) {
case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -14168,7 +14168,7 @@ CypherParser::OC_ParameterContext* CypherParser::oC_Parameter() {
setState(2278);
_errHandler->sync(this);
switch (_input->LA(1)) {
case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -14500,7 +14500,7 @@ CypherParser::OC_SymbolicNameContext* CypherParser::oC_SymbolicName() {
break;
}

case CypherParser::COMMENT:
case CypherParser::COMMENT_:
case CypherParser::EXPORT:
case CypherParser::IMPORT:
case CypherParser::DATABASE:
Expand Down Expand Up @@ -14536,8 +14536,8 @@ CypherParser::KU_NonReservedKeywordsContext::KU_NonReservedKeywordsContext(Parse
: ParserRuleContext(parent, invokingState) {
}

tree::TerminalNode* CypherParser::KU_NonReservedKeywordsContext::COMMENT() {
return getToken(CypherParser::COMMENT, 0);
tree::TerminalNode* CypherParser::KU_NonReservedKeywordsContext::COMMENT_() {
return getToken(CypherParser::COMMENT_, 0);
}

tree::TerminalNode* CypherParser::KU_NonReservedKeywordsContext::COUNT() {
Expand Down
2 changes: 1 addition & 1 deletion third_party/antlr4_cypher/include/cypher_lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CypherLexer : public antlr4::Lexer {
T__26 = 27, T__27 = 28, T__28 = 29, T__29 = 30, T__30 = 31, T__31 = 32,
T__32 = 33, T__33 = 34, T__34 = 35, T__35 = 36, T__36 = 37, T__37 = 38,
T__38 = 39, T__39 = 40, T__40 = 41, T__41 = 42, T__42 = 43, T__43 = 44,
T__44 = 45, CALL = 46, COMMENT = 47, MACRO = 48, GLOB = 49, COPY = 50,
T__44 = 45, CALL = 46, COMMENT_ = 47, MACRO = 48, GLOB = 49, COPY = 50,
FROM = 51, COLUMN = 52, EXPORT = 53, IMPORT = 54, DATABASE = 55, NODE = 56,
TABLE = 57, GROUP = 58, RDFGRAPH = 59, DROP = 60, ALTER = 61, DEFAULT = 62,
RENAME = 63, ADD = 64, PRIMARY = 65, KEY = 66, REL = 67, TO = 68, EXPLAIN = 69,
Expand Down
6 changes: 3 additions & 3 deletions third_party/antlr4_cypher/include/cypher_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CypherParser : public antlr4::Parser {
T__26 = 27, T__27 = 28, T__28 = 29, T__29 = 30, T__30 = 31, T__31 = 32,
T__32 = 33, T__33 = 34, T__34 = 35, T__35 = 36, T__36 = 37, T__37 = 38,
T__38 = 39, T__39 = 40, T__40 = 41, T__41 = 42, T__42 = 43, T__43 = 44,
T__44 = 45, CALL = 46, COMMENT = 47, MACRO = 48, GLOB = 49, COPY = 50,
T__44 = 45, CALL = 46, COMMENT_ = 47, MACRO = 48, GLOB = 49, COPY = 50,
FROM = 51, COLUMN = 52, EXPORT = 53, IMPORT = 54, DATABASE = 55, NODE = 56,
TABLE = 57, GROUP = 58, RDFGRAPH = 59, DROP = 60, ALTER = 61, DEFAULT = 62,
RENAME = 63, ADD = 64, PRIMARY = 65, KEY = 66, REL = 67, TO = 68, EXPLAIN = 69,
Expand Down Expand Up @@ -427,7 +427,7 @@ class CypherParser : public antlr4::Parser {
public:
KU_CommentOnContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
antlr4::tree::TerminalNode *COMMENT();
antlr4::tree::TerminalNode *COMMENT_();
std::vector<antlr4::tree::TerminalNode *> SP();
antlr4::tree::TerminalNode* SP(size_t i);
antlr4::tree::TerminalNode *ON();
Expand Down Expand Up @@ -2338,7 +2338,7 @@ class CypherParser : public antlr4::Parser {
public:
KU_NonReservedKeywordsContext(antlr4::ParserRuleContext *parent, size_t invokingState);
virtual size_t getRuleIndex() const override;
antlr4::tree::TerminalNode *COMMENT();
antlr4::tree::TerminalNode *COMMENT_();
antlr4::tree::TerminalNode *COUNT();
antlr4::tree::TerminalNode *NODE();
antlr4::tree::TerminalNode *REL();
Expand Down

0 comments on commit 2397c02

Please sign in to comment.