aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/lexer/antlr3/lexer.cpp
blob: e2d23d1503d9a2ede9dd3bf9983600f7673c2f38 (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
#include "lexer.h"
#include <yql/essentials/parser/proto_ast/gen/v1/SQLv1Lexer.h>
#include <yql/essentials/public/issue/yql_issue.h>
#include <yql/essentials/parser/proto_ast/collect_issues/collect_issues.h>
#include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h>

namespace NALPDefault {
extern ANTLR_UINT8 *SQLv1ParserTokenNames[];
}

namespace NSQLTranslationV1 {

namespace {

class TLexer: public NSQLTranslation::ILexer {
public:
    bool Tokenize(const TString& query, const TString& queryName, const TTokenCallback& onNextToken, NYql::TIssues& issues, size_t maxErrors) final {
        NYql::TIssues newIssues;
        NSQLTranslation::TErrorCollectorOverIssues collector(newIssues, maxErrors, queryName);
        NProtoAST::TLexerTokensCollector3<NALPDefault::SQLv1Lexer> tokensCollector(query, (const char**)NALPDefault::SQLv1ParserTokenNames, queryName);
        tokensCollector.CollectTokens(collector, onNextToken);
        issues.AddIssues(newIssues);
        return !AnyOf(newIssues.begin(), newIssues.end(), [](auto issue) { return issue.GetSeverity() == NYql::ESeverity::TSeverityIds_ESeverityId_S_ERROR; });
    }
};

class TFactory: public NSQLTranslation::ILexerFactory {
public:
    THolder<NSQLTranslation::ILexer> MakeLexer() const final {
        return MakeHolder<TLexer>();
    }
};

}

NSQLTranslation::TLexerFactoryPtr MakeAntlr3LexerFactory() {
    return MakeIntrusive<TFactory>();
}

}