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

55 lines
1.0 KiB
C++

#ifndef sk_LEXER_HPP
#define sk_LEXER_HPP
#include "commons.hpp"
#include "Node.hpp"
#include "Logger.hpp"
namespace sk
{
SK_ERROR(lexical_error);
struct ScanInfo {
bool ok = false;
size_t cursor = 0;
std::string repr;
NodeType type;
};
using scanner_t = std::function<ScanInfo()>;
class Lexer
{
public:
explicit Lexer(std::filesystem::path path, Logger& logger);
virtual ~Lexer();
Loc loc() const { return m_loc; }
void scan(std::string const& source);
std::shared_ptr<Node> next();
private:
Loc m_loc;
Logger& m_logger;
std::string m_source;
size_t m_cursor = 0;
std::vector<scanner_t> m_scanners;
void skip_spaces();
ScanInfo scan_int();
ScanInfo scan_float();
ScanInfo scan_text(std::string const& text,
NodeType type,
bool value);
ScanInfo scan_keyword(std::string const& text,
NodeType type,
bool value);
ScanInfo scan_string();
};
}
#endif