Store TokenIterators in ASTLiteral

This commit is contained in:
Alexander Tokmakov 2019-05-22 03:57:34 +03:00 committed by Alexander Tokmakov
parent dfebedfb70
commit 2322a88ef0
2 changed files with 24 additions and 8 deletions

View File

@ -3,6 +3,7 @@
#include <Core/Field.h>
#include <Common/FieldVisitors.h>
#include <Parsers/ASTWithAlias.h>
#include <Parsers/TokenIterator.h>
namespace DB
@ -15,6 +16,10 @@ class ASTLiteral : public ASTWithAlias
public:
Field value;
/// For ConstantExpressionTemplate
std::optional<TokenIterator> begin;
std::optional<TokenIterator> end;
ASTLiteral(const Field & value_) : value(value_) {}
/** Get the text that identifies this element. */

View File

@ -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<ASTLiteral>(res);
auto literal = std::make_shared<ASTLiteral>(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<ASTLiteral>(res);
auto literal = std::make_shared<ASTLiteral>(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<ASTLiteral>(s);
auto literal = std::make_shared<ASTLiteral>(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<ASTLiteral>(arr);
auto literal = std::make_shared<ASTLiteral>(arr);
literal->begin = literal_begin;
literal->end = ++pos;
node = literal;
return true;
}
else if (pos->type == TokenType::Comma)