From 158a213d349d0eee6dad3d2a0505de8232fe931f Mon Sep 17 00:00:00 2001 From: Joanna Hulboj Date: Mon, 5 Dec 2022 14:26:13 +0000 Subject: [PATCH] Bring back literals starting with a digit --- src/Parsers/Lexer.cpp | 10 +++++++-- ...2493_numeric_literals_with_underscores.sql | 22 +++++++++---------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Parsers/Lexer.cpp b/src/Parsers/Lexer.cpp index 847ad8059ff..c12434c5816 100644 --- a/src/Parsers/Lexer.cpp +++ b/src/Parsers/Lexer.cpp @@ -159,14 +159,20 @@ Token Lexer::nextTokenImpl() } } - /// Identifier cannot start with a digit - prepare ErrorWrongNumber (changes for #28967) + /// Try to parse it to a identifier(1identifier_name), otherwise it return ErrorWrongNumber if (pos < end && isWordCharASCII(*pos)) { ++pos; while (pos < end && isWordCharASCII(*pos)) ++pos; - return Token(TokenType::ErrorWrongNumber, token_begin, pos); + for (const char * iterator = token_begin; iterator < pos; ++iterator) + { + if (!isWordCharASCII(*iterator) && *iterator != '$') + return Token(TokenType::ErrorWrongNumber, token_begin, pos); + } + + return Token(TokenType::BareWord, token_begin, pos); } return Token(TokenType::Number, token_begin, pos); diff --git a/tests/queries/0_stateless/02493_numeric_literals_with_underscores.sql b/tests/queries/0_stateless/02493_numeric_literals_with_underscores.sql index d3605d36d90..1b7c312b4a1 100644 --- a/tests/queries/0_stateless/02493_numeric_literals_with_underscores.sql +++ b/tests/queries/0_stateless/02493_numeric_literals_with_underscores.sql @@ -132,15 +132,15 @@ select _1000 FROM (SELECT 1 AS _1000) FORMAT Null; select -_1; -- { serverError UNKNOWN_IDENTIFIER } select -_1 FROM (SELECT -1 AS _1) FORMAT Null; select +_1; -- { clientError SYNTAX_ERROR } -select 1__0; -- { clientError SYNTAX_ERROR } -select 10_; -- { clientError SYNTAX_ERROR } -select 1_e5; -- { clientError SYNTAX_ERROR } -select 1e_5; -- { clientError SYNTAX_ERROR } -select 1e_; -- { clientError SYNTAX_ERROR } +select 1__0; -- { serverError UNKNOWN_IDENTIFIER } +select 10_; -- { serverError UNKNOWN_IDENTIFIER } +select 1_e5; -- { serverError UNKNOWN_IDENTIFIER } +select 1e_5; -- { serverError UNKNOWN_IDENTIFIER } +select 1e_; -- { serverError UNKNOWN_IDENTIFIER } select 1_.; -- { clientError SYNTAX_ERROR } -select 1e_1; -- { clientError SYNTAX_ERROR } -select 0_x2; -- { clientError SYNTAX_ERROR } -select 0b; -- { clientError SYNTAX_ERROR } -select 0x; -- { clientError SYNTAX_ERROR } -select 0x_; -- { clientError SYNTAX_ERROR } -select 0x_1; -- { clientError SYNTAX_ERROR } +select 1e_1; -- { serverError UNKNOWN_IDENTIFIER } +select 0_x2; -- { serverError UNKNOWN_IDENTIFIER } +select 0b; -- { serverError UNKNOWN_IDENTIFIER } +select 0x; -- { serverError UNKNOWN_IDENTIFIER } +select 0x_; -- { serverError UNKNOWN_IDENTIFIER } +select 0x_1; -- { serverError UNKNOWN_IDENTIFIER }