mirror of
https://github.com/YosysHQ/yosys
synced 2025-06-08 15:13:24 +00:00
liberty: Error on unclosed curly braces
This is an indication that the liberty file was truncated, which shouldn't be silently ignored.
This commit is contained in:
parent
418e795235
commit
ce74404890
2 changed files with 22 additions and 7 deletions
|
@ -436,6 +436,9 @@ void LibertyParser::report_unexpected_token(int tok)
|
|||
eReport += "'.";
|
||||
error(eReport);
|
||||
break;
|
||||
case EOF:
|
||||
error("Unexpected end of file");
|
||||
break;
|
||||
default:
|
||||
eReport = "Unexpected token: ";
|
||||
eReport += static_cast<char>(tok);
|
||||
|
@ -484,7 +487,7 @@ void LibertyParser::parse_vector_range(int tok)
|
|||
}
|
||||
}
|
||||
|
||||
LibertyAst *LibertyParser::parse()
|
||||
LibertyAst *LibertyParser::parse(bool top_level)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
|
@ -498,7 +501,13 @@ LibertyAst *LibertyParser::parse()
|
|||
while ((tok == 'n') || (tok == ';'))
|
||||
tok = lexer(str);
|
||||
|
||||
if (tok == '}' || tok < 0)
|
||||
if (tok == EOF) {
|
||||
if (top_level)
|
||||
return NULL;
|
||||
report_unexpected_token(tok);
|
||||
}
|
||||
|
||||
if (tok == '}')
|
||||
return NULL;
|
||||
|
||||
if (tok != 'v') {
|
||||
|
@ -571,12 +580,18 @@ LibertyAst *LibertyParser::parse()
|
|||
}
|
||||
|
||||
if (tok == '{') {
|
||||
bool terminated = false;
|
||||
while (1) {
|
||||
LibertyAst *child = parse();
|
||||
if (child == NULL)
|
||||
LibertyAst *child = parse(false);
|
||||
if (child == NULL) {
|
||||
terminated = true;
|
||||
break;
|
||||
}
|
||||
ast->children.push_back(child);
|
||||
}
|
||||
if (!terminated) {
|
||||
report_unexpected_token(EOF);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue