Added tests

This commit is contained in:
Maksim Kita 2021-07-21 16:41:45 +03:00
parent 63f67f7997
commit 49983883cc
4 changed files with 29 additions and 23 deletions

View File

@ -422,7 +422,7 @@ private:
{TokenType::Semicolon, Replxx::Color::INTENSE},
{TokenType::Dot, Replxx::Color::INTENSE},
{TokenType::Asterisk, Replxx::Color::INTENSE},
{TokenType::HereDoc, Replxx::Color::BLUE},
{TokenType::HereDoc, Replxx::Color::CYAN},
{TokenType::Plus, Replxx::Color::INTENSE},
{TokenType::Minus, Replxx::Color::INTENSE},
{TokenType::Slash, Replxx::Color::INTENSE},

View File

@ -1,7 +1,6 @@
#include <Parsers/Lexer.h>
#include <Common/StringUtils/StringUtils.h>
#include <common/find_symbols.h>
#include <iostream>
namespace DB
{
@ -340,22 +339,16 @@ Token Lexer::nextTokenImpl()
default:
if (*pos == '$')
{
if (((pos + 1 < end && !isWordCharASCII(pos[1])) || pos + 1 == end))
{
/// Capture standalone dollar sign
return Token(TokenType::DollarSign, token_begin, ++pos);
}
else
{
std::string_view token_stream(pos, end - pos);
/// Try to capture dollar sign as start of here doc
std::string_view token_stream(pos, end - pos);
auto heredoc_name_end_position = token_stream.find('$', 1);
if (heredoc_name_end_position != std::string::npos)
{
size_t heredoc_size = heredoc_name_end_position + 1;
std::string_view heredoc = {token_stream.data(), heredoc_size};
size_t heredoc_end_position = token_stream.find(heredoc, heredoc_size + 1);
size_t heredoc_end_position = token_stream.find(heredoc, heredoc_size);
if (heredoc_end_position != std::string::npos)
{
@ -365,6 +358,11 @@ Token Lexer::nextTokenImpl()
return Token(TokenType::HereDoc, token_begin, pos);
}
}
if (((pos + 1 < end && !isWordCharASCII(pos[1])) || pos + 1 == end))
{
/// Capture standalone dollar sign
return Token(TokenType::DollarSign, token_begin, ++pos);
}
}
if (isWordCharASCII(*pos) || *pos == '$')

View File

@ -0,0 +1,4 @@
VALUE
VALUE
\'VALUE\'

View File

@ -0,0 +1,4 @@
SELECT $$VALUE$$;
SELECT $doc$$doc$;
SELECT $doc$VALUE$doc$;
SELECT $doc$'VALUE'$doc$;