lexer.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "lexer.h"
  2. #include <yql/essentials/public/issue/yql_issue.h>
  3. #include <yql/essentials/parser/proto_ast/antlr3/proto_ast_antlr3.h>
  4. #include <yql/essentials/parser/proto_ast/collect_issues/collect_issues.h>
  5. #include <yql/essentials/parser/proto_ast/gen/v0/SQLLexer.h>
  6. #if defined(_tsan_enabled_)
  7. #include <util/system/mutex.h>
  8. #endif
  9. namespace NALP {
  10. extern ANTLR_UINT8* SQLParserTokenNames[];
  11. }
  12. namespace NSQLTranslationV0 {
  13. namespace {
  14. #if defined(_tsan_enabled_)
  15. TMutex SanitizerSQLTranslationMutex;
  16. #endif
  17. using NSQLTranslation::ILexer;
  18. class TV0Lexer : public ILexer {
  19. public:
  20. TV0Lexer() = default;
  21. bool Tokenize(const TString& query, const TString& queryName, const TTokenCallback& onNextToken, NYql::TIssues& issues, size_t maxErrors) override {
  22. NYql::TIssues newIssues;
  23. #if defined(_tsan_enabled_)
  24. TGuard<TMutex> grd(SanitizerSQLTranslationMutex);
  25. #endif
  26. NSQLTranslation::TErrorCollectorOverIssues collector(newIssues, maxErrors, "");
  27. NProtoAST::TLexerTokensCollector3<NALP::SQLLexer> tokensCollector(query, (const char**)NALP::SQLParserTokenNames, queryName);
  28. tokensCollector.CollectTokens(collector, onNextToken);
  29. issues.AddIssues(newIssues);
  30. return !AnyOf(newIssues.begin(), newIssues.end(), [](auto issue) { return issue.GetSeverity() == NYql::ESeverity::TSeverityIds_ESeverityId_S_ERROR; });
  31. }
  32. };
  33. } // namespace
  34. NSQLTranslation::ILexer::TPtr MakeLexer() {
  35. return NSQLTranslation::ILexer::TPtr(new TV0Lexer);
  36. }
  37. } // namespace NSQLTranslationV1