2017-11-21 19:17:24 +00:00
|
|
|
#include "parseIdentifierOrStringLiteral.h"
|
|
|
|
|
2021-11-26 15:49:40 +00:00
|
|
|
#include <Parsers/ExpressionElementParsers.h>
|
|
|
|
#include <Parsers/ASTLiteral.h>
|
|
|
|
#include <Parsers/ASTIdentifier_fwd.h>
|
2020-05-30 14:18:08 +00:00
|
|
|
#include <Parsers/CommonParsers.h>
|
2020-06-05 21:31:37 +00:00
|
|
|
#include <Parsers/ExpressionListParsers.h>
|
2017-11-21 19:17:24 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
|
|
|
|
2024-02-21 16:56:36 +00:00
|
|
|
|
2017-11-21 19:17:24 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
2024-02-21 16:56:36 +00:00
|
|
|
|
2017-11-21 19:17:24 +00:00
|
|
|
bool parseIdentifierOrStringLiteral(IParser::Pos & pos, Expected & expected, String & result)
|
|
|
|
{
|
2020-06-05 21:31:37 +00:00
|
|
|
return IParserBase::wrapParseImpl(pos, [&]
|
2017-11-21 19:17:24 +00:00
|
|
|
{
|
2020-06-05 21:31:37 +00:00
|
|
|
ASTPtr ast;
|
|
|
|
if (ParserIdentifier().parse(pos, ast, expected))
|
|
|
|
{
|
|
|
|
result = getIdentifierName(ast);
|
|
|
|
return true;
|
|
|
|
}
|
2017-11-21 19:17:24 +00:00
|
|
|
|
2020-06-05 21:31:37 +00:00
|
|
|
if (ParserStringLiteral().parse(pos, ast, expected))
|
|
|
|
{
|
|
|
|
result = ast->as<ASTLiteral &>().value.safeGet<String>();
|
2024-02-21 16:56:36 +00:00
|
|
|
return !result.empty();
|
2020-06-05 21:31:37 +00:00
|
|
|
}
|
2017-11-21 19:17:24 +00:00
|
|
|
|
2020-06-05 21:31:37 +00:00
|
|
|
return false;
|
|
|
|
});
|
2017-11-21 19:17:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-30 14:18:08 +00:00
|
|
|
|
|
|
|
bool parseIdentifiersOrStringLiterals(IParser::Pos & pos, Expected & expected, Strings & result)
|
|
|
|
{
|
2020-06-05 21:31:37 +00:00
|
|
|
Strings res;
|
2020-05-30 14:18:08 +00:00
|
|
|
|
2020-06-05 21:31:37 +00:00
|
|
|
auto parse_single_id_or_literal = [&]
|
|
|
|
{
|
|
|
|
String str;
|
|
|
|
if (!parseIdentifierOrStringLiteral(pos, expected, str))
|
|
|
|
return false;
|
2020-05-30 14:18:08 +00:00
|
|
|
|
2020-06-05 21:31:37 +00:00
|
|
|
res.emplace_back(std::move(str));
|
2020-05-30 14:18:08 +00:00
|
|
|
return true;
|
2020-06-05 21:31:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!ParserList::parseUtil(pos, expected, parse_single_id_or_literal, false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
result = std::move(res);
|
|
|
|
return true;
|
2020-05-30 14:18:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-26 03:37:08 +00:00
|
|
|
}
|