1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
#include <Parsers/Access/ParserUserNameWithHost.h>
#include <Parsers/Access/ASTUserNameWithHost.h>
#include <Parsers/CommonParsers.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/parseIdentifierOrStringLiteral.h>
#include <boost/algorithm/string.hpp>
namespace DB
{
namespace
{
bool parseUserNameWithHost(IParserBase::Pos & pos, Expected & expected, std::shared_ptr<ASTUserNameWithHost> & ast)
{
return IParserBase::wrapParseImpl(pos, [&]
{
String base_name;
if (!parseIdentifierOrStringLiteral(pos, expected, base_name))
return false;
String host_pattern;
if (ParserToken{TokenType::At}.ignore(pos, expected))
{
if (!parseIdentifierOrStringLiteral(pos, expected, host_pattern))
return false;
boost::algorithm::trim(host_pattern);
if (host_pattern == "%")
host_pattern.clear();
}
ast = std::make_shared<ASTUserNameWithHost>();
ast->base_name = std::move(base_name);
ast->host_pattern = std::move(host_pattern);
return true;
});
}
}
bool ParserUserNameWithHost::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
std::shared_ptr<ASTUserNameWithHost> res;
if (!parseUserNameWithHost(pos, expected, res))
return false;
node = res;
return true;
}
bool ParserUserNamesWithHost::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
std::vector<std::shared_ptr<ASTUserNameWithHost>> names;
auto parse_single_name = [&]
{
std::shared_ptr<ASTUserNameWithHost> ast;
if (!parseUserNameWithHost(pos, expected, ast))
return false;
names.emplace_back(std::move(ast));
return true;
};
if (!ParserList::parseUtil(pos, expected, parse_single_name, false))
return false;
auto result = std::make_shared<ASTUserNamesWithHost>();
result->names = std::move(names);
node = result;
return true;
}
}
|