2018-01-15 19:07:47 +00:00
|
|
|
#include <Common/StringUtils/StringUtils.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
2018-11-25 00:08:50 +00:00
|
|
|
#include <common/find_symbols.h>
|
2016-11-12 17:55:40 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
#include <string.h> /// strncmp, strncasecmp
|
2016-11-12 17:55:40 +00:00
|
|
|
|
2016-11-20 12:43:20 +00:00
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-07-27 21:27:10 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2016-11-12 17:55:40 +00:00
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
ParserKeyword::ParserKeyword(const char * s_) : s(s_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char * ParserKeyword::getName() const
|
|
|
|
{
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-01 18:36:55 +00:00
|
|
|
bool ParserKeyword::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected)
|
2017-06-18 03:07:03 +00:00
|
|
|
{
|
2017-07-12 03:43:50 +00:00
|
|
|
if (pos->type != TokenType::BareWord)
|
|
|
|
return false;
|
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
const char * current_word = s;
|
|
|
|
|
|
|
|
size_t s_length = strlen(s);
|
|
|
|
if (!s_length)
|
|
|
|
throw Exception("Logical error: keyword cannot be empty string", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
|
|
|
const char * s_end = s + s_length;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2017-07-13 04:20:56 +00:00
|
|
|
expected.add(pos, current_word);
|
2017-07-12 03:43:50 +00:00
|
|
|
if (pos->type != TokenType::BareWord)
|
|
|
|
return false;
|
|
|
|
|
2017-06-18 03:07:03 +00:00
|
|
|
const char * next_whitespace = find_first_symbols<' ', '\0'>(current_word, s_end);
|
|
|
|
size_t word_length = next_whitespace - current_word;
|
|
|
|
|
2017-07-12 19:20:57 +00:00
|
|
|
if (word_length != pos->size())
|
2017-06-18 03:07:03 +00:00
|
|
|
return false;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
if (strncasecmp(pos->begin, current_word, word_length))
|
2017-06-18 03:07:03 +00:00
|
|
|
return false;
|
|
|
|
|
2017-07-10 03:28:12 +00:00
|
|
|
++pos;
|
2017-06-18 03:07:03 +00:00
|
|
|
|
|
|
|
if (!*next_whitespace)
|
|
|
|
break;
|
|
|
|
|
|
|
|
current_word = next_whitespace + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-12 17:55:40 +00:00
|
|
|
}
|