aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/Access/parseUserName.cpp
blob: a4c5c7e894641a9137d630730ed1c4bccc483805 (plain) (blame)
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
#include <Parsers/Access/parseUserName.h>

#include <Parsers/Access/ASTUserNameWithHost.h>
#include <Parsers/Access/ParserUserNameWithHost.h>
#include <Parsers/CommonParsers.h>


namespace DB
{

bool parseUserName(IParser::Pos & pos, Expected & expected, String & user_name)
{
    ASTPtr ast;
    if (!ParserUserNameWithHost{}.parse(pos, ast, expected))
        return false;
    user_name = ast->as<const ASTUserNameWithHost &>().toString();
    return true;
}


bool parseUserNames(IParser::Pos & pos, Expected & expected, Strings & user_names)
{
    ASTPtr ast;
    if (!ParserUserNamesWithHost{}.parse(pos, ast, expected))
        return false;
    user_names = ast->as<const ASTUserNamesWithHost &>().toStrings();
    return true;
}


bool parseCurrentUserTag(IParser::Pos & pos, Expected & expected)
{
    return IParserBase::wrapParseImpl(pos, [&]
    {
        if (!ParserKeyword{"CURRENT_USER"}.ignore(pos, expected) && !ParserKeyword{"currentUser"}.ignore(pos, expected))
            return false;

        if (ParserToken{TokenType::OpeningRoundBracket}.ignore(pos, expected))
        {
            if (!ParserToken{TokenType::ClosingRoundBracket}.ignore(pos, expected))
                return false;
        }
        return true;
    });
}

}