Add backslash to invalid control character error, made pretty error messages use 1-based line index
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-06-19 13:33:01 +02:00
parent 8541085b27
commit 6bcedaf743
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
3 changed files with 4 additions and 4 deletions

View File

@ -103,7 +103,7 @@ std::string DiagnosticsHolder::GetFullErrorMessage(Diagnostic diagnostic) {
auto startPos = diagnostic.GetStartPosition();
auto line = this -> GetLineFromPosition(startPos);
auto linePos = startPos - this ->GetStartPositionForLine(line);
stream << " (" << line << ", " << linePos << ") ";
stream << " (" << line + 1 << ", " << linePos + 1 << ") ";
auto unformatted = ErrorMessages.find(diagnostic.GetCode());
if (unformatted != ErrorMessages.end()){
stream << PrettyDiagnostic(unformatted->second, diagnostic.GetArguments());

View File

@ -304,9 +304,9 @@ namespace Porygon::Parser {
if (ControlCharacters.find(c) != ControlCharacters.end()) {
stream << ControlCharacters.at(c);
} else {
auto v = string(1, c).c_str();
auto v = ("\\" + string(1, c)).c_str();
this->ScriptData->Diagnostics->LogError(Diagnostics::DiagnosticCode::InvalidStringControlCharacter,
start + 1 + i, 1, {v});
start + i, 2, {v});
stream << c;
}
} else {

View File

@ -48,7 +48,7 @@ TEST_CASE( "Get full diagnostic message", "[integration]" ) {
REQUIRE(script->Diagnostics -> HasErrors());
auto diags = script->Diagnostics -> GetDiagnostics();
auto msg = script -> Diagnostics -> GetFullErrorMessage(diags[0]);
REQUIRE(msg == "[Error] (1, 2) 'x' is not a valid control character.");
REQUIRE(msg == "[Error] (2, 2) '\\x' is not a valid control character.");
delete script;
}