#ifndef sk_LEXER_HPP #define sk_LEXER_HPP #include "commons.hpp" #include "Node.hpp" #include "Logger.hpp" namespace sk { SK_ERROR(lexical_error); struct ScanInfo { bool ok = false; size_t cursor = 0; std::string repr; NodeType type; }; using scanner_t = std::function; class Lexer { public: explicit Lexer(std::filesystem::path path, Logger& logger); virtual ~Lexer(); Loc loc() const { return m_loc; } void scan(std::string const& source); std::shared_ptr next(); private: Loc m_loc; Logger& m_logger; std::string m_source; size_t m_cursor = 0; std::vector m_scanners; void skip_spaces(); ScanInfo scan_int(); ScanInfo scan_float(); ScanInfo scan_text(std::string const& text, NodeType type, bool value); ScanInfo scan_keyword(std::string const& text, NodeType type, bool value); ScanInfo scan_string(); }; } #endif