summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/analysis/local/local.h
blob: 86de7d1632abe82fe31cebba58ca6734e446a0ce (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
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
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once

#include <yql/essentials/sql/v1/complete/core/name.h>
#include <yql/essentials/sql/v1/complete/sql_complete.h>

#include <yql/essentials/sql/v1/lexer/lexer.h>

#include <util/generic/string.h>
#include <util/generic/hash.h>
#include <util/generic/hash_set.h>
#include <util/generic/maybe.h>

namespace NSQLComplete {

    struct TEditRange {
        size_t Begin = 0;
        size_t Length = 0;
    };

    struct TLocalSyntaxContext {
        using TKeywords = THashMap<TString, TVector<TString>>;

        struct TPragma {
            TString Namespace;
        };

        struct TFunction {
            TString Namespace;
        };

        struct THint {
            EStatementKind StatementKind;
        };

        struct TCluster {
            TString Provider;
        };

        struct TObject {
            TString Provider;
            TString Cluster;
            TString Path;
            THashSet<EObjectKind> Kinds;

            bool HasCluster() const {
                return !Cluster.empty();
            }
        };

        struct TColumn {
            TString Table;
        };

        struct TQuotation {
            bool AtLhs = false;
            bool AtRhs = false;
        };

        TKeywords Keywords;
        TMaybe<TPragma> Pragma;
        bool Type = false;
        TMaybe<TFunction> Function;
        TMaybe<THint> Hint;
        TMaybe<TObject> Object;
        TMaybe<TCluster> Cluster;
        TMaybe<TColumn> Column;
        bool Binding = false;

        TQuotation IsQuoted;
        TEditRange EditRange;
    };

    // TODO(YQL-19747): Make it thread-safe to make ISqlCompletionEngine thread-safe.
    class ILocalSyntaxAnalysis {
    public:
        using TPtr = THolder<ILocalSyntaxAnalysis>;

        virtual ~ILocalSyntaxAnalysis() = default;
        virtual TLocalSyntaxContext Analyze(TCompletionInput input) = 0;
    };

    ILocalSyntaxAnalysis::TPtr MakeLocalSyntaxAnalysis(
        TLexerSupplier lexer,
        const THashSet<TString>& ignoredRules,
        const THashMap<TString, THashSet<TString>>& disabledPreviousByToken,
        const THashMap<TString, THashSet<TString>>& forcedPreviousByToken);

} // namespace NSQLComplete