From 3659f653fb600c746577d39359e9b22a5e992e89 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 13 Jul 2017 08:28:51 +0300 Subject: [PATCH] Using lexer: better error messages [#CLICKHOUSE-2]. --- dbms/src/Parsers/parseQuery.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/dbms/src/Parsers/parseQuery.cpp b/dbms/src/Parsers/parseQuery.cpp index c0e9f9cb15f..0bb08fd3241 100644 --- a/dbms/src/Parsers/parseQuery.cpp +++ b/dbms/src/Parsers/parseQuery.cpp @@ -245,23 +245,23 @@ ASTPtr tryParseQuery( Token last_token = token_iterator.max(); const char * max_parsed_pos = last_token.begin; + /// Lexical error + if (last_token.isError()) + { + out_error_message = getLexicalErrorMessage(begin, end, max_parsed_pos, getErrorTokenDescription(last_token.type), hilite, query_description); + return nullptr; + } + + /// Unmatched parentheses + UnmatchedParentheses unmatched_parens = checkUnmatchedParentheses(TokenIterator(tokens), &last_token); + if (!unmatched_parens.empty()) + { + out_error_message = getUnmatchedParenthesesErrorMessage(begin, end, unmatched_parens, hilite, query_description); + return nullptr; + } + if (!parse_res) { - /// Lexical error - if (last_token.isError()) - { - out_error_message = getLexicalErrorMessage(begin, end, max_parsed_pos, getErrorTokenDescription(last_token.type), hilite, query_description); - return nullptr; - } - - /// Unmatched parentheses - UnmatchedParentheses unmatched_parens = checkUnmatchedParentheses(TokenIterator(tokens), &last_token); - if (!unmatched_parens.empty()) - { - out_error_message = getUnmatchedParenthesesErrorMessage(begin, end, unmatched_parens, hilite, query_description); - return nullptr; - } - /// Parse error. out_error_message = getSyntaxErrorMessage(begin, end, max_parsed_pos, expected, hilite, query_description); return nullptr;