#ifndef roza_LEXER_HPP #define roza_LEXER_HPP #include "commons.hpp" #include "Node.hpp" #include "SrcLoc.hpp" #include "StatusLog.hpp" namespace roza { struct ScanInfo { std::shared_ptr node = nullptr; size_t cursor = 0; }; using scanner = std::function; class Lexer { public: explicit Lexer(StatusLog& log, SrcLoc loc); virtual ~Lexer(); SrcLoc loc() const { return m_loc; } size_t size() const { return m_nodes.size(); } bool is_at_end() const; void scan(std::string const& source); void skip_blanks(); std::shared_ptr get_or_nullptr(size_t index) const; private: StatusLog& m_log; SrcLoc m_loc; std::string m_source; size_t m_cursor = 0; std::vector> m_nodes; std::vector m_scanners; bool is_sep(size_t index) const; ScanInfo scan_int() const; ScanInfo scan_text(std::string const& text, NodeType type, bool value=false) const; ScanInfo scan_keyword(std::string const& keyword, NodeType type, bool value=false) const; ScanInfo scan_ident() const; }; } #endif