Token to_string now include source name and is printed error style

So instead of the previous weird format, we have the format
<source_name>:<line>:<column>: <TYPE> which also allows me to quickly
go to that token via Emacs' (compile).
This commit is contained in:
2024-07-06 17:36:58 +01:00
parent f9acb23671
commit 1145b97c4c
3 changed files with 5 additions and 6 deletions

View File

@@ -556,13 +556,13 @@ namespace Lexer
std::string to_string(const Token &t)
{
std::stringstream stream;
stream << to_string(t.type);
stream << t.source_name << ":" << t.line << ":" << t.column << ": "
<< to_string(t.type);
if (t.operand_type != Token::OperandType::NIL)
stream << "[" << to_string(t.operand_type) << "]";
if (t.content != "")
stream << "(`" << t.content << "`)";
stream << "@" << t.line << ", " << t.column;
return stream.str();
}

View File

@@ -114,7 +114,7 @@ namespace Lexer
Err();
Err(Type type, size_t col, size_t line, std::string_view source_name);
Err(Type type, size_t col, size_t line, std::string_view source_name = "");
};
Err tokenise_buffer(std::string_view source_name, std::string_view content,

View File

@@ -70,7 +70,7 @@ int main(int argc, const char *argv[])
string source_str;
string_view original;
string_view src;
vector<Token *> tokens, preprocessed_tokens;
vector<Token *> tokens;
Lex_Err lerr;
// Highest scoped variable cut off point
@@ -87,7 +87,7 @@ int main(int argc, const char *argv[])
src = string_view{source_str};
lerr = tokenise_buffer(source_name, src, tokens);
if (lerr.type != Lexer ::Err::Type::OK)
if (lerr.type != Lex_Err::Type::OK)
{
cerr << lerr << endl;
ret = 255 - static_cast<int>(lerr.type);
@@ -95,7 +95,6 @@ int main(int argc, const char *argv[])
}
else
{
#if VERBOSE >= 1
printf("[%sLEXER%s]: %lu bytes -> %lu tokens\n", TERM_GREEN, TERM_RESET,
source_str.size(), tokens.size());