mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Using lexer (development) [#CLICKHOUSE-2].
This commit is contained in:
parent
4562785c2a
commit
57d2f5d0e6
@ -40,6 +40,13 @@ public:
|
||||
data.emplace_back(token);
|
||||
}
|
||||
}
|
||||
|
||||
const Token & max()
|
||||
{
|
||||
if (data.empty())
|
||||
return (*this)[0];
|
||||
return data.back();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -64,6 +71,8 @@ public:
|
||||
bool operator== (const TokenIterator & rhs) const { return index == rhs.index; }
|
||||
|
||||
bool isValid() { return get().type < TokenType::EndOfStream; }
|
||||
|
||||
const Token & max() { return tokens->max(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -134,30 +134,40 @@ ASTPtr tryParseQuery(
|
||||
|
||||
ASTPtr res;
|
||||
bool parse_res = parser.parse(token_iterator, res, expected);
|
||||
const char * max_parsed_pos = token_iterator.max().begin;
|
||||
|
||||
/// Lexical error
|
||||
if (!parse_res && token_iterator->type > TokenType::EndOfStream)
|
||||
{
|
||||
expected = "any valid token";
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, token_iterator->begin, expected, hilite, description);
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, max_parsed_pos, expected, hilite, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// Excessive input after query. Parsed query must end with end of data or semicolon.
|
||||
if (parse_res && token_iterator->type != TokenType::EndOfStream && token_iterator->type != TokenType::Semicolon)
|
||||
/// Excessive input after query. Parsed query must end with end of data or semicolon or data for INSERT.
|
||||
ASTInsertQuery * insert = nullptr;
|
||||
if (parse_res)
|
||||
insert = typeid_cast<ASTInsertQuery *>(res.get());
|
||||
|
||||
if (parse_res
|
||||
&& token_iterator->type != TokenType::EndOfStream
|
||||
&& token_iterator->type != TokenType::Semicolon
|
||||
&& !(insert && insert->data))
|
||||
{
|
||||
expected = "end of query";
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, token_iterator->begin, expected, hilite, description);
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, max_parsed_pos, expected, hilite, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/// If multi-statements are not allowed, then after semicolon, there must be no non-space characters.
|
||||
while (token_iterator->type == TokenType::Semicolon)
|
||||
++token_iterator;
|
||||
|
||||
if (parse_res && !allow_multi_statements && token_iterator->type != TokenType::EndOfStream)
|
||||
/// If multi-statements are not allowed, then after semicolon, there must be no non-space characters.
|
||||
if (parse_res && !allow_multi_statements
|
||||
&& token_iterator->type != TokenType::EndOfStream
|
||||
&& !(insert && insert->data))
|
||||
{
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, token_iterator->begin, nullptr, hilite,
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, max_parsed_pos, nullptr, hilite,
|
||||
(description.empty() ? std::string() : std::string(". ")) + "Multi-statements are not allowed");
|
||||
return nullptr;
|
||||
}
|
||||
@ -165,10 +175,11 @@ ASTPtr tryParseQuery(
|
||||
/// Parse error.
|
||||
if (!parse_res)
|
||||
{
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, token_iterator->begin, expected, hilite, description);
|
||||
out_error_message = getSyntaxErrorMessage(begin, end, max_parsed_pos, expected, hilite, description);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
pos = token_iterator->begin;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user