sapphire/src/Lexer.h
2022-06-02 18:25:01 +02:00

46 lines
996 B
C++

#pragma once
#include "Token.h"
#include <memory>
#include <vector>
#include <string>
#include <array>
typedef std::vector<Token> TokenStream;
#define TYPE_COUNT 14
class Lexer
{
private:
Location loc;
Location prev_loc;
int advance();
int rewind();
char current_char;
int index;
Lexer(const std::string& fname);
std::string current_line_text;
std::string previous_line_text;
std::string current_lexed_text;
std::string recalculate_current_line(const std::string& text);
Token create_string();
Token create_number();
Token create_identifier();
bool is_in_string(const std::string& string, const char& character);
public:
static const std::array<std::string,TYPE_COUNT> types;
~Lexer();
TokenStream lex(const std::string& text);
static std::shared_ptr<Lexer> make_lexer(const std::string& fname);
static void assign_parent_location(std::shared_ptr<Lexer>& lexer, const std::shared_ptr<Location>& loc);
};