Skip to content

Commit e914afd

Browse files
author
Avi SZYCHTER
committed
Better syntax error/warning handling at the end of the parsing
1 parent ba3577b commit e914afd

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/parsing/DBCParser.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88

99
using namespace DBCParser;
1010

11-
CANSignal parseSignal(Tokenizer& tokenizer);
12-
CANFrame parseFrame(Tokenizer& tokenizer);
13-
std::set<std::string> parseECUs(Tokenizer& tokenizer);
14-
void parseNewSymbols(Tokenizer& tokenizer);
15-
void addBADirective(Tokenizer& tokenizer,
16-
CANDatabase& db);
17-
void addComment(Tokenizer& tokenizer, CANDatabase& db);
18-
void parseSignalChoices(Tokenizer& tokenizer,
19-
CANDatabase& db);
20-
2111
static std::string VERSION_TOKEN = "VERSION";
2212
static std::string NS_SECTION_TOKEN = "NS_";
2313
static std::string BIT_TIMING_TOKEN = "BS_";
@@ -380,6 +370,16 @@ CANDatabase DBCParser::fromTokenizer(const std::string& name, Tokenizer& tokeniz
380370
parseValDescSection(tokenizer, result);
381371

382372
while(!is_token(tokenizer, Token::Eof)) {
373+
// We have a syntax error because we have a token which does not
374+
// represent any command.
375+
if(!is_dbc_token(tokenizer.getCurrentToken())) {
376+
throw_error("Syntax error",
377+
"Unexpected token \"" + tokenizer.getCurrentToken().image + "\"",
378+
tokenizer.lineCount());
379+
}
380+
381+
// We have a valid DBC instruction, but we ignore it because
382+
// it is not in a valid position.
383383
warning("Unexpected token " + tokenizer.getCurrentToken().image +
384384
" at line " + std::to_string(tokenizer.lineCount()) +
385385
" (maybe is it an unsupported instruction ? maybe is it a misplaced instruction ?)",

0 commit comments

Comments
 (0)