This repository has been archived on 2023-09-10. You can view files and clone it, but cannot push or open issues/pull-requests.
joko/lib/Lexer.hpp

46 lines
776 B
C++

#ifndef jk_LEXER_HPP
#define jk_LEXER_HPP
#include "commons.hpp"
#include "Logger.hpp"
#include "Node.hpp"
namespace jk
{
JK_ERROR(lexical_error);
struct ScanInfo {
size_t cursor;
NodeType type;
std::string repr;
};
using scanner_t = std::function<std::optional<ScanInfo>()>;
class Lexer
{
public:
explicit Lexer(Logger& logger, Loc const& loc);
virtual ~Lexer();
void scan(std::string const& source);
std::shared_ptr<Node> next();
private:
Logger& m_logger;
Loc m_loc;
size_t m_cursor;
std::string m_source;
std::vector<scanner_t> m_scanners;
bool more(size_t index) const;
char current(size_t index) const;
void skip_spaces();
std::optional<ScanInfo> scan_int() const;
};
}
#endif