2019-05-22 11:24:28 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2019-05-18 18:35:51 +00:00
|
|
|
#ifndef PORYGONLANG_TOKEN_HPP
|
|
|
|
#define PORYGONLANG_TOKEN_HPP
|
|
|
|
|
2019-05-19 12:26:21 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <string>
|
2019-05-18 18:35:51 +00:00
|
|
|
#include "TokenKind.hpp"
|
2019-05-19 12:26:21 +00:00
|
|
|
using namespace std;
|
2019-05-18 18:35:51 +00:00
|
|
|
|
|
|
|
class IToken{
|
2019-05-19 14:11:16 +00:00
|
|
|
unsigned int Position;
|
|
|
|
unsigned int Length;
|
2019-05-18 18:35:51 +00:00
|
|
|
public:
|
|
|
|
virtual TokenKind GetKind() = 0;
|
2019-05-19 14:11:16 +00:00
|
|
|
|
|
|
|
IToken(unsigned int position, unsigned int length){
|
|
|
|
Position = position;
|
|
|
|
Length = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GetStartPosition(){
|
|
|
|
return Position;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GetEndPosition(){
|
|
|
|
return Position + Length - 1;
|
|
|
|
}
|
2019-05-20 15:45:03 +00:00
|
|
|
|
|
|
|
unsigned int GetLength(){
|
|
|
|
return Length;
|
|
|
|
}
|
2019-05-21 10:59:15 +00:00
|
|
|
|
|
|
|
virtual ~IToken(){
|
|
|
|
|
|
|
|
}
|
2019-05-18 18:35:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SimpleToken : public IToken{
|
|
|
|
public:
|
|
|
|
TokenKind Kind;
|
|
|
|
|
2019-05-19 14:11:16 +00:00
|
|
|
explicit SimpleToken(TokenKind type, unsigned int position, unsigned int length) : IToken(position, length){
|
2019-05-18 18:35:51 +00:00
|
|
|
Kind = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenKind GetKind() override{
|
|
|
|
return Kind;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class IntegerToken : public IToken{
|
|
|
|
public:
|
|
|
|
long Value;
|
|
|
|
|
2019-05-19 14:11:16 +00:00
|
|
|
explicit IntegerToken(long value, unsigned int position, unsigned int length) : IToken(position, length){
|
2019-05-18 18:35:51 +00:00
|
|
|
Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenKind GetKind() override{
|
|
|
|
return TokenKind::Integer;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-19 10:49:26 +00:00
|
|
|
class FloatToken : public IToken{
|
|
|
|
public:
|
|
|
|
double Value;
|
|
|
|
|
2019-05-19 14:11:16 +00:00
|
|
|
explicit FloatToken(double value, unsigned int position, unsigned int length) : IToken(position, length){
|
2019-05-19 10:49:26 +00:00
|
|
|
Value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenKind GetKind() override{
|
|
|
|
return TokenKind::Float;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-22 11:24:28 +00:00
|
|
|
class StringToken : public IToken{
|
|
|
|
public:
|
|
|
|
string Value;
|
|
|
|
|
|
|
|
explicit StringToken(string value, unsigned int position, unsigned int length) : IToken(position, length){
|
|
|
|
Value = std::move(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenKind GetKind() override{
|
|
|
|
return TokenKind::String;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-19 12:26:21 +00:00
|
|
|
class IdentifierToken : public IToken{
|
|
|
|
public:
|
|
|
|
string Value;
|
|
|
|
|
2019-05-19 14:11:16 +00:00
|
|
|
explicit IdentifierToken(string value, unsigned int position, unsigned int length) : IToken(position, length){
|
2019-05-19 12:26:21 +00:00
|
|
|
Value = std::move(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
TokenKind GetKind() override{
|
|
|
|
return TokenKind::Identifier;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-18 18:35:51 +00:00
|
|
|
#endif //PORYGONLANG_TOKEN_HPP
|