summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/proto_parser/antlr4/proto_parser.cpp
blob: 2d29d0a6ffd0faa4adfc499b048b1183e7a2836b (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
#include "proto_parser.h"
#include <yql/essentials/parser/proto_ast/antlr4/proto_ast_antlr4.h>
#include <yql/essentials/parser/proto_ast/gen/v1_antlr4/SQLv1Antlr4Lexer.h>
#include <yql/essentials/parser/proto_ast/gen/v1_antlr4/SQLv1Antlr4Parser.h>
#include <yql/essentials/utils/yql_panic.h>

namespace NSQLTranslationV1 {

namespace {

class TParser: public NSQLTranslation::IParser {
public:
    explicit TParser(bool isAmbuguityError, bool isAmbiguityDebugging)
        : IsAmbiguityError_(isAmbuguityError)
        , IsAmbiguityDebugging_(isAmbiguityDebugging)
    {
    }

    google::protobuf::Message* Parse(
        const TString& query, const TString& queryName, NProtoAST::IErrorCollector& err,
        google::protobuf::Arena* arena) final {
        YQL_ENSURE(arena);
        NProtoAST::TProtoASTBuilder4<
            NALPDefaultAntlr4::SQLv1Antlr4Parser,
            NALPDefaultAntlr4::SQLv1Antlr4Lexer>
            builder(query, queryName, arena, IsAmbiguityError_, IsAmbiguityDebugging_);
        return builder.BuildAST(err);
    }

private:
    bool IsAmbiguityError_;
    bool IsAmbiguityDebugging_;
};

class TFactory: public NSQLTranslation::IParserFactory {
public:
    explicit TFactory(bool isAmbuguityError, bool isAmbiguityDebugging)
        : IsAmbiguityError_(isAmbuguityError)
        , IsAmbiguityDebugging_(isAmbiguityDebugging)
    {
    }

    std::unique_ptr<NSQLTranslation::IParser> MakeParser() const final {
        return std::make_unique<TParser>(IsAmbiguityError_, IsAmbiguityDebugging_);
    }

private:
    bool IsAmbiguityError_;
    bool IsAmbiguityDebugging_;
};

} // namespace

NSQLTranslation::TParserFactoryPtr MakeAntlr4ParserFactory(
    bool isAmbiguityError,
    bool isAmbiguityDebugging)
{
    return MakeIntrusive<TFactory>(isAmbiguityError, isAmbiguityDebugging);
}

} // namespace NSQLTranslationV1