Defined Lexer::Token::LogStr
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include <Lexer.h>
|
||||
#include <Token.h>
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
namespace LXC::Lexer
|
||||
{
|
||||
// Constructor to assign the members of the token class //
|
||||
@@ -29,8 +31,60 @@ namespace LXC::Lexer
|
||||
contents = nullptr;
|
||||
}
|
||||
|
||||
// Helper macro for converting type to string //
|
||||
#define TOKEN_TYPE_CASE(type) case type: return #type;
|
||||
|
||||
static constexpr const char* TokenTypeToCStr(Token::TokenType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
// All the different types of tokens //
|
||||
TOKEN_TYPE_CASE(Token::Add);
|
||||
TOKEN_TYPE_CASE(Token::Sub);
|
||||
TOKEN_TYPE_CASE(Token::Mul);
|
||||
TOKEN_TYPE_CASE(Token::Div);
|
||||
TOKEN_TYPE_CASE(Token::Mod);
|
||||
|
||||
TOKEN_TYPE_CASE(Token::For);
|
||||
TOKEN_TYPE_CASE(Token::While);
|
||||
TOKEN_TYPE_CASE(Token::If);
|
||||
TOKEN_TYPE_CASE(Token::Else_If);
|
||||
TOKEN_TYPE_CASE(Token::Else);
|
||||
TOKEN_TYPE_CASE(Token::Return);
|
||||
|
||||
TOKEN_TYPE_CASE(Token::String_Literal);
|
||||
TOKEN_TYPE_CASE(Token::Num_Literal);
|
||||
TOKEN_TYPE_CASE(Token::Identifier);
|
||||
|
||||
TOKEN_TYPE_CASE(Token::Assign);
|
||||
TOKEN_TYPE_CASE(Token::Close_bracket);
|
||||
TOKEN_TYPE_CASE(Token::Open_bracket);
|
||||
TOKEN_TYPE_CASE(Token::Close_brace);
|
||||
TOKEN_TYPE_CASE(Token::Open_brace);
|
||||
TOKEN_TYPE_CASE(Token::Close_paren);
|
||||
TOKEN_TYPE_CASE(Token::Open_paren);
|
||||
TOKEN_TYPE_CASE(Token::Comma);
|
||||
|
||||
TOKEN_TYPE_CASE(Token::End_of_file);
|
||||
TOKEN_TYPE_CASE(Token::UNDEFINED);
|
||||
|
||||
// When the case has not been defined yet //
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
std::string LXC::Lexer::Token::LogStr() const
|
||||
{
|
||||
return std::string("CALL LogStr() function");
|
||||
// Output stream to log to //
|
||||
std::ostringstream os;
|
||||
os << std::setw(15) << std::left << TokenTypeToCStr(type) << " | ";
|
||||
|
||||
if (contents != nullptr)
|
||||
os << '"' << contents << '"';
|
||||
else
|
||||
os << "EMPTY";
|
||||
|
||||
return os.str();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user