From 2322a88ef0c8da3d5c8380c21f374d6dae3f6dcd Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Wed, 22 May 2019 03:57:34 +0300 Subject: [PATCH] Store TokenIterators in ASTLiteral --- dbms/src/Parsers/ASTLiteral.h | 5 ++++ dbms/src/Parsers/ExpressionElementParsers.cpp | 27 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/dbms/src/Parsers/ASTLiteral.h b/dbms/src/Parsers/ASTLiteral.h index dd5bb572e7d..f72dedb62a6 100644 --- a/dbms/src/Parsers/ASTLiteral.h +++ b/dbms/src/Parsers/ASTLiteral.h @@ -3,6 +3,7 @@ #include #include #include +#include namespace DB @@ -15,6 +16,10 @@ class ASTLiteral : public ASTWithAlias public: Field value; + /// For ConstantExpressionTemplate + std::optional begin; + std::optional end; + ASTLiteral(const Field & value_) : value(value_) {} /** Get the text that identifies this element. */ diff --git a/dbms/src/Parsers/ExpressionElementParsers.cpp b/dbms/src/Parsers/ExpressionElementParsers.cpp index eddbe2abb2f..2bc332a324f 100644 --- a/dbms/src/Parsers/ExpressionElementParsers.cpp +++ b/dbms/src/Parsers/ExpressionElementParsers.cpp @@ -921,6 +921,7 @@ bool ParserNull::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { + Pos literal_begin = pos; bool negative = false; if (pos->type == TokenType::Minus) @@ -983,8 +984,10 @@ bool ParserNumber::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) res = uint_value; } - ++pos; - node = std::make_shared(res); + auto literal = std::make_shared(res); + literal->begin = literal_begin; + literal->end = ++pos; + node = literal; return true; } @@ -1005,8 +1008,10 @@ bool ParserUnsignedInteger::parseImpl(Pos & pos, ASTPtr & node, Expected & expec } res = x; - ++pos; - node = std::make_shared(res); + auto literal = std::make_shared(res); + literal->begin = pos; + literal->end = ++pos; + node = literal; return true; } @@ -1035,8 +1040,10 @@ bool ParserStringLiteral::parseImpl(Pos & pos, ASTPtr & node, Expected & expecte return false; } - ++pos; - node = std::make_shared(s); + auto literal = std::make_shared(s); + literal->begin = pos; + literal->end = ++pos; + node = literal; return true; } @@ -1046,6 +1053,8 @@ bool ParserArrayOfLiterals::parseImpl(Pos & pos, ASTPtr & node, Expected & expec if (pos->type != TokenType::OpeningSquareBracket) return false; + Pos literal_begin = pos; + Array arr; ParserLiteral literal_p; @@ -1058,8 +1067,10 @@ bool ParserArrayOfLiterals::parseImpl(Pos & pos, ASTPtr & node, Expected & expec { if (pos->type == TokenType::ClosingSquareBracket) { - ++pos; - node = std::make_shared(arr); + auto literal = std::make_shared(arr); + literal->begin = literal_begin; + literal->end = ++pos; + node = literal; return true; } else if (pos->type == TokenType::Comma)