sapphire/src/Token.h

84 lines
1.5 KiB
C
Raw Normal View History

#pragma once
#include "Location.h"
#include <string>
#include <vector>
enum TokenType
{
TT_Identifier,
TT_Number,
TT_Float,
TT_Keyword,
TT_String,
TT_Plus,
TT_Minus,
TT_Mul,
TT_Div,
TT_At,
TT_Equal,
TT_LessThan,
TT_GreaterThan,
TT_LParen,
TT_RParen,
TT_LBracket,
TT_RBracket,
TT_Semicolon,
TT_LoadedString,
TT_EOF,
TT_Null,
TT_Equals,
TT_GTE,
TT_LTE,
TT_Period,
TT_Comma,
TT_Path,
TT_Exclamation,
TT_NEqual
};
extern const std::string token_strings[];
struct Token
{
TokenType tk_type;
int int_value;
std::string string_value;
float float_value;
Location loc;
Token(const TokenType& type);
Token(const TokenType& type, const Location& location);
Token(const TokenType& type, const int& val, const Location& location);
Token(const TokenType& type, const std::string& val, const Location& location);
Token(const TokenType& type, const std::string& val);
Token(const TokenType& type, const float& val, const Location& location);
~Token();
std::string to_string() const;
std::string line() const;
static Token make_with_line(const Token& origin, const std::string& line_text);
void operator=(const Token& other);
static void erase(Token& tk);
Token copy_with_new_type(const TokenType& type);
static bool match_token_types(const std::vector<Token>& a, const std::vector<Token>& b, int count);
private:
std::string line_text;
};
typedef std::vector<Token> TokenStream;