lexer.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <util/generic/string.h>
  3. #include <util/generic/vector.h>
  4. #include <util/stream/output.h>
  5. #include <functional>
  6. namespace NYql {
  7. class TIssues;
  8. }
  9. namespace NSQLTranslation {
  10. struct TParsedToken {
  11. // TODO: TStringBuf for Name & Content
  12. TString Name;
  13. TString Content;
  14. // Position of first token byte/symbol
  15. // When antlr3 lexer is used, LinePos is a position as in a byte array,
  16. // but when antlr4 lexer is used, LinePos is a position as in a symbol array,
  17. ui32 Line = 0; // starts from 1
  18. ui32 LinePos = 0; // starts from 0
  19. };
  20. class ILexer {
  21. public:
  22. using TPtr = THolder<ILexer>;
  23. using TTokenCallback = std::function<void(TParsedToken&& token)>;
  24. virtual bool Tokenize(const TString& query, const TString& queryName, const TTokenCallback& onNextToken, NYql::TIssues& issues, size_t maxErrors) = 0;
  25. virtual ~ILexer() = default;
  26. };
  27. using TParsedTokenList = TVector<TParsedToken>;
  28. IOutputStream& OutputTokens(IOutputStream& out, TParsedTokenList::const_iterator begin, TParsedTokenList::const_iterator end);
  29. bool Tokenize(ILexer& lexer, const TString& query, const TString& queryName, TParsedTokenList& tokens, NYql::TIssues& issues, size_t maxErrors);
  30. }