diff options
Diffstat (limited to 'libsolidity/parsing/Scanner.cpp')
-rw-r--r-- | libsolidity/parsing/Scanner.cpp | 28 |
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 |