@@ -697,6 +697,17 @@ void Lexer::lexOperatorIdentifier() {
697
697
break ;
698
698
} while (advanceIfValidContinuationOfOperator (CurPtr, BufferEnd));
699
699
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
+
700
711
// Decide between the binary, prefix, and postfix cases.
701
712
// It's binary if either both sides are bound or both sides are not bound.
702
713
// Otherwise, it's postfix if left-bound and prefix if right-bound.
@@ -771,27 +782,9 @@ void Lexer::lexOperatorIdentifier() {
771
782
return formToken (tok::unknown, TokStart);
772
783
}
773
784
} else {
774
- // If there is a "//" in the middle of an identifier token, it starts
775
- // a single-line comment.
776
- auto Pos = StringRef (TokStart, CurPtr-TokStart).find (" //" );
777
- if (Pos != StringRef::npos) {
778
- CurPtr = TokStart+Pos;
779
- // Next token is a comment, which counts as whitespace.
780
- rightBound = false ;
781
- }
782
-
783
- // If there is a "/*" in the middle of an identifier token, it starts
784
- // a multi-line comment.
785
- Pos = StringRef (TokStart, CurPtr-TokStart).find (" /*" );
786
- if (Pos != StringRef::npos) {
787
- CurPtr = TokStart+Pos;
788
- // Next token is a comment, which counts as whitespace.
789
- rightBound = false ;
790
- }
791
-
792
785
// Verify there is no "*/" in the middle of the identifier token, we reject
793
786
// it as potentially ending a block comment.
794
- Pos = StringRef (TokStart, CurPtr-TokStart).find (" */" );
787
+ auto Pos = StringRef (TokStart, CurPtr-TokStart).find (" */" );
795
788
if (Pos != StringRef::npos) {
796
789
diagnose (TokStart+Pos, diag::lex_unexpected_block_comment_end);
797
790
return formToken (tok::unknown, TokStart);
0 commit comments