@@ -2031,6 +2031,39 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2031
2031
llvm::SaveAndRestore<Token> SavedTok (Tok);
2032
2032
llvm::SaveAndRestore<ParsedTrivia> SavedLeadingTrivia (LeadingTrivia);
2033
2033
llvm::SaveAndRestore<ParsedTrivia> SavedTrailingTrivia (TrailingTrivia);
2034
+
2035
+ // The simple case: just a single literal segment.
2036
+ if (Segments.size () == 1 &&
2037
+ Segments.front ().Kind == Lexer::StringSegment::Literal) {
2038
+ {
2039
+ SyntaxParsingContext SegmentsCtx (SyntaxContext,
2040
+ SyntaxKind::StringLiteralSegments);
2041
+
2042
+ // First segment shall inherit the attached comments.
2043
+ unsigned CommentLength = 0 ;
2044
+ CommentLength = SourceMgr.getByteDistance (EntireTok.getCommentRange ().
2045
+ getStart (), Loc);
2046
+ consumeExtraToken (Token (tok::string_literal,
2047
+ CharSourceRange (SourceMgr, Loc, EndLoc).str (),
2048
+ CommentLength));
2049
+
2050
+ SyntaxParsingContext StrSegContext (SyntaxContext,
2051
+ SyntaxKind::StringSegment);
2052
+
2053
+ // Make an unknown token to encapsulate the entire string segment and add
2054
+ // such token to the context.
2055
+ auto Segment = Segments.front ();
2056
+ Token content (tok::string_segment,
2057
+ CharSourceRange (Segment.Loc , Segment.Length ).str ());
2058
+ SyntaxContext->addToken (content, EmptyTrivia, EmptyTrivia);
2059
+ }
2060
+
2061
+ // Add the close quote the context; the quote should have a void leading trivia
2062
+ // and the trailing trivia of the entire string token.
2063
+ SyntaxContext->addToken (CloseQuote, EmptyTrivia, EntireTrailingTrivia);
2064
+
2065
+ return makeParserResult (createStringLiteralExprFromSegment (Context, L, Segments.front (), Loc));
2066
+ }
2034
2067
2035
2068
unsigned LiteralCapacity = 0 ;
2036
2069
unsigned InterpolationCount = 0 ;
@@ -2073,13 +2106,6 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2073
2106
Status.setIsParseError ();
2074
2107
return makeParserResult (Status, new (Context) ErrorExpr (Loc));
2075
2108
}
2076
-
2077
- // The simple case: just a single literal segment.
2078
- if (Segments.size () == 1 &&
2079
- Segments.front ().Kind == Lexer::StringSegment::Literal) {
2080
- return makeParserResult (
2081
- createStringLiteralExprFromSegment (Context, L, Segments.front (), Loc));
2082
- }
2083
2109
2084
2110
return makeParserResult (Status, new (Context) InterpolatedStringLiteralExpr (
2085
2111
Loc, LiteralCapacity, InterpolationCount,
0 commit comments