#ifndef wg_LEXER_HPP #define wg_LEXER_HPP #include "commons.hpp" #include "Node.hpp" #include "Loc.hpp" namespace wg { struct ScanInfo { size_t cursor; NodeType type; std::string repr; }; using scanner_t = std::function()>; class Lexer { public: explicit Lexer(); virtual ~Lexer(); void scan(std::string const& source); std::shared_ptr next(); std::vector> all(); private: std::string m_source; size_t m_cursor = 0; Loc m_loc; std::vector m_scanners; std::vector m_seps; void add_text(std::string const& text, NodeType node, bool has_value=false); void add_keyword(std::string const& text, NodeType node, bool has_value=false); bool is_sep(size_t index) const; void skip_spaces(); std::optional scan_text(std::string const& text, NodeType type, bool has_value) const; std::optional scan_keyword(std::string const& text, NodeType type, bool has_value) const; std::optional scan_ident() const; std::optional scan_int() const; }; } #endif