Corrects comment literal that span too long.

This commit is contained in:
Erik Kundt 2020-01-25 17:53:48 +01:00
parent b43751d65e
commit cfc70ede5c
2 changed files with 13 additions and 9 deletions

View File

@ -306,19 +306,24 @@ bool Scanner::tryScanEndOfLine()
return false; return false;
} }
Token Scanner::scanSingleLineDocComment() int Scanner::scanSingleLineDocComment()
{ {
LiteralScope literal(this, LITERAL_TYPE_COMMENT); LiteralScope literal(this, LITERAL_TYPE_COMMENT);
int endPosition = m_source->position();
advance(); //consume the last '/' at /// advance(); //consume the last '/' at ///
skipWhitespaceExceptUnicodeLinebreak(); skipWhitespaceExceptUnicodeLinebreak();
while (!isSourcePastEndOfInput()) while (!isSourcePastEndOfInput())
{ {
endPosition = m_source->position();
if (tryScanEndOfLine()) if (tryScanEndOfLine())
{ {
// check if next line is also a documentation comment // Check if next line is also a single-line comment.
skipWhitespace(); // If any whitespaces were skipped, use source position before.
if (!skipWhitespace())
endPosition = m_source->position();
if (!m_source->isPastEndOfInput(3) && if (!m_source->isPastEndOfInput(3) &&
m_source->get(0) == '/' && m_source->get(0) == '/' &&
m_source->get(1) == '/' && m_source->get(1) == '/' &&
@ -338,7 +343,7 @@ Token Scanner::scanSingleLineDocComment()
advance(); advance();
} }
literal.complete(); literal.complete();
return Token::CommentLiteral; return endPosition;
} }
Token Scanner::skipMultiLineComment() Token Scanner::skipMultiLineComment()
@ -426,12 +431,10 @@ Token Scanner::scanSlash()
else if (m_char == '/') else if (m_char == '/')
{ {
// doxygen style /// comment // doxygen style /// comment
Token comment;
m_skippedComments[NextNext].location.start = firstSlashPosition; m_skippedComments[NextNext].location.start = firstSlashPosition;
m_skippedComments[NextNext].location.source = m_source; m_skippedComments[NextNext].location.source = m_source;
comment = scanSingleLineDocComment(); m_skippedComments[NextNext].token = Token::CommentLiteral;
m_skippedComments[NextNext].location.end = sourcePos(); m_skippedComments[NextNext].location.end = scanSingleLineDocComment();
m_skippedComments[NextNext].token = comment;
return Token::Whitespace; return Token::Whitespace;
} }
else else

View File

@ -229,7 +229,8 @@ private:
Token scanString(); Token scanString();
Token scanHexString(); Token scanHexString();
Token scanSingleLineDocComment(); /// Scans a single line comment and returns its corrected end position.
int scanSingleLineDocComment();
Token scanMultiLineDocComment(); Token scanMultiLineDocComment();
/// Scans a slash '/' and depending on the characters returns the appropriate token /// Scans a slash '/' and depending on the characters returns the appropriate token
Token scanSlash(); Token scanSlash();