MalachScript/src/Parser/Lexer/LexToken.hpp

60 lines
1.8 KiB
C++
Raw Normal View History

#ifndef ELOHIMSCRIPT_LEXTOKEN_HPP
#define ELOHIMSCRIPT_LEXTOKEN_HPP
#include <memory>
2020-10-04 15:15:28 +00:00
#include <utility>
#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; }
};
2020-10-04 15:15:28 +00:00
class IntegerLiteral : public LexTokenImpl<LexTokenKind::IntegerLiteral> {
uint64_t _value;
public:
2020-10-04 15:15:28 +00:00
IntegerLiteral(uint64_t value) : _value(value) {}
[[nodiscard]] uint64_t GetValue() const noexcept { return _value; }
};
2020-10-04 15:15:28 +00:00
class FloatLiteral : public LexTokenImpl<LexTokenKind::FloatLiteral> {
double _value;
public:
2020-10-04 15:15:28 +00:00
FloatLiteral(double value) : _value(value) {}
[[nodiscard]] double GetValue() const noexcept { return _value; }
};
2020-10-04 15:15:28 +00:00
class StringLiteral : public LexTokenImpl<LexTokenKind::StringLiteral> {
std::u8string _value;
public:
StringLiteral(std::u8string value) : _value(std::move(value)) {}
[[nodiscard]] const std::u8string& GetValue() const noexcept { return _value; }
};
2020-10-04 16:30:53 +00:00
class IdentifierToken : public LexTokenImpl<LexTokenKind::Identifier>{
std::u8string _value;
public:
IdentifierToken(std::u8string value) : _value(std::move(value)) {}
[[nodiscard]] const std::u8string& GetValue() const noexcept { return _value; }
};
}
#endif // ELOHIMSCRIPT_LEXTOKEN_HPP