More user friendly output in case of Identifier and Token keywords

This commit is contained in:
Alex Beregszaszi 2018-05-04 13:26:23 +01:00
parent 882248ce75
commit c7ee649d80

View File

@ -68,23 +68,24 @@ void ParserBase::expectToken(Token::Value _value, bool _advance)
Token::Value tok = m_scanner->currentToken(); Token::Value tok = m_scanner->currentToken();
if (tok != _value) if (tok != _value)
{ {
string got; auto tokenName = [this](Token::Value _token)
if (Token::isReservedKeyword(tok))
got = "reserved keyword '" + Token::friendlyName(tok) + "'";
else if (Token::isElementaryTypeName(tok)) //for the sake of accuracy in reporting
{ {
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken(); if (_token == Token::Identifier)
got = "'" + elemTypeName.toString() + "'"; return string("identifier");
} else if (_token == Token::EOS)
else return string("end of source");
got = "'" + Token::friendlyName(tok) + "'"; else if (Token::isReservedKeyword(_token))
return string("reserved keyword '") + Token::friendlyName(_token) + "'";
else if (Token::isElementaryTypeName(_token)) //for the sake of accuracy in reporting
{
ElementaryTypeNameToken elemTypeName = m_scanner->currentElementaryTypeNameToken();
return string("'") + elemTypeName.toString() + "'";
}
else
return string("'") + Token::friendlyName(_token) + "'";
};
fatalParserError( fatalParserError(string("Expected ") + tokenName(_value) + string(" but got ") + tokenName(tok));
string("Expected '") +
Token::friendlyName(_value) +
string("' but got ") +
got
);
} }
if (_advance) if (_advance)
m_scanner->next(); m_scanner->next();