Consolidate ParseTree onto PrettyStackTraceFunction (#3002)

The function is already in use by semantics, it's intended to be cleaner
than having to write a dedicated printer class.
This commit is contained in:
Jon Ross-Perkins
2023-07-21 01:09:41 +00:00
committed by GitHub
parent e51f971bce
commit c8e02c14ce
4 changed files with 30 additions and 32 deletions
+19
View File
@@ -442,4 +442,23 @@ auto ParserContext::EmitExpectedDeclarationSemiOrDefinition(
expected_kind);
}
auto ParserContext::PrintForStackDump(llvm::raw_ostream& output) const -> void {
output << "Parser stack:\n";
for (int i = 0; i < static_cast<int>(state_stack_.size()); ++i) {
const auto& entry = state_stack_[i];
output << "\t" << i << ".\t" << entry.state;
PrintTokenForStackDump(output, entry.token);
}
output << "\tcursor\tposition_";
PrintTokenForStackDump(output, *position_);
}
auto ParserContext::PrintTokenForStackDump(llvm::raw_ostream& output,
TokenizedBuffer::Token token) const
-> void {
output << " @ " << tokens_->GetLineNumber(tokens_->GetLine(token)) << ":"
<< tokens_->GetColumnNumber(token) << ": token " << token << " : "
<< tokens_->GetKind(token) << "\n";
}
} // namespace Carbon