2025-06-08 16:42:16 +01:00

42 lines
927 B
C++

#pragma once
#include "object.hh"
#include <cstdint>
#include <string>
#include <utility>
enum class TokenType : uint8_t {
// Single-character tokens.
LEFT_PAREN, RIGHT_PAREN, LEFT_BRACE, RIGHT_BRACE,
COMMA, DOT, MINUS, PLUS, SEMICOLON, SLASH, STAR,
// One or two character tokens.
BANG, BANG_EQUAL,
EQUAL, EQUAL_EQUAL,
GREATER, GREATER_EQUAL,
LESS, LESS_EQUAL,
// Literals.
IDENTIFIER, STRING, NUMBER,
// Keywords.
AND, CLASS, ELSE, FALSE, FUN, FOR, IF, NIL, OR,
PRINT, RETURN, SUPER, THIS, TRUE, VAR, WHILE,
EOFILE,
};
struct Token {
Token(TokenType type, std::string lexeme, Object literal, int line)
: type{type}, lexeme{std::move(lexeme)}, literal{literal}, line{line}
{};
TokenType type;
std::string lexeme;
Object literal;
int line;
};
std::ostream &operator<<(std::ostream &os, const TokenType &type);
std::ostream &operator<<(std::ostream &os, const Token &token);