Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the column index in lexer. #3626

Merged
merged 6 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser/scanner.lex
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ LABEL_FULL_WIDTH {CN_EN_FULL_WIDTH}{CN_EN_NUM_FULL_WIDTH}*

{DEC}+\.\. {
yyless(yyleng - 2);
yylloc->columns(-2); // remove the extra counted column number
return parseDecimal();
}
{DEC}+ {
Expand Down
26 changes: 26 additions & 0 deletions src/parser/test/ScannerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/tck/features/match/PipeAndVariable.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down