Skip to content

Commit 1df518c

Browse files
committed
[Lexer] Simplify comment detection code in lexOperatorIdentifier
1 parent 9d1a3fc commit 1df518c

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

lib/Parse/Lexer.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -697,32 +697,23 @@ void Lexer::lexOperatorIdentifier() {
697697
break;
698698
} while (advanceIfValidContinuationOfOperator(CurPtr, BufferEnd));
699699

700+
if (CurPtr-TokStart > 2) {
701+
// If there is a "//" or "/*" in the middle of an identifier token,
702+
// it starts a comment.
703+
for (auto Ptr = TokStart+1; Ptr != CurPtr-1; ++Ptr) {
704+
if (Ptr[0] == '/' && (Ptr[1] == '/' || Ptr[1] == '*')) {
705+
CurPtr = Ptr;
706+
break;
707+
}
708+
}
709+
}
710+
700711
// Decide between the binary, prefix, and postfix cases.
701712
// It's binary if either both sides are bound or both sides are not bound.
702713
// Otherwise, it's postfix if left-bound and prefix if right-bound.
703714
bool leftBound = isLeftBound(TokStart, BufferStart);
704715
bool rightBound = isRightBound(CurPtr, leftBound, CodeCompletionPtr);
705716

706-
if (CurPtr-TokStart > 2) {
707-
// If there is a "//" in the middle of an identifier token, it starts
708-
// a single-line comment.
709-
auto Pos = StringRef(TokStart, CurPtr-TokStart).find("//");
710-
if (Pos != StringRef::npos) {
711-
CurPtr = TokStart+Pos;
712-
// Next token is a comment, which counts as whitespace.
713-
rightBound = false;
714-
}
715-
716-
// If there is a "/*" in the middle of an identifier token, it starts
717-
// a multi-line comment.
718-
Pos = StringRef(TokStart, CurPtr-TokStart).find("/*");
719-
if (Pos != StringRef::npos) {
720-
CurPtr = TokStart+Pos;
721-
// Next token is a comment, which counts as whitespace.
722-
rightBound = false;
723-
}
724-
}
725-
726717
// Match various reserved words.
727718
if (CurPtr-TokStart == 1) {
728719
switch (TokStart[0]) {

0 commit comments

Comments
 (0)