ClickHouse/src/Parsers/parseIdentifierOrStringLiteral.cpp

56 lines
1.3 KiB
C++
Raw Normal View History

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