Support for nested multiline comments

This commit is contained in:
Alexey Milovidov 2020-09-09 20:51:05 +03:00
parent 9acb8fe196
commit 7304bad56f
3 changed files with 22 additions and 4 deletions

View File

@ -253,15 +253,27 @@ Token Lexer::nextTokenImpl()
else else
{ {
++pos; ++pos;
/// Nested multiline comments are supported according to the SQL standard.
size_t nesting_level = 1;
while (pos + 2 <= end) while (pos + 2 <= end)
{ {
/// This means that nested multiline comments are not supported. if (pos[0] == '/' && pos[1] == '*')
if (pos[0] == '*' && pos[1] == '/')
{ {
pos += 2; pos += 2;
return Token(TokenType::Comment, token_begin, pos); ++nesting_level;
} }
++pos; else if (pos[0] == '*' && pos[1] == '/')
{
pos += 2;
--nesting_level;
if (nesting_level == 0)
return Token(TokenType::Comment, token_begin, pos);
}
else
++pos;
} }
return Token(TokenType::ErrorMultilineCommentIsNotClosed, token_begin, end); return Token(TokenType::ErrorMultilineCommentIsNotClosed, token_begin, end);
} }

View File

@ -0,0 +1,3 @@
1
1
1

View File

@ -0,0 +1,3 @@
SELECT /*/**/*/ 1;
SELECT /*a/*b*/c*/ 1;
SELECT /*ab/*cd*/ef*/ 1;