aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/parsing
diff options
context:
space:
mode:
authorBalajiganapathi S <balajiganapathi.s@gmail.com>2017-10-21 03:35:08 +0800
committerChristian Parpart <christian@ethereum.org>2018-08-08 18:05:51 +0800
commit0000bfc604b985c47ab153f4172596b860c7cce8 (patch)
tree8bf5d50847fb78f89ce1cf380f86691257344b33 /libsolidity/parsing
parent4dc3335cda18bae7c683227a9795a7cc1de95fd2 (diff)
downloaddexon-solidity-0000bfc604b985c47ab153f4172596b860c7cce8.tar.gz
dexon-solidity-0000bfc604b985c47ab153f4172596b860c7cce8.tar.zst
dexon-solidity-0000bfc604b985c47ab153f4172596b860c7cce8.zip
Allow underscores in numbers.
Diffstat (limited to 'libsolidity/parsing')
-rw-r--r--libsolidity/parsing/Scanner.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/libsolidity/parsing/Scanner.cpp b/libsolidity/parsing/Scanner.cpp
index 801d2cc4..65189b19 100644
--- a/libsolidity/parsing/Scanner.cpp
+++ b/libsolidity/parsing/Scanner.cpp
@@ -726,8 +726,21 @@ Token::Value Scanner::scanHexString()
void Scanner::scanDecimalDigits()
{
- while (isDecimalDigit(m_char))
+ if (!isDecimalDigit(m_char)) // avoid underscore at beginning
+ return;
+ while (isDecimalDigit(m_char) || m_char == '_')
+ {
+ if (m_char == '_')
+ {
+ advance();
+ if (!isDecimalDigit(m_char)) // avoid trailing underscore
+ {
+ rollback(1);
+ break;
+ }
+ }
addLiteralCharAndAdvance();
+ }
}
Token::Value Scanner::scanNumber(char _charSeen)
@@ -755,8 +768,19 @@ Token::Value Scanner::scanNumber(char _charSeen)
addLiteralCharAndAdvance();
if (!isHexDigit(m_char))
return Token::Illegal; // we must have at least one hex digit after 'x'/'X'
- while (isHexDigit(m_char))
+ while (isHexDigit(m_char) || m_char == '_') // same logic as scanDecimalDigits
+ {
+ if (m_char == '_')
+ {
+ advance();
+ if (!isHexDigit(m_char)) // avoid trailing underscore
+ {
+ rollback(1);
+ break;
+ }
+ }
addLiteralCharAndAdvance();
+ }
}
else if (isDecimalDigit(m_char))
// We do not allow octal numbers