Files
dbc/core/dbc_parser.h
T
2026-10-20 13:38:21 -04:00

70 lines
2.1 KiB
C++

/**
* @file dbc_parser.h
* @brief DBC file parser and interpretation options.
*
* Created: 2026-03-13
* Author: Deeaitch (Dim. Himro)
*
* Licensed under the MIT License.
* See LICENSE file in the project root for full license text.
*/
#ifndef DBC_PARSER_H
#define DBC_PARSER_H
#include <string>
#include "dbc_diagnostic.h"
/** Explicit interpretation applied to extended frames in this file. */
struct DbcParserOptions {
bool enableJ1939 = false; /**< Derive J1939 PGNs from extended CAN IDs. */
};
/**
* @brief Minimal DBC parser.
*
* Supports:
* - BO_
* - SG_
* - CM_ BO_
* - CM_ SG_
* - basic M / mN multiplexing
* - VAL_ signal value descriptions
* - BA_DEF_, BA_DEF_DEF_, BA_ typed attributes, frame format and cycle time
*
* Frame/signal comments support multiline quoted text and deferred references.
*
* Reports unsupported statements as warnings, except SG_MUL_VAL_ which is
* an error. VERSION, NS_, BS_, BU_ and NS_ symbol declarations stay quiet.
*/
class DbcParser {
public:
/** @brief Create a parser with explicit extended-frame interpretation options. */
explicit DbcParser(DbcParserOptions options = {}) : options(options) {}
/**
* @brief Parse DBC file.
* @param filePath Path to input file.
* @return Parsed database.
* @throws std::runtime_error on file or parse errors.
* Line parse errors include the file path and one-based line number.
* Duplicate normalized CAN IDs of the same frame type and duplicate signal
* names within a frame are rejected at the repeated definition's line.
*/
DbcDatabase ParseFile(const std::string &filePath) const;
/**
* @brief Parse with warnings and a structured first error instead of throwing.
* @return Valid database with diagnostics; empty database on error.
* File errors use line zero; statement errors use physical one-based lines.
* Warnings indicate ignored syntax and possible incomplete decoding.
*/
DbcParseResult ParseFileWithDiagnostics(const std::string &filePath) const;
private:
DbcParserOptions options;
};
#endif /* DBC_PARSER_H */