Browse Source

Merge pull request #721 from LefterisJP/sol_fixMultiLCommentScan

Fix for sol scanner where empty multiline comment became Natspec comment
cl-refactor
Gav Wood 10 years ago
parent
commit
d0cc3f4efb
  1. 21
      libsolidity/Scanner.cpp
  2. 1
      libsolidity/Scanner.h
  3. 7
      test/SolidityScanner.cpp

21
libsolidity/Scanner.cpp

@ -285,8 +285,6 @@ Token::Value Scanner::scanMultiLineDocComment()
bool endFound = false; bool endFound = false;
bool charsAdded = false; bool charsAdded = false;
advance(); //consume the last '*' at /**
skipWhitespaceExceptLF();
while (!isSourcePastEndOfInput()) while (!isSourcePastEndOfInput())
{ {
//handle newlines in multline comments //handle newlines in multline comments
@ -354,11 +352,20 @@ Token::Value Scanner::scanSlash()
return Token::WHITESPACE; return Token::WHITESPACE;
else if (m_char == '*') else if (m_char == '*')
{ {
Token::Value comment; advance(); //consume the last '*' at /**
m_nextSkippedComment.location.start = firstSlashPosition; skipWhitespaceExceptLF();
comment = scanMultiLineDocComment();
m_nextSkippedComment.location.end = getSourcePos(); // special case of a closed normal multiline comment
m_nextSkippedComment.token = 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; return Token::WHITESPACE;
} }
else else

1
libsolidity/Scanner.h

@ -119,6 +119,7 @@ public:
{ {
return m_currentToken.token; return m_currentToken.token;
} }
Location getCurrentLocation() const { return m_currentToken.location; } Location getCurrentLocation() const { return m_currentToken.location; }
std::string const& getCurrentLiteral() const { return m_currentToken.literal; } std::string const& getCurrentLiteral() const { return m_currentToken.literal; }
///@} ///@}

7
test/SolidityScanner.cpp

@ -227,6 +227,13 @@ BOOST_AUTO_TEST_CASE(documentation_comment_before_eos)
BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), ""); 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) BOOST_AUTO_TEST_CASE(empty_multiline_documentation_comment_before_eos)
{ {
Scanner scanner(CharStream("/***/")); Scanner scanner(CharStream("/***/"));

Loading…
Cancel
Save