diff options
author | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-01 05:43:40 +0800 |
---|---|---|
committer | Lefteris Karapetsas <lefteris@refu.co> | 2014-12-01 05:43:40 +0800 |
commit | a59546473916fcccb2ddc444e7264a94c551c617 (patch) | |
tree | 3e4906c2a5f0cdbcb7b135f80d8f967bb1d5b42a /Scanner.cpp | |
parent | db7b118ece60ae20f20c871bd257a1af5366423f (diff) | |
download | dexon-solidity-a59546473916fcccb2ddc444e7264a94c551c617.tar.gz dexon-solidity-a59546473916fcccb2ddc444e7264a94c551c617.tar.zst dexon-solidity-a59546473916fcccb2ddc444e7264a94c551c617.zip |
Simplifying scanning for natspec documentation
- Scanner no longer remembers the last natspect comment until
a new one is encountered. It remembers it only until the next
scan()
Diffstat (limited to 'Scanner.cpp')
-rw-r--r-- | Scanner.cpp | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/Scanner.cpp b/Scanner.cpp index 4da9874a..3335e9df 100644 --- a/Scanner.cpp +++ b/Scanner.cpp @@ -104,16 +104,14 @@ int hexValue(char c) void Scanner::reset(CharStream const& _source) { - bool foundDocComment; m_source = _source; m_char = m_source.get(); skipWhitespace(); - foundDocComment = scanToken(); + scanToken(); - // special version of Scanner:next() taking the previous scanToken() result into account m_currentToken = m_nextToken; - if (scanToken() || foundDocComment) - m_skippedComment = m_nextSkippedComment; + m_skippedComment = m_nextSkippedComment; + scanToken(); } @@ -142,8 +140,9 @@ BOOST_STATIC_ASSERT(Token::NUM_TOKENS <= 0x100); Token::Value Scanner::next() { m_currentToken = m_nextToken; - if (scanToken()) - m_skippedComment = m_nextSkippedComment; + m_skippedComment = m_nextSkippedComment; + scanToken(); + return m_currentToken.token; } @@ -188,13 +187,13 @@ Token::Value Scanner::scanDocumentationComment() { // check if next line is also a documentation comment skipWhitespace(); - if (m_source.get(0) == '/' && + if (!m_source.isPastEndOfInput(3) && + m_source.get(0) == '/' && m_source.get(1) == '/' && - m_source.get(2) == '/' && - !m_source.isPastEndOfInput(3)) + m_source.get(2) == '/') { addCommentLiteralChar('\n'); - m_char = m_source.advanceBy(3); + m_char = m_source.advanceAndGet(3); } else break; // next line is not a documentation comment, we are done @@ -230,10 +229,10 @@ Token::Value Scanner::skipMultiLineComment() return Token::ILLEGAL; } -bool Scanner::scanToken() +void Scanner::scanToken() { - bool foundDocComment = false; m_nextToken.literal.clear(); + m_nextSkippedComment.literal.clear(); Token::Value token; do { @@ -345,7 +344,6 @@ bool Scanner::scanToken() m_nextSkippedComment.location.end = getSourcePos(); m_nextSkippedComment.token = comment; token = Token::WHITESPACE; - foundDocComment = true; } else token = skipSingleLineComment(); @@ -441,8 +439,6 @@ bool Scanner::scanToken() while (token == Token::WHITESPACE); m_nextToken.location.end = getSourcePos(); m_nextToken.token = token; - - return foundDocComment; } bool Scanner::scanEscape() @@ -783,23 +779,13 @@ Token::Value Scanner::scanIdentifierOrKeyword() return KeywordOrIdentifierToken(m_nextToken.literal); } -char CharStream::advanceAndGet() +char CharStream::advanceAndGet(size_t _chars) { if (isPastEndOfInput()) return 0; - ++m_pos; + m_pos += _chars; if (isPastEndOfInput()) return 0; - return get(); -} - -char CharStream::advanceBy(size_t _chars) -{ - if (asserts(!isPastEndOfInput(_chars))) - BOOST_THROW_EXCEPTION(InternalCompilerError()); - - m_pos += _chars; - return m_source[m_pos]; } |