76 std::ifstream input(filePath.c_str());
77 if (!input.is_open()) {
78 result.
diagnostics.push_back({DbcDiagnosticSeverity::Error,
79 DbcDiagnosticCode::FileOpenError, filePath, 0U,
80 "Failed to open DBC file: " + filePath});
88 bool inNamespace =
false;
89 std::size_t lineNumber = 0U;
91 while (std::getline(input, line)) {
93 if (!line.empty() && line.back() ==
'\r')
95 const std::string rawLine = line;
96 const std::size_t statementLine = lineNumber;
97 line = dbc_detail::TrimText(line);
101 std::istringstream tokens(line);
103 std::string argument;
105 const bool hasArgument =
static_cast<bool>(tokens >> argument);
106 if (inNamespace && !hasArgument && keyword !=
"BO_" && keyword !=
"SG_" &&
107 keyword !=
"BS_" && keyword !=
"BS_:" &&
108 keyword !=
"BU_" && keyword !=
"BU_:")
110 inNamespace = keyword ==
"NS_" || keyword ==
"NS_:";
112 if (keyword ==
"CM_") {
114 ReadCommentLines(input, line, lineNumber);
118 context.lineNumber = statementLine;
119 if (!dispatcher.
Dispatch(line, context)) {
120 result.
diagnostics.push_back({DbcDiagnosticSeverity::Warning,
121 DbcDiagnosticCode::UnsupportedStatement,
122 filePath, statementLine,
123 "Unsupported statement '" + keyword +
124 "' is ignored; decoding or metadata may be incomplete."});
126 }
catch (
const std::exception &error) {
127 result.
diagnostics.push_back({DbcDiagnosticSeverity::Error,
128 StatementErrorCode(keyword), filePath,
129 statementLine, error.what()});
134 if (input.bad() || !input.eof()) {
135 result.
diagnostics.push_back({DbcDiagnosticSeverity::Error,
136 DbcDiagnosticCode::FileReadError, filePath, 0U,
137 "Failed to read DBC file: " + filePath});
142 context.ResolveComments(filePath);
143 context.ResolveValueDescriptions(filePath);
144 context.ValidateMultiplexing(filePath);
145 context.ResolveAttributes(filePath, result.
diagnostics);
150 result.
database = std::move(database);