aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/proto_parser/antlr3_ansi/proto_parser.cpp
blob: 102f5e187e19af62a1288198906958dc9e3f34dd (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
#include "proto_parser.h"
#include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h>
#include <yql/essentials/parser/proto_ast/gen/v1_ansi/SQLv1Lexer.h>
#include <yql/essentials/parser/proto_ast/gen/v1_ansi/SQLv1Parser.h>
#include <yql/essentials/utils/yql_panic.h>

namespace NSQLTranslationV1 {

namespace {

class TParser : public NSQLTranslation::IParser {
public:
    google::protobuf::Message* Parse(
    const TString& query, const TString& queryName, NProtoAST::IErrorCollector& err,
        google::protobuf::Arena* arena) final {
        YQL_ENSURE(arena);
        NProtoAST::TProtoASTBuilder3<NALPAnsi::SQLv1Parser, NALPAnsi::SQLv1Lexer> builder(query, queryName, arena);
        return builder.BuildAST(err);
    }
};

class TFactory: public NSQLTranslation::IParserFactory {
public:
    std::unique_ptr<NSQLTranslation::IParser> MakeParser() const final {
        return std::make_unique<TParser>();
    }
};

}

NSQLTranslation::TParserFactoryPtr MakeAntlr3AnsiParserFactory() {
    return MakeIntrusive<TFactory>();
}

}