blob: b938eaf06315243b905dac9f4259f7bc38d1ca95 (
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
|
#include "evaluate.h"
namespace NSQLComplete {
namespace {
class TVisitor: public SQLv1Antlr4BaseVisitor {
public:
explicit TVisitor(const TEnvironment* env)
: Env_(env)
{
}
std::any visitBind_parameter(SQLv1::Bind_parameterContext* ctx) override {
std::string id = GetId(ctx);
if (const NYT::TNode* node = Env_->Parameters.FindPtr(id)) {
return *node;
}
return defaultResult();
}
std::any defaultResult() override {
return NYT::TNode();
}
private:
std::string GetId(SQLv1::Bind_parameterContext* ctx) const {
if (auto* x = ctx->an_id_or_type()) {
return x->getText();
} else if (auto* x = ctx->TOKEN_TRUE()) {
return x->getText();
} else if (auto* x = ctx->TOKEN_FALSE()) {
return x->getText();
} else {
Y_ABORT("You should change implementation according grammar changes");
}
}
const TEnvironment* Env_;
};
NYT::TNode EvaluateG(antlr4::ParserRuleContext* ctx, const TEnvironment& env) {
return std::any_cast<NYT::TNode>(TVisitor(&env).visit(ctx));
}
} // namespace
NYT::TNode Evaluate(SQLv1::Bind_parameterContext* ctx, const TEnvironment& env) {
return EvaluateG(ctx, env);
}
} // namespace NSQLComplete
|