44 lines
809 B
C++
44 lines
809 B
C++
|
#ifndef muz_LEXER_HPP
|
||
|
#define muz_LEXER_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
#include "Node.hpp"
|
||
|
|
||
|
namespace muz
|
||
|
{
|
||
|
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<std::shared_ptr<Node>> all();
|
||
|
std::shared_ptr<Node> next();
|
||
|
|
||
|
private:
|
||
|
std::string m_source;
|
||
|
size_t m_cursor = 0;
|
||
|
std::vector<char> m_seps;
|
||
|
|
||
|
std::optional<TokenInfo> 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
|