provide general hex-literal error message, fixes #1802

dummy
This commit is contained in:
Lazaridis 2018-10-01 00:27:16 +03:00
parent 4ab2e03be3
commit 4bcd89105c
4 changed files with 16 additions and 7 deletions

View File

@ -1554,6 +1554,9 @@ ASTPointer<Expression> Parser::parsePrimaryExpression()
expression = nodeFactory.createNode<TupleExpression>(components, isArray);
break;
}
case Token::IllegalHex:
fatalParserError("Expected even number of hex-nibbles within double-quotes.");
break;
default:
if (Token::isElementaryTypeName(token))
{

View File

@ -612,7 +612,7 @@ void Scanner::scanToken()
if (m_char == '"' || m_char == '\'')
token = scanHexString();
else
token = Token::Illegal;
token = Token::IllegalHex;
}
}
else if (isDecimalDigit(m_char))
@ -736,11 +736,11 @@ Token::Value Scanner::scanHexString()
{
char c = m_char;
if (!scanHexByte(c))
return Token::Illegal;
return Token::IllegalHex;
addLiteralChar(c);
}
if (m_char != quote)
return Token::Illegal;
return Token::IllegalHex;
literal.complete();
advance(); // consume quote
return Token::StringLiteral;

View File

@ -261,6 +261,8 @@ namespace solidity
\
/* Illegal token - not able to scan. */ \
T(Illegal, "ILLEGAL", 0) \
/* Illegal hex token */ \
T(IllegalHex, "ILLEGAL_HEX", 0) \
\
/* Scanner-internal use only. */ \
T(Whitespace, NULL, 0)

View File

@ -471,6 +471,8 @@ BOOST_AUTO_TEST_CASE(invalid_short_unicode_string_escape)
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
}
// HEX STRING LITERAL
BOOST_AUTO_TEST_CASE(valid_hex_literal)
{
Scanner scanner(CharStream("{ hex\"00112233FF\""));
@ -483,30 +485,32 @@ BOOST_AUTO_TEST_CASE(invalid_short_hex_literal)
{
Scanner scanner(CharStream("{ hex\"00112233F\""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
BOOST_CHECK_EQUAL(scanner.next(), Token::IllegalHex);
}
BOOST_AUTO_TEST_CASE(invalid_hex_literal_with_space)
{
Scanner scanner(CharStream("{ hex\"00112233FF \""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
BOOST_CHECK_EQUAL(scanner.next(), Token::IllegalHex);
}
BOOST_AUTO_TEST_CASE(invalid_hex_literal_with_wrong_quotes)
{
Scanner scanner(CharStream("{ hex\"00112233FF'"));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
BOOST_CHECK_EQUAL(scanner.next(), Token::IllegalHex);
}
BOOST_AUTO_TEST_CASE(invalid_hex_literal_nonhex_string)
{
Scanner scanner(CharStream("{ hex\"hello\""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::LBrace);
BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal);
BOOST_CHECK_EQUAL(scanner.next(), Token::IllegalHex);
}
// COMMENTS
BOOST_AUTO_TEST_CASE(invalid_multiline_comment_close)
{
// This used to parse as "comment", "identifier"