From 1145b97c4c1d82af1db1334f50b248ca203f7d88 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sat, 6 Jul 2024 17:36:58 +0100 Subject: [PATCH] Token to_string now include source name and is printed error style So instead of the previous weird format, we have the format ::: which also allows me to quickly go to that token via Emacs' (compile). --- src/lexer.cpp | 4 ++-- src/lexer.hpp | 2 +- src/main.cpp | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lexer.cpp b/src/lexer.cpp index 31abc31..be7c44a 100644 --- a/src/lexer.cpp +++ b/src/lexer.cpp @@ -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(); } diff --git a/src/lexer.hpp b/src/lexer.hpp index c9e0945..6725238 100644 --- a/src/lexer.hpp +++ b/src/lexer.hpp @@ -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, diff --git a/src/main.cpp b/src/main.cpp index 106b495..cced77d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,7 +70,7 @@ int main(int argc, const char *argv[]) string source_str; string_view original; string_view src; - vector tokens, preprocessed_tokens; + vector 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(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());