Handle invalid chars better, and do small cleanups around error output. (#657)

This adds a test for invalid characters (that would've failed before, because the printed char isn't escaped). Not sure if there's a good way to test the PrintDiagnostic code, as it appears to occur on bison parser errors, which I'm just not sure how to trigger.
This commit is contained in:
Jon Meow
2021-07-20 12:04:45 -07:00
committed by GitHub
parent 1ddb1a264a
commit 368fc0063c
6 changed files with 23 additions and 14 deletions
@@ -7,15 +7,14 @@
#include <cstring>
#include <iostream>
#include "executable_semantics/tracing_flag.h"
// Writes a syntax error diagnostic, containing message, for the input file at
// the given line, to standard error.
auto Carbon::ParseAndLexContext::PrintDiagnostic(const std::string& message,
int line_num) -> void {
// TODO: Do we really want this to be fatal? It makes the comment and the
// name a lie, and renders some of the other yyparse() result propagation code
// moot.
std::cerr << input_file_name << ":" << line_num << ": " << message
<< std::endl;
exit(-1); // TODO: do we really want this here? It makes the comment and the
// name a lie, and renders some of the other yyparse() result
// propagation code moot.
exit(-1);
}