commit d94e7bd2f595340a2b16190588467ae5ac4c87bb
parent 03c3373ef23dd9fb047d66c8adab3a77ba758c93
Author: Mohammad-Reza Nabipoor <m.nabipoor@yahoo.com>
Date: Fri, 28 Aug 2020 17:09:59 +0430
kaleidoscope_tokens.hpp: Add to_string for Token type
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/kaleidoscope_tokens.hpp b/kaleidoscope_tokens.hpp
@@ -4,6 +4,7 @@
#include "kaleidoscope_lexer.hpp"
#include <cstddef>
+#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
@@ -28,6 +29,23 @@ struct Token
friend bool operator!=(const Token& x, const Token& y) { return !(x == y); }
};
+std::string
+to_string(const Token& t)
+{
+ std::ostringstream oss;
+
+ // clang-format on
+
+ oss << "Token{"
+ << "\n kal::TkType::" << kal::TKTYPE_STR[static_cast<int>(t.type)]
+ << ",\n " << t.bpos << ",\n " << t.epos << ",\n \"" << t.str << '"'
+ << ",\n " << t.dbl << "}\n";
+
+ // clang-format off
+
+ return oss.str();
+}
+
inline TkType
token_type(const Token& t)
{