2020-10-04 14:33:12 +00:00
|
|
|
#ifndef ELOHIMSCRIPT_LEXTOKEN_HPP
|
|
|
|
#define ELOHIMSCRIPT_LEXTOKEN_HPP
|
|
|
|
|
|
|
|
#include <memory>
|
2020-10-04 15:15:28 +00:00
|
|
|
#include <utility>
|
2020-10-04 14:33:12 +00:00
|
|
|
#include "LexTokenKind.hpp"
|
|
|
|
|
|
|
|
namespace ElohimScript::Parser {
|
|
|
|
class LexToken {
|
|
|
|
friend class Lexer;
|
|
|
|
|
|
|
|
std::unique_ptr<const LexToken> _next;
|
2020-10-04 17:38:13 +00:00
|
|
|
TextSpan _span;
|
2020-10-04 14:33:12 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-04 17:38:13 +00:00
|
|
|
LexToken(TextSpan span) : _span(span) {}
|
2020-10-04 14:33:12 +00:00
|
|
|
virtual ~LexToken() = default;
|
|
|
|
[[nodiscard]] virtual LexTokenKind GetKind() const noexcept = 0;
|
|
|
|
[[nodiscard]] const std::unique_ptr<const LexToken>& GetNext() const noexcept { return _next; }
|
2020-10-04 17:38:13 +00:00
|
|
|
[[nodiscard]] const TextSpan& GetSpan() const noexcept { return _span; }
|
2020-10-04 14:33:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <LexTokenKind kind> class LexTokenImpl : public LexToken {
|
|
|
|
public:
|
2020-10-04 17:38:13 +00:00
|
|
|
LexTokenImpl(TextSpan span) : LexToken(span){};
|
2020-10-04 14:33:12 +00:00
|
|
|
[[nodiscard]] LexTokenKind GetKind() const noexcept override { return kind; }
|
|
|
|
};
|
|
|
|
|
2020-10-04 15:15:28 +00:00
|
|
|
class IntegerLiteral : public LexTokenImpl<LexTokenKind::IntegerLiteral> {
|
2020-10-04 14:33:12 +00:00
|
|
|
uint64_t _value;
|
|
|
|
|
|
|
|
public:
|
2020-10-04 17:38:13 +00:00
|
|
|
IntegerLiteral(TextSpan span, uint64_t value)
|
|
|
|
: LexTokenImpl<LexTokenKind::IntegerLiteral>(span), _value(value) {}
|
2020-10-04 14:33:12 +00:00
|
|
|
[[nodiscard]] uint64_t GetValue() const noexcept { return _value; }
|
|
|
|
};
|
|
|
|
|
2020-10-04 15:15:28 +00:00
|
|
|
class FloatLiteral : public LexTokenImpl<LexTokenKind::FloatLiteral> {
|
2020-10-04 14:33:12 +00:00
|
|
|
double _value;
|
|
|
|
|
|
|
|
public:
|
2020-10-04 17:38:13 +00:00
|
|
|
FloatLiteral(TextSpan span, double value) : LexTokenImpl<LexTokenKind::FloatLiteral>(span), _value(value) {}
|
2020-10-04 14:33:12 +00:00
|
|
|
[[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:
|
2020-10-04 17:38:13 +00:00
|
|
|
StringLiteral(TextSpan span, std::u8string value)
|
|
|
|
: LexTokenImpl<LexTokenKind::StringLiteral>(span), _value(std::move(value)) {}
|
2020-10-04 15:15:28 +00:00
|
|
|
[[nodiscard]] const std::u8string& GetValue() const noexcept { return _value; }
|
|
|
|
};
|
2020-10-04 16:30:53 +00:00
|
|
|
|
2020-10-04 17:38:13 +00:00
|
|
|
class IdentifierToken : public LexTokenImpl<LexTokenKind::Identifier> {
|
|
|
|
std::u8string _value;
|
2020-10-04 16:30:53 +00:00
|
|
|
|
|
|
|
public:
|
2020-10-04 17:38:13 +00:00
|
|
|
IdentifierToken(TextSpan span, std::u8string value)
|
|
|
|
: LexTokenImpl<LexTokenKind::Identifier>(span), _value(std::move(value)) {}
|
2020-10-04 16:30:53 +00:00
|
|
|
[[nodiscard]] const std::u8string& GetValue() const noexcept { return _value; }
|
|
|
|
};
|
2020-10-04 14:33:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // ELOHIMSCRIPT_LEXTOKEN_HPP
|