1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 04:17:35 +00:00

LibCpp: Modify Token::to_string() to include more information

Token::to_string() now includes not only the token's type, but also its
text and span in the document.
This commit is contained in:
Itamar 2021-05-21 14:39:42 +03:00 committed by Andreas Kling
parent cdea9f5339
commit 0c9db38e8f
4 changed files with 18 additions and 12 deletions

View file

@ -21,12 +21,7 @@ Parser::Parser(const StringView& program, const String& filename, Preprocessor::
if constexpr (CPP_DEBUG) {
dbgln("Tokens:");
for (auto& token : m_tokens) {
StringView text;
if (token.start().line != token.end().line || token.start().column > token.end().column)
text = {};
else
text = text_of_token(token);
dbgln("{} {}:{}-{}:{} ({})", token.to_string(), token.start().line, token.start().column, token.end().line, token.end().column, text);
dbgln("{}", token.to_string());
}
}
}
@ -930,7 +925,7 @@ Optional<size_t> Parser::index_of_token_at(Position pos) const
void Parser::print_tokens() const
{
for (auto& token : m_tokens) {
dbgln("{}", token.to_string());
outln("{}", token.to_string());
}
}