This commit is contained in:
deeaitch committed 2026-10-14 10:32:44 -04:00
1 parent 0b05152bcf
commit d87c100398
9 files changed
+265 -65

No files matched your search

+44 -4
View File
@@ -19,6 +19,36 @@
#include <utility>
namespace {
// Read through the closing unescaped quote, preserving comment whitespace.
void ReadCommentLines(std::ifstream &input, std::string &statement,
std::size_t &lineNumber) {
bool inQuote = false;
bool escaped = false;
std::string part = statement;
for (;;) {
for (const char character: part) {
if (escaped) {
escaped = false;
} else if (inQuote && character == '\\') {
escaped = true;
} else if (character == '"') {
if (inQuote)
return;
inQuote = true;
}
}
if (!inQuote || !std::getline(input, part))
return;
++lineNumber;
if (!part.empty() && part.back() == '\r')
part.pop_back();
statement += '\n';
statement += part;
// A physical newline cannot escape the next line's first character.
escaped = false;
}
}
DbcDiagnosticCode StatementErrorCode(const std::string &keyword) {
if (keyword == "SG_MUL_VAL_")
return DbcDiagnosticCode::UnsupportedStatement;
@@ -59,6 +89,10 @@ DbcParseResult DbcParser::ParseFileWithDiagnostics(const std::string &filePath)
std::string line;
while (std::getline(input, line)) {
++lineNumber;
if (!line.empty() && line.back() == '\r')
line.pop_back();
const std::string rawLine = line;
const std::size_t statementLine = lineNumber;
line = dbc_detail::TrimText(line);
if (line.empty())
continue;
@@ -74,19 +108,24 @@ DbcParseResult DbcParser::ParseFileWithDiagnostics(const std::string &filePath)
continue; // NS_ lists syntax symbols; BO_, SG_, BS_ and BU_ end the list.
inNamespace = keyword == "NS_" || keyword == "NS_:";
if (keyword == "CM_") {
line = rawLine;
ReadCommentLines(input, line, lineNumber);
}
try {
context.lineNumber = lineNumber;
context.lineNumber = statementLine;
if (!dispatcher.Dispatch(line, context)) {
result.diagnostics.push_back({DbcDiagnosticSeverity::Warning,
DbcDiagnosticCode::UnsupportedStatement,
filePath, lineNumber,
filePath, statementLine,
"Unsupported statement '" + keyword +
"' is ignored; decoding or metadata may be incomplete."});
"' is ignored; decoding or metadata may be incomplete."});
}
} catch (const std::exception &error) {
result.diagnostics.push_back({DbcDiagnosticSeverity::Error,
StatementErrorCode(keyword), filePath,
lineNumber, error.what()});
statementLine, error.what()});
return result;
}
}
@@ -99,6 +138,7 @@ DbcParseResult DbcParser::ParseFileWithDiagnostics(const std::string &filePath)
}
try {
context.ResolveComments(filePath);
context.ResolveValueDescriptions(filePath);
context.ValidateMultiplexing(filePath);
} catch (const DbcDiagnosticError &error) {