MalachScript/src/Parser/Lexer/LexToken.hpp

43 lines
1.2 KiB
C++

#ifndef ELOHIMSCRIPT_LEXTOKEN_HPP
#define ELOHIMSCRIPT_LEXTOKEN_HPP
#include <memory>
#include "LexTokenKind.hpp"
namespace ElohimScript::Parser {
class LexToken {
friend class Lexer;
std::unique_ptr<const LexToken> _next;
public:
virtual ~LexToken() = default;
[[nodiscard]] virtual LexTokenKind GetKind() const noexcept = 0;
[[nodiscard]] const std::unique_ptr<const LexToken>& GetNext() const noexcept { return _next; }
};
template <LexTokenKind kind> class LexTokenImpl : public LexToken {
public:
LexTokenImpl() = default;
[[nodiscard]] LexTokenKind GetKind() const noexcept override { return kind; }
};
class IntegerToken : public LexTokenImpl<LexTokenKind::IntegerToken> {
uint64_t _value;
public:
IntegerToken(uint64_t value) : _value(value) {}
[[nodiscard]] uint64_t GetValue() const noexcept { return _value; }
};
class FloatToken : public LexTokenImpl<LexTokenKind::FloatToken> {
double _value;
public:
FloatToken(double value) : _value(value) {}
[[nodiscard]] double GetValue() const noexcept { return _value; }
};
}
#endif // ELOHIMSCRIPT_LEXTOKEN_HPP