mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 12:51:04 +01:00
Error: track message and prefix/location separately. (#1529)
This allows us to combine multiple Errors together without repeating the prefix information. Also fixes several cases where two "COMPILATION ERROR" prefixes would be prepended to the same message when errors with prefixes and locations were produced by the lexer and parser.
This commit is contained in:
@@ -4,23 +4,20 @@
|
||||
|
||||
#include "explorer/syntax/parse_and_lex_context.h"
|
||||
|
||||
#include "explorer/common/error_builders.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto ParseAndLexContext::RecordSyntaxError(const std::string& message,
|
||||
bool prefix_with_newline)
|
||||
-> Parser::symbol_type {
|
||||
// Optionally adds a newline in trace mode because trace prints an incomplete
|
||||
// line "Reading a token: " which can prevent LIT from finding expected
|
||||
// patterns.
|
||||
// TODO: support formatting of `SourceLocation` instances with formatv().
|
||||
std::string full_message;
|
||||
llvm::raw_string_ostream(full_message)
|
||||
<< (prefix_with_newline && parser_debug() ? "\n" : "")
|
||||
<< "COMPILATION ERROR: " << source_loc() << ": " << message;
|
||||
error_messages_.push_back(full_message);
|
||||
auto ParseAndLexContext::RecordSyntaxError(Error error) -> Parser::symbol_type {
|
||||
errors_.push_back(std::move(error));
|
||||
|
||||
// TODO: use `YYerror` token once bison is upgraded to at least 3.5.
|
||||
return Parser::make_END_OF_FILE(current_token_position);
|
||||
}
|
||||
|
||||
auto ParseAndLexContext::RecordSyntaxError(const std::string& message)
|
||||
-> Parser::symbol_type {
|
||||
return RecordSyntaxError(CompilationError(source_loc()) << message);
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user