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

- Work in progress on the scanner for recognizing the second
      type of doxygen comments for Natspec.
This commit is contained in:
Lefteris Karapetsas 2014-12-17 18:53:18 +01:00
parent a98afc8eaa
commit d3234c51b9
2 changed files with 56 additions and 5 deletions

View File

@ -219,7 +219,7 @@ Token::Value Scanner::skipSingleLineComment()
return Token::WHITESPACE; return Token::WHITESPACE;
} }
Token::Value Scanner::scanDocumentationComment() Token::Value Scanner::scanSingleLineDocComment()
{ {
LiteralScope literal(this, LITERAL_TYPE_COMMENT); LiteralScope literal(this, LITERAL_TYPE_COMMENT);
advance(); //consume the last '/' advance(); //consume the last '/'
@ -250,7 +250,6 @@ Token::Value Scanner::scanDocumentationComment()
Token::Value Scanner::skipMultiLineComment() Token::Value Scanner::skipMultiLineComment()
{ {
solAssert(m_char == '*', "");
advance(); advance();
while (!isSourcePastEndOfInput()) while (!isSourcePastEndOfInput())
{ {
@ -270,6 +269,43 @@ Token::Value Scanner::skipMultiLineComment()
return Token::ILLEGAL; 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() void Scanner::scanToken()
{ {
m_nextToken.literal.clear(); m_nextToken.literal.clear();
@ -381,7 +417,7 @@ void Scanner::scanToken()
{ {
Token::Value comment; Token::Value comment;
m_nextSkippedComment.location.start = getSourcePos(); m_nextSkippedComment.location.start = getSourcePos();
comment = scanDocumentationComment(); comment = scanSingleLineDocComment();
m_nextSkippedComment.location.end = getSourcePos(); m_nextSkippedComment.location.end = getSourcePos();
m_nextSkippedComment.token = comment; m_nextSkippedComment.token = comment;
token = Token::WHITESPACE; token = Token::WHITESPACE;
@ -390,7 +426,21 @@ void Scanner::scanToken()
token = skipSingleLineComment(); token = skipSingleLineComment();
} }
else if (m_char == '*') 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 == '=') else if (m_char == '=')
token = selectToken(Token::ASSIGN_DIV); token = selectToken(Token::ASSIGN_DIV);
else else

View File

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