From 631bd9ab38f9fc232f851fcb82121e258d729d11 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 5 Jan 2015 16:37:43 +0100 Subject: [PATCH] Fix for sol scanner where empty multiline comment became Natspec comment --- libsolidity/Scanner.cpp | 23 ++++++++++++++++------- libsolidity/Scanner.h | 1 + test/SolidityScanner.cpp | 7 +++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/libsolidity/Scanner.cpp b/libsolidity/Scanner.cpp index f22e69bc8..1f700d8b1 100644 --- a/libsolidity/Scanner.cpp +++ b/libsolidity/Scanner.cpp @@ -285,8 +285,6 @@ Token::Value Scanner::scanMultiLineDocComment() bool endFound = false; bool charsAdded = false; - advance(); //consume the last '*' at /** - skipWhitespaceExceptLF(); while (!isSourcePastEndOfInput()) { //handle newlines in multline comments @@ -354,11 +352,22 @@ Token::Value Scanner::scanSlash() return Token::WHITESPACE; else if (m_char == '*') { - Token::Value comment; - m_nextSkippedComment.location.start = firstSlashPosition; - comment = scanMultiLineDocComment(); - m_nextSkippedComment.location.end = getSourcePos(); - m_nextSkippedComment.token = comment; + advance(); //consume the last '*' at /** + skipWhitespaceExceptLF(); + + // special case of a closed normal multiline comment + if (!m_source.isPastEndOfInput() && m_source.get(0) == '/') + { + advance(); //skip the closing slash + } + else // we actually have a multiline documentation comment + { + Token::Value comment; + m_nextSkippedComment.location.start = firstSlashPosition; + comment = scanMultiLineDocComment(); + m_nextSkippedComment.location.end = getSourcePos(); + m_nextSkippedComment.token = comment; + } return Token::WHITESPACE; } else diff --git a/libsolidity/Scanner.h b/libsolidity/Scanner.h index 5b90a94eb..d93b79df0 100644 --- a/libsolidity/Scanner.h +++ b/libsolidity/Scanner.h @@ -119,6 +119,7 @@ public: { return m_currentToken.token; } + Location getCurrentLocation() const { return m_currentToken.location; } std::string const& getCurrentLiteral() const { return m_currentToken.literal; } ///@} diff --git a/test/SolidityScanner.cpp b/test/SolidityScanner.cpp index 355ea9e22..b7942d293 100644 --- a/test/SolidityScanner.cpp +++ b/test/SolidityScanner.cpp @@ -227,6 +227,13 @@ BOOST_AUTO_TEST_CASE(documentation_comment_before_eos) BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); } +BOOST_AUTO_TEST_CASE(empty_multiline_comment) +{ + Scanner scanner(CharStream("/**/")); + BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS); + BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); +} + BOOST_AUTO_TEST_CASE(empty_multiline_documentation_comment_before_eos) { Scanner scanner(CharStream("/***/"));