diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2016-08-16 22:31:23 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2016-08-16 22:31:23 +0800 |
commit | ec3298535ebe1d6602df9196b81c92d4a88b4821 (patch) | |
tree | f09308a0955b9fb08736b8afa59a381cb909e232 /libsolidity | |
parent | 970260bf0f8b9cdfd46c6956c14e267788ffdc0f (diff) | |
download | dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.tar dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.tar.gz dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.tar.bz2 dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.tar.lz dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.tar.xz dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.tar.zst dexon-solidity-ec3298535ebe1d6602df9196b81c92d4a88b4821.zip |
Introduce hex literals (#832)
* Introduce hex keyword token
* Support hex literals
* Include tests for hex literals
* Document hex literals
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/parsing/Scanner.cpp | 35 | ||||
-rw-r--r-- | libsolidity/parsing/Scanner.h | 1 | ||||
-rw-r--r-- | libsolidity/parsing/Token.h | 1 |
3 files changed, 37 insertions, 0 deletions
diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp index d730210a..603f3e42 100644 --- a/libsolidity/parsing/Scanner.cpp +++ b/libsolidity/parsing/Scanner.cpp @@ -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)) diff --git a/libsolidity/parsing/Scanner.h b/libsolidity/parsing/Scanner.h index 708adf8f..36cba112 100644 --- a/libsolidity/parsing/Scanner.h +++ b/libsolidity/parsing/Scanner.h @@ -203,6 +203,7 @@ private: std::tuple<Token::Value, unsigned, unsigned> scanIdentifierOrKeyword(); Token::Value scanString(); + Token::Value scanHexString(); Token::Value scanSingleLineDocComment(); Token::Value scanMultiLineDocComment(); /// Scans a slash '/' and depending on the characters returns the appropriate token diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h index f4de74c7..007baef4 100644 --- a/libsolidity/parsing/Token.h +++ b/libsolidity/parsing/Token.h @@ -155,6 +155,7 @@ namespace solidity K(External, "external", 0) \ K(For, "for", 0) \ K(Function, "function", 0) \ + K(Hex, "hex", 0) \ K(If, "if", 0) \ K(Indexed, "indexed", 0) \ K(Internal, "internal", 0) \ |