mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Add a FatalUserError macro to help print user-caused errors. (#668)
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "common/check.h"
|
||||
#include "executable_semantics/common/error.h"
|
||||
#include "executable_semantics/common/tracing_flag.h"
|
||||
#include "executable_semantics/syntax/parse_and_lex_context.h"
|
||||
#include "executable_semantics/syntax/parser.h"
|
||||
@@ -21,9 +23,8 @@ auto parse(const std::string& input_file_name)
|
||||
-> std::variant<AST, SyntaxErrorCode> {
|
||||
yyin = fopen(input_file_name.c_str(), "r");
|
||||
if (yyin == nullptr) {
|
||||
std::cerr << "Error opening '" << input_file_name
|
||||
<< "': " << std::strerror(errno) << std::endl;
|
||||
exit(1);
|
||||
FatalUserError() << "Error opening '" << input_file_name
|
||||
<< "': " << std::strerror(errno);
|
||||
}
|
||||
|
||||
std::optional<AST> parsed_input = std::nullopt;
|
||||
@@ -38,11 +39,8 @@ auto parse(const std::string& input_file_name)
|
||||
return syntax_error_code;
|
||||
}
|
||||
|
||||
if (parsed_input == std::nullopt) {
|
||||
std::cerr << "Internal error: parser validated syntax yet didn't produce "
|
||||
"an AST.\n";
|
||||
exit(1);
|
||||
}
|
||||
CHECK(parsed_input != std::nullopt)
|
||||
<< "parser validated syntax yet didn't produce an AST.";
|
||||
return *parsed_input;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user