From 6bcedaf743c9483a17858a2539045cdbded30227 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Wed, 19 Jun 2019 13:33:01 +0200 Subject: [PATCH] Add backslash to invalid control character error, made pretty error messages use 1-based line index --- src/Diagnostics/DiagnosticsHolder.cpp | 2 +- src/Parser/Lexer.cpp | 4 ++-- tests/integration/DiagnosticsTests.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Diagnostics/DiagnosticsHolder.cpp b/src/Diagnostics/DiagnosticsHolder.cpp index 41c245e..0139081 100644 --- a/src/Diagnostics/DiagnosticsHolder.cpp +++ b/src/Diagnostics/DiagnosticsHolder.cpp @@ -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()); diff --git a/src/Parser/Lexer.cpp b/src/Parser/Lexer.cpp index 3773bbb..39b5b8d 100644 --- a/src/Parser/Lexer.cpp +++ b/src/Parser/Lexer.cpp @@ -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 { diff --git a/tests/integration/DiagnosticsTests.cpp b/tests/integration/DiagnosticsTests.cpp index 1ed9e31..11c79e5 100644 --- a/tests/integration/DiagnosticsTests.cpp +++ b/tests/integration/DiagnosticsTests.cpp @@ -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; }