mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Introduce hex literals (#832)
* Introduce hex keyword token * Support hex literals * Include tests for hex literals * Document hex literals
This commit is contained in:
committed by
chriseth
parent
970260bf0f
commit
ec3298535e
@@ -591,7 +591,23 @@ void Scanner::scanToken()
|
||||
break;
|
||||
default:
|
||||
if (isIdentifierStart(m_char))
|
||||
{
|
||||
tie(token, m, n) = scanIdentifierOrKeyword();
|
||||
|
||||
// Special case for hexademical literals
|
||||
if (token == Token::Hex)
|
||||
{
|
||||
// reset
|
||||
m = 0;
|
||||
n = 0;
|
||||
|
||||
// Special quoted hex string must follow
|
||||
if (m_char == '"' || m_char == '\'')
|
||||
token = scanHexString();
|
||||
else
|
||||
token = Token::Illegal;
|
||||
}
|
||||
}
|
||||
else if (isDecimalDigit(m_char))
|
||||
token = scanNumber();
|
||||
else if (skipWhitespace())
|
||||
@@ -684,6 +700,25 @@ Token::Value Scanner::scanString()
|
||||
return Token::StringLiteral;
|
||||
}
|
||||
|
||||
Token::Value Scanner::scanHexString()
|
||||
{
|
||||
char const quote = m_char;
|
||||
advance(); // consume quote
|
||||
LiteralScope literal(this, LITERAL_TYPE_STRING);
|
||||
while (m_char != quote && !isSourcePastEndOfInput() && !isLineTerminator(m_char))
|
||||
{
|
||||
char c = m_char;
|
||||
if (!scanHexByte(c))
|
||||
return Token::Illegal;
|
||||
addLiteralChar(c);
|
||||
}
|
||||
if (m_char != quote)
|
||||
return Token::Illegal;
|
||||
literal.complete();
|
||||
advance(); // consume quote
|
||||
return Token::StringLiteral;
|
||||
}
|
||||
|
||||
void Scanner::scanDecimalDigits()
|
||||
{
|
||||
while (isDecimalDigit(m_char))
|
||||
|
||||
Reference in New Issue
Block a user