Skip to content

Commit

Permalink
Fix the column index in lexer (#3626)
Browse files Browse the repository at this point in the history
* Fix the column index in lexer.

* Add comments.

* Fix cases.

Co-authored-by: Yee <2520865+yixinglu@users.noreply.github.com>
  • Loading branch information
Shylock-Hg and yixinglu authored Jan 6, 2022
1 parent 34580ee commit b91f8e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
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

0 comments on commit b91f8e5

Please sign in to comment.