#include #ifndef PORYGONLANG_TOKEN_HPP #define PORYGONLANG_TOKEN_HPP #include #include #include "TokenKind.hpp" #include "../Utilities/HashedString.hpp" using namespace std; class IToken{ const unsigned int _position; const unsigned int _length; public: virtual const TokenKind GetKind() const = 0; IToken(unsigned int position, unsigned int length) : _position(position), _length(length) { } const unsigned int GetStartPosition() const{ return _position; } const unsigned int GetEndPosition() const{ return _position + _length - 1; } const unsigned int GetLength() const{ return _length; } virtual ~IToken() = default; }; class SimpleToken : public IToken{ const TokenKind _kind; public: explicit SimpleToken(TokenKind kind, unsigned int position, unsigned int length) : IToken(position, length), _kind(kind) { } const TokenKind GetKind() const final{ return _kind; } }; class IntegerToken : public IToken{ const long _value; public: explicit IntegerToken(long value, unsigned int position, unsigned int length) : IToken(position, length), _value(value) { } const TokenKind GetKind() const final{ return TokenKind::Integer; } const long GetValue() const{ return _value; } }; class FloatToken : public IToken{ const double _value; public: explicit FloatToken(double value, unsigned int position, unsigned int length) : IToken(position, length), _value(value) { } const TokenKind GetKind() const final{ return TokenKind::Float; } const double GetValue() const{ return _value; } }; class StringToken : public IToken{ const string _value; public: explicit StringToken(string value, unsigned int position, unsigned int length) : IToken(position, length), _value(std::move(value)) { } const TokenKind GetKind() const final{ return TokenKind::String; } const string& GetValue() const{ return _value; } }; class IdentifierToken : public IToken{ const HashedString _value; public: explicit IdentifierToken(const HashedString value, unsigned int position, unsigned int length) : IToken(position, length), _value(value) { } const TokenKind GetKind() const final{ return TokenKind::Identifier; } const HashedString GetValue() const{ return _value; } }; #endif //PORYGONLANG_TOKEN_HPP