#ifndef muz_LEXER_HPP #define muz_LEXER_HPP #include "commons.hpp" #include "Node.hpp" namespace muz { MUZ_ERROR(lexical_error); struct TokenInfo { size_t position; NodeType type; std::string value; }; /** * Scan a text and gives corresponding tokens. * @see Node **/ class Lexer { public: explicit Lexer(); virtual ~Lexer(); void scan(std::string const& source); std::vector> all(); std::shared_ptr next(); private: std::string m_source; size_t m_cursor = 0; int m_line = 1; std::vector m_seps; void skip_spaces(); std::optional next_word(); bool is_sep(size_t index) const; bool is_num(std::string const& word) const; bool is_ident(std::string const& word) const; bool is_dir_ident(std::string const& word) const; }; } #endif