aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Functions/JSONPath/Parsers/ParserJSONPathMemberSquareBracketAccess.cpp
blob: 93e0639ccfed3539c35cf00c9c1fc2500c44a4da (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
#include "ParserJSONPathMemberSquareBracketAccess.h"
#include <memory>
#include <Functions/JSONPath/ASTs/ASTJSONPathMemberAccess.h>
#include <IO/ReadBufferFromMemory.h>
#include <IO/ReadHelpers.h>
#include <Parsers/ASTIdentifier.h>
#include <Parsers/ExpressionElementParsers.h>

namespace DB
{
bool ParserJSONPathMemberSquareBracketAccess::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
    if (pos->type != TokenType::OpeningSquareBracket)
        return false;
    ++pos;
    ASTPtr member_name;
    if (pos->type == TokenType::BareWord || pos->type == TokenType::QuotedIdentifier)
    {
        ParserIdentifier name_p;
        if (!name_p.parse(pos, member_name, expected))
            return false;
    }
    else if (pos->type == TokenType::StringLiteral)
    {
        ReadBufferFromMemory in(pos->begin, pos->size());
        String name;
        readQuotedStringWithSQLStyle(name, in);
        member_name = std::make_shared<ASTIdentifier>(name);
        ++pos;
    }
    else
    {
        return false;
    }
    if (pos->type != TokenType::ClosingSquareBracket)
    {
        return false;
    }
    ++pos;
    auto member_access = std::make_shared<ASTJSONPathMemberAccess>();
    node = member_access;
    return tryGetIdentifierNameInto(member_name, member_access->member_name);
}
}