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:
Richard Smith
2022-07-26 15:08:19 -07:00
committed by GitHub
parent 856a5c4536
commit 7a67715ac5
16 changed files with 177 additions and 52 deletions
+5 -4
View File
@@ -29,10 +29,11 @@ static auto ParseImpl(yyscan_t scanner, Nonnull<Arena*> arena,
}
if (auto syntax_error_code = parser(); syntax_error_code != 0) {
const std::string error_message = context.error_messages().empty()
? "Unknown parser error"
: context.error_messages()[0];
return Error(error_message);
auto errors = context.take_errors();
if (errors.empty()) {
return Error("Unknown parser erroor");
}
return std::move(errors.front());
}
// Return parse results.