// // Created by lenfrex on 2023/4/13. // #ifndef LEXER_CPP_LEXER_H #define LEXER_CPP_LEXER_H #include #include #include "Token.h" class Lexer { public: explicit Lexer(char *code); void lexAll(); [[nodiscard]] const std::vector &getResults() const; private: char *buffer; std::vector results = std::vector(); bool stop = false; int currLine = 0; int currPos = 0; void lexNumber(Token &token); void lexIdentifier(Token &token); static std::string copyAsString(const char *sourceStart, int length); void setToken(Token &token, TokenType type, const char *source, int length); void setToken(Token &token, TokenType type, const std::string &content, int length); void move(int offset); void lexToken(Token &token); }; #endif //LEXER_CPP_LEXER_H