From 85a56c9b24e0e4892e499be76430567419eb18b2 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 4 Jan 2022 17:41:23 +0800 Subject: [PATCH 1/3] Fix the column index in lexer. --- src/parser/GraphScanner.h | 3 +++ src/parser/scanner.lex | 1 + src/parser/test/ScannerTest.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/parser/GraphScanner.h b/src/parser/GraphScanner.h index f7092a2231d..5647a7a84c2 100644 --- a/src/parser/GraphScanner.h +++ b/src/parser/GraphScanner.h @@ -5,6 +5,8 @@ #ifndef PARSER_GRAPHSCANNER_H_ #define PARSER_GRAPHSCANNER_H_ +#include + #include "common/base/Base.h" // Only include FlexLexer.h if it hasn't been already included @@ -177,6 +179,7 @@ class GraphScanner : public yyFlexLexer { private: friend class Scanner_Basic_Test; + FRIEND_TEST(Scanner, LexColumnCount); int yylex() override; bool hasUnaryMinus_{false}; diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index af7b2ad9f58..37c0bef0f74 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -374,6 +374,7 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}* {DEC}+\.\. { yyless(yyleng - 2); + yylloc->columns(-2); return parseDecimal(); } {DEC}+ { diff --git a/src/parser/test/ScannerTest.cpp b/src/parser/test/ScannerTest.cpp index 830e9c3bb69..1aa2f579ff4 100644 --- a/src/parser/test/ScannerTest.cpp +++ b/src/parser/test/ScannerTest.cpp @@ -603,4 +603,30 @@ TEST(Scanner, Basic) { } } +TEST(Scanner, LexColumnCount) { + using TokenType = nebula::GraphParser::token_type; + nebula::GraphParser::semantic_type yylval; + nebula::GraphParser::location_type yyloc; + GraphScanner scanner; + std::string stream("2.."); + + auto input = [&](char *buf, int maxSize) { + static int copied = 0; + int left = stream.size() - copied; + if (left == 0) { + return 0; + } + int n = left < maxSize ? left : maxSize; + ::memcpy(buf, &stream[copied], n); + copied += n; + return n; + }; + scanner.setReadBuffer(input); + auto type = scanner.yylex(&yylval, &yyloc); + ASSERT_EQ(type, TokenType::INTEGER); + type = scanner.yylex(&yylval, &yyloc); + ASSERT_EQ(type, TokenType::DOT_DOT); + ASSERT_EQ(yyloc.begin.column, 2); +} + } // namespace nebula From f2ae50148465739643efd856f5197663b2734797 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 4 Jan 2022 17:47:33 +0800 Subject: [PATCH 2/3] Add comments. --- src/parser/GraphScanner.h | 3 --- src/parser/scanner.lex | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/parser/GraphScanner.h b/src/parser/GraphScanner.h index 5647a7a84c2..f7092a2231d 100644 --- a/src/parser/GraphScanner.h +++ b/src/parser/GraphScanner.h @@ -5,8 +5,6 @@ #ifndef PARSER_GRAPHSCANNER_H_ #define PARSER_GRAPHSCANNER_H_ -#include - #include "common/base/Base.h" // Only include FlexLexer.h if it hasn't been already included @@ -179,7 +177,6 @@ class GraphScanner : public yyFlexLexer { private: friend class Scanner_Basic_Test; - FRIEND_TEST(Scanner, LexColumnCount); int yylex() override; bool hasUnaryMinus_{false}; diff --git a/src/parser/scanner.lex b/src/parser/scanner.lex index 37c0bef0f74..6e9bf1c4cd0 100644 --- a/src/parser/scanner.lex +++ b/src/parser/scanner.lex @@ -374,7 +374,7 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}* {DEC}+\.\. { yyless(yyleng - 2); - yylloc->columns(-2); + yylloc->columns(-2); // remove the extra counted column number return parseDecimal(); } {DEC}+ { From cce39255af22f473e39462e885a8f06d4269f2e3 Mon Sep 17 00:00:00 2001 From: Shylock Hg <33566796+Shylock-Hg@users.noreply.github.com> Date: Tue, 4 Jan 2022 19:23:00 +0800 Subject: [PATCH 3/3] Fix cases. --- tests/tck/features/match/PipeAndVariable.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tck/features/match/PipeAndVariable.feature b/tests/tck/features/match/PipeAndVariable.feature index c41255896f2..8a0f8cfb1b2 100644 --- a/tests/tck/features/match/PipeAndVariable.feature +++ b/tests/tck/features/match/PipeAndVariable.feature @@ -116,7 +116,7 @@ Feature: Pipe or use variable to store the lookup results MATCH (v:player{name : "Tim Duncan"})-[e:like*2..3]-(b:player) RETURN id(b) as id | GO 1 TO 2 STEPS FROM $-.id OVER * YIELD dst(edge) as id """ - Then a SyntaxError should be raised at runtime: syntax error near `GO 1 TO ' + Then a SyntaxError should be raised at runtime: syntax error near `| GO 1 T' When executing query: """ $var = MATCH (v:player{name : "Tim Duncan"})-[e:like*2..3]-(b:player) RETURN id(b) as id