@@ -40,6 +40,19 @@ Token &Token::operator=(Token &&other)
4040 return *this ;
4141}
4242
43+ QStringView Token::getTokenTypeString (TokenType type)
44+ {
45+ size_t index = static_cast <size_t >(type);
46+
47+ // Ensure the index is valid and within range
48+ if (index >= tokenTypeStrings.size ()) {
49+ throw std::out_of_range (" Invalid TokenType index" );
50+ }
51+
52+ // Return the string representation of the token type
53+ return QStringView (tokenTypeStrings[index].toString ());
54+ }
55+
4356// Returns the type of the token
4457Token::TokenType Token::getType () const {
4558 return type;
@@ -60,26 +73,13 @@ int Token::getColumn() const {
6073 return column;
6174}
6275
63- // Converts the token type to its string representation using a lookup table
64- QStringView Token::getTokenTypeString () const {
65- size_t index = static_cast <size_t >(type);
66-
67- // Ensure the index is valid and within range
68- if (index >= tokenTypeStrings.size ()) {
69- throw std::out_of_range (" Invalid TokenType index" );
70- }
71-
72- // Return the string representation of the token type
73- return QStringView (tokenTypeStrings[index].toString ());
74- }
75-
7676// Converts the token to a detailed string representation
7777QString Token::toString (bool includePosition) const {
7878 QString str;
7979 QTextStream stream (&str);
8080
8181 // Include the token type and value
82- stream << value << " , " << getTokenTypeString ();
82+ stream << value << " , " << getTokenTypeString (type );
8383
8484 // Optionally include the token's line and column positions
8585 if (includePosition) {
@@ -96,18 +96,23 @@ QString Token::toHTMLString(bool includePosition) const
9696 QTextStream stream (&str);
9797
9898 // Use light gray for token value
99+ if (value == " <" ){
100+ stream << " <span style='color:#c0c0c0;'><" << value << " ></span>, " ;
101+
102+ } else {
99103 stream << " <span style='color:#c0c0c0;'>" << value << " </span>, " ;
104+ }
100105
101106 // Conditional formatting for token type
102107 if (type == TokenType::UNKNOWN) {
103108 // Bright red for unknown type
104- stream << " <span style='color:#ff5555; font-weight:bold;'>" << getTokenTypeString () << " </span>" ;
109+ stream << " <span style='color:#ff5555; font-weight:bold;'>" << getTokenTypeString (type ) << " </span>" ;
105110 } else if (type != TokenType::NUMBER && type != TokenType::IDENTIFIER && type != TokenType::UNKNOWN) {
106111 // Light blue for reserved types
107- stream << " <span style='color:#5555ff; font-weight:bold;'>" << getTokenTypeString () << " </span>" ;
112+ stream << " <span style='color:#5555ff; font-weight:bold;'>" << getTokenTypeString (type ) << " </span>" ;
108113 } else {
109114 // Default white for known types
110- stream << " <span style='color:#ffffff; font-weight:bold;'>" << getTokenTypeString () << " </span>" ;
115+ stream << " <span style='color:#ffffff; font-weight:bold;'>" << getTokenTypeString (type ) << " </span>" ;
111116 }
112117
113118 // Optionally include the token's line and column positions
0 commit comments