mirror of
https://github.com/YosysHQ/yosys
synced 2025-05-11 17:54:44 +00:00
Factor report_unexpected_token out into its own function.
This commit is contained in:
parent
314842d2a0
commit
0a6d9f4dc9
2 changed files with 30 additions and 40 deletions
|
@ -332,24 +332,8 @@ int LibertyParser::lexer(std::string &str)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
LibertyAst *LibertyParser::parse()
|
void LibertyParser::report_unexpected_token(int tok)
|
||||||
{
|
{
|
||||||
std::string str;
|
|
||||||
|
|
||||||
int tok = lexer(str);
|
|
||||||
|
|
||||||
// there are liberty files in the wild that
|
|
||||||
// have superfluous ';' at the end of
|
|
||||||
// a { ... }. We simply ignore a ';' here.
|
|
||||||
// and get to the next statement.
|
|
||||||
|
|
||||||
while ((tok == 'n') || (tok == ';'))
|
|
||||||
tok = lexer(str);
|
|
||||||
|
|
||||||
if (tok == '}' || tok < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (tok != 'v') {
|
|
||||||
std::string eReport;
|
std::string eReport;
|
||||||
switch(tok)
|
switch(tok)
|
||||||
{
|
{
|
||||||
|
@ -368,10 +352,33 @@ LibertyAst *LibertyParser::parse()
|
||||||
error(eReport);
|
error(eReport);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error();
|
eReport = "Unexpected token: ";
|
||||||
|
eReport += static_cast<char>(tok);
|
||||||
|
error(eReport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LibertyAst *LibertyParser::parse()
|
||||||
|
{
|
||||||
|
std::string str;
|
||||||
|
|
||||||
|
int tok = lexer(str);
|
||||||
|
|
||||||
|
// there are liberty files in the wild that
|
||||||
|
// have superfluous ';' at the end of
|
||||||
|
// a { ... }. We simply ignore a ';' here.
|
||||||
|
// and get to the next statement.
|
||||||
|
|
||||||
|
while ((tok == 'n') || (tok == ';'))
|
||||||
|
tok = lexer(str);
|
||||||
|
|
||||||
|
if (tok == '}' || tok < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (tok != 'v') {
|
||||||
|
report_unexpected_token(tok);
|
||||||
|
}
|
||||||
|
|
||||||
LibertyAst *ast = new LibertyAst;
|
LibertyAst *ast = new LibertyAst;
|
||||||
ast->id = str;
|
ast->id = str;
|
||||||
|
|
||||||
|
@ -460,25 +467,7 @@ LibertyAst *LibertyParser::parse()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tok != 'v') {
|
if (tok != 'v') {
|
||||||
std::string eReport;
|
report_unexpected_token(tok);
|
||||||
switch(tok)
|
|
||||||
{
|
|
||||||
case 'n':
|
|
||||||
continue;
|
|
||||||
case '[':
|
|
||||||
case ']':
|
|
||||||
case '}':
|
|
||||||
case '{':
|
|
||||||
case '\"':
|
|
||||||
case ':':
|
|
||||||
eReport = "Unexpected '";
|
|
||||||
eReport += static_cast<char>(tok);
|
|
||||||
eReport += "'.";
|
|
||||||
error(eReport);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
error();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ast->args.push_back(arg);
|
ast->args.push_back(arg);
|
||||||
}
|
}
|
||||||
|
@ -495,7 +484,7 @@ LibertyAst *LibertyParser::parse()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
error();
|
report_unexpected_token(tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast;
|
return ast;
|
||||||
|
|
|
@ -105,6 +105,7 @@ namespace Yosys
|
||||||
*/
|
*/
|
||||||
int lexer(std::string &str);
|
int lexer(std::string &str);
|
||||||
|
|
||||||
|
void report_unexpected_token(int tok);
|
||||||
LibertyAst *parse();
|
LibertyAst *parse();
|
||||||
void error() const;
|
void error() const;
|
||||||
void error(const std::string &str) const;
|
void error(const std::string &str) const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue