summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/lexer/regex/lexer.cpp
diff options
context:
space:
mode:
authorvityaman <[email protected]>2025-04-09 15:56:28 +0300
committerrobot-piglet <[email protected]>2025-04-09 16:23:45 +0300
commit51016b5bd58ceae9cd9e56aaa4b52a0a12174221 (patch)
tree8996776d97804c1e0f08e329abed7c638e2ce506 /yql/essentials/sql/v1/lexer/regex/lexer.cpp
parent8c02be7c9a260edf13714760e07bf560c803761a (diff)
YQL-19616 Fix regex lexer
Fixed regex lexer issues: - `TSKIP` token recognition - `HEXGIGITS` number recognition - `EOF` token content --- - Related to https://github.com/ydb-platform/ydb/issues/15129 - Related to https://github.com/vityaman/ydb/issues/11 --- Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1190 commit_hash:497c39efcbbe4e387da523b5e2c8abaa6485d93b
Diffstat (limited to 'yql/essentials/sql/v1/lexer/regex/lexer.cpp')
-rw-r--r--yql/essentials/sql/v1/lexer/regex/lexer.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/yql/essentials/sql/v1/lexer/regex/lexer.cpp b/yql/essentials/sql/v1/lexer/regex/lexer.cpp
index b8ca033b0c6..9f96e444ac7 100644
--- a/yql/essentials/sql/v1/lexer/regex/lexer.cpp
+++ b/yql/essentials/sql/v1/lexer/regex/lexer.cpp
@@ -28,11 +28,14 @@ namespace NSQLTranslationV1 {
: Grammar_(std::move(grammar))
, Ansi_(ansi)
{
+ RE2::Options custom;
+ custom.set_longest_match(true);
+
for (const auto& [token, regex] : RegexByOtherName) {
if (token == CommentTokenName) {
CommentRegex_.Reset(new RE2(regex));
} else {
- OtherRegexes_.emplace_back(token, new RE2(regex));
+ OtherRegexes_.emplace_back(token, new RE2(regex, custom));
}
}
}
@@ -62,7 +65,7 @@ namespace NSQLTranslationV1 {
onNextToken(std::move(matched));
}
- onNextToken(TParsedToken{.Name = "EOF"});
+ onNextToken(TParsedToken{.Name = "EOF", .Content = "<EOF>"});
return errors == 0;
}
@@ -110,7 +113,7 @@ namespace NSQLTranslationV1 {
size_t count = 0;
for (const auto& keyword : Grammar_.KeywordNames) {
const TStringBuf content = prefix.substr(0, keyword.length());
- if (AsciiEqualsIgnoreCase(content, keyword)) {
+ if (AsciiEqualsIgnoreCase(content, NSQLReflect::TLexerGrammar::KeywordBlock(keyword))) {
matches.emplace_back(keyword, TString(content));
count += 1;
}