Browse Source

Work in progress for /** ... */ natspec comments

- Work in progress on the scanner for recognizing the second
      type of doxygen comments for Natspec.
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
6d48f3e987
  1. 58
      libsolidity/Scanner.cpp
  2. 3
      libsolidity/Scanner.h
  3. 7
      test/solidityScanner.cpp

58
libsolidity/Scanner.cpp

@ -219,7 +219,7 @@ Token::Value Scanner::skipSingleLineComment()
return Token::WHITESPACE;
}
Token::Value Scanner::scanDocumentationComment()
Token::Value Scanner::scanSingleLineDocComment()
{
LiteralScope literal(this, LITERAL_TYPE_COMMENT);
advance(); //consume the last '/'
@ -250,7 +250,6 @@ Token::Value Scanner::scanDocumentationComment()
Token::Value Scanner::skipMultiLineComment()
{
solAssert(m_char == '*', "");
advance();
while (!isSourcePastEndOfInput())
{
@ -270,6 +269,43 @@ Token::Value Scanner::skipMultiLineComment()
return Token::ILLEGAL;
}
Token::Value Scanner::scanMultiLineDocComment()
{
LiteralScope literal(this, LITERAL_TYPE_COMMENT);
bool endFound = false;
advance(); //consume the last '*'
while (!isSourcePastEndOfInput())
{
// skip starting '*' in multiine comments
if (isLineTerminator(m_char))
{
skipWhitespace();
if (!m_source.isPastEndOfInput(2) && m_source.get(1) == '*' && m_source.get(2) != '/')
{
addCommentLiteralChar('\n');
m_char = m_source.advanceAndGet(3);
}
else
addCommentLiteralChar('\n');
}
if (!m_source.isPastEndOfInput(1) && m_source.get(0) == '*' && m_source.get(1) == '/')
{
m_source.advanceAndGet(2);
endFound = true;
break;
}
addCommentLiteralChar(m_char);
advance();
}
literal.complete();
if (!endFound)
return Token::ILLEGAL;
else
return Token::COMMENT_LITERAL;
}
void Scanner::scanToken()
{
m_nextToken.literal.clear();
@ -381,7 +417,7 @@ void Scanner::scanToken()
{
Token::Value comment;
m_nextSkippedComment.location.start = getSourcePos();
comment = scanDocumentationComment();
comment = scanSingleLineDocComment();
m_nextSkippedComment.location.end = getSourcePos();
m_nextSkippedComment.token = comment;
token = Token::WHITESPACE;
@ -390,7 +426,21 @@ void Scanner::scanToken()
token = skipSingleLineComment();
}
else if (m_char == '*')
token = skipMultiLineComment();
{
if (!advance()) /* slash star comment before EOS */
token = Token::WHITESPACE;
else if (m_char == '*')
{
Token::Value comment;
m_nextSkippedComment.location.start = getSourcePos();
comment = scanMultiLineDocComment();
m_nextSkippedComment.location.end = getSourcePos();
m_nextSkippedComment.token = comment;
token = Token::WHITESPACE;
}
else
token = skipMultiLineComment();
}
else if (m_char == '=')
token = selectToken(Token::ASSIGN_DIV);
else

3
libsolidity/Scanner.h

@ -190,7 +190,8 @@ private:
Token::Value scanIdentifierOrKeyword();
Token::Value scanString();
Token::Value scanDocumentationComment();
Token::Value scanSingleLineDocComment();
Token::Value scanMultiLineDocComment();
/// Scans an escape-sequence which is part of a string and adds the
/// decoded character to the current literal. Returns true if a pattern

7
test/solidityScanner.cpp

@ -160,6 +160,13 @@ BOOST_AUTO_TEST_CASE(documentation_comments_parsed_begin)
BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), " Send $(value / 1000) chocolates to the user");
}
BOOST_AUTO_TEST_CASE(multiline_documentation_comments_parsed_begin)
{
Scanner scanner(CharStream("/** Send $(value / 1000) chocolates to the user*/"));
BOOST_CHECK_EQUAL(scanner.getCurrentToken(), Token::EOS);
BOOST_CHECK_EQUAL(scanner.getCurrentCommentLiteral(), " Send $(value / 1000) chocolates to the user");
}
BOOST_AUTO_TEST_CASE(documentation_comments_parsed)
{
Scanner scanner(CharStream("some other tokens /// Send $(value / 1000) chocolates to the user"));

Loading…
Cancel
Save