summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/ide/completion/configuration.cpp
blob: dce8496f8652e8b2f83beb775da03d901e6860b4 (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
#include "configuration.h"

#include <yql/essentials/sql/v1/ide/completion/syntax/grammar.h>

namespace NSQLComplete {

TConfiguration MakeConfiguration(THashSet<TString> allowedStmts) {
    allowedStmts.emplace("sql_stmt");

    TConfiguration config;
    for (const std::string& name : GetSqlGrammar().GetAllRules()) {
        if (name.ends_with("_stmt") && !allowedStmts.contains(name)) {
            config.IgnoredRules_.emplace(name);
        }
    }
    return config;
}

TConfiguration MakeYDBConfiguration() {
    TConfiguration config;
    config.IgnoredRules_ = {
        "use_stmt",
        "import_stmt",
        "export_stmt",
    };
    return config;
}

TConfiguration MakeYQLConfiguration() {
    auto config = MakeConfiguration(/* allowedStmts = */ {
        "lambda_stmt",
        "declare_stmt",
        "import_stmt",
        "export_stmt",
        "do_stmt",
        "pragma_stmt",
        "select_stmt",
        "select_unparenthesized_stmt",
        "into_table_stmt",
        "values_stmt",
        "drop_table_stmt",
        "define_action_or_subquery_stmt",
        "if_stmt",
        "for_stmt",
        "use_stmt",
        "subselect_stmt",
        "named_nodes_stmt",
        "commit_stmt",
    });

    config.DisabledPreviousByToken_ = {};

    config.ForcedPreviousByToken_ = {
        {"PARALLEL", {}},
        {"TABLESTORE", {}},
        {"FOR", {"EVALUATE"}},
        {"IF", {"EVALUATE"}},
        {"EXTERNAL", {"USING"}},
    };

    return config;
}

} // namespace NSQLComplete