Fixed error line number mismatch when including files or using comments

This commit is contained in:
WerWolv 2021-01-08 17:14:35 +01:00
parent 205f3a327e
commit fd98db1b70

View File

@ -66,7 +66,12 @@ namespace hex::lang {
if (!preprocessedInclude.has_value()) if (!preprocessedInclude.has_value())
throw this->m_error; throw this->m_error;
output += preprocessedInclude.value(); auto content = preprocessedInclude.value();
std::replace(content.begin(), content.end(), '\n', ' ');
std::replace(content.begin(), content.end(), '\r', ' ');
output += content;
delete[] buffer; delete[] buffer;
@ -145,15 +150,17 @@ namespace hex::lang {
offset += 1; offset += 1;
} else if (code.substr(offset, 2) == "/*") { } else if (code.substr(offset, 2) == "/*") {
while (code.substr(offset, 2) != "*/" && offset < code.length()) { while (code.substr(offset, 2) != "*/" && offset < code.length()) {
if (code[offset] == '\n') if (code[offset] == '\n') {
output += '\n';
lineNumber++; lineNumber++;
}
offset += 1; offset += 1;
} }
offset += 2; offset += 2;
if (offset >= code.length()) if (offset >= code.length())
throwPreprocessorError("unterminated comment", lineNumber); throwPreprocessorError("unterminated comment", lineNumber - 1);
} }
if (code[offset] == '\n') if (code[offset] == '\n')