49 lines
1014 B
C++
49 lines
1014 B
C++
#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> node = nullptr;
|
|
size_t cursor = 0;
|
|
};
|
|
|
|
using scanner = std::function<ScanInfo(void)>;
|
|
|
|
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<Node> 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<std::shared_ptr<Node>> m_nodes;
|
|
std::vector<scanner> m_scanners;
|
|
|
|
ScanInfo scan_int() const;
|
|
ScanInfo scan_text(std::string const& text,
|
|
NodeType type,
|
|
bool value=false) const;
|
|
};
|
|
}
|
|
|
|
#endif
|