#ifndef jk_LEXER_HPP #define jk_LEXER_HPP #include "commons.hpp" #include "Logger.hpp" #include "Node.hpp" namespace jk { JK_ERROR(lexical_error); struct ScanInfo { size_t cursor; NodeType type; std::string repr; }; using scanner_t = std::function()>; class Lexer { public: explicit Lexer(Logger& logger, Loc const& loc); virtual ~Lexer(); Loc loc() const { return m_loc; } void scan(std::string const& source); std::shared_ptr next(); private: Logger& m_logger; Loc m_loc; size_t m_cursor; std::string m_source; std::vector m_scanners; bool more(size_t index) const; char at(size_t index) const; void skip_spaces(); std::optional scan_int() const; std::optional scan_text(NodeType type, std::string const& text, bool has_value) const; std::optional scan_ident() const; }; } #endif