blob: 16140bc614ebe6f89ddc5ef1c49eb2d5fcafcbfc (
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
|
#include "function.h"
#include "narrowing_visitor.h"
namespace NSQLComplete {
namespace {
class TVisitor: public TSQLv1NarrowingVisitor {
public:
TVisitor(antlr4::TokenStream* tokens, size_t cursorPosition)
: TSQLv1NarrowingVisitor(tokens, cursorPosition)
{
}
std::any visit(antlr4::tree::ParseTree* tree) override {
if (IsEnclosing(tree)) {
return TSQLv1NarrowingVisitor::visit(tree);
}
return {};
}
std::any visitTable_ref(SQLv1::Table_refContext* ctx) override {
auto* function = ctx->an_id_expr();
auto* lparen = ctx->TOKEN_LPAREN();
if (function == nullptr || lparen == nullptr) {
return {};
}
if (CursorPosition() <= TextInterval(lparen).b) {
return {};
}
return function->getText();
}
};
} // namespace
TMaybe<TString> EnclosingFunction(
SQLv1::Sql_queryContext* ctx,
antlr4::TokenStream* tokens,
size_t cursorPosition) {
std::any result = TVisitor(tokens, cursorPosition).visit(ctx);
if (!result.has_value()) {
return Nothing();
}
return std::any_cast<std::string>(result);
}
} // namespace NSQLComplete
|