@@ -2022,31 +2022,17 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2022
2022
// Add the open quote to the context; the quote should have the leading trivia
2023
2023
// of the entire string token and a void trailing trivia.
2024
2024
SyntaxContext->addToken (OpenQuote, LeadingTrivia, EmptyTrivia);
2025
-
2026
- // We don't expose the entire interpolated string as one token. Instead, we
2027
- // should expose the tokens in each segment.
2028
- consumeTokenWithoutFeedingReceiver ();
2029
- // We are going to mess with Tok to do reparsing for interpolated literals,
2030
- // don't lose our 'next' token.
2031
- llvm::SaveAndRestore<Token> SavedTok (Tok);
2032
- llvm::SaveAndRestore<ParsedTrivia> SavedLeadingTrivia (LeadingTrivia);
2033
- llvm::SaveAndRestore<ParsedTrivia> SavedTrailingTrivia (TrailingTrivia);
2034
2025
2035
2026
// The simple case: just a single literal segment.
2036
2027
if (Segments.size () == 1 &&
2037
- Segments.front ().Kind == Lexer::StringSegment::Literal) {
2028
+ Segments.front ().Kind == Lexer::StringSegment::Literal) {
2038
2029
{
2030
+ consumeExtraToken (Tok);
2031
+ consumeTokenWithoutFeedingReceiver ();
2032
+
2039
2033
SyntaxParsingContext SegmentsCtx (SyntaxContext,
2040
2034
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
-
2035
+
2050
2036
SyntaxParsingContext StrSegContext (SyntaxContext,
2051
2037
SyntaxKind::StringSegment);
2052
2038
@@ -2061,17 +2047,27 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2061
2047
// Add the close quote the context; the quote should have a void leading trivia
2062
2048
// and the trailing trivia of the entire string token.
2063
2049
SyntaxContext->addToken (CloseQuote, EmptyTrivia, EntireTrailingTrivia);
2064
-
2065
- return makeParserResult (createStringLiteralExprFromSegment (Context, L, Segments.front (), Loc));
2066
- }
2067
2050
2051
+ return makeParserResult (
2052
+ createStringLiteralExprFromSegment (Context, L, Segments.front (), Loc));
2053
+ }
2054
+
2055
+ // We don't expose the entire interpolated string as one token. Instead, we
2056
+ // should expose the tokens in each segment.
2057
+ consumeTokenWithoutFeedingReceiver ();
2058
+ // We are going to mess with Tok to do reparsing for interpolated literals,
2059
+ // don't lose our 'next' token.
2060
+ llvm::SaveAndRestore<Token> SavedTok (Tok);
2061
+ llvm::SaveAndRestore<ParsedTrivia> SavedLeadingTrivia (LeadingTrivia);
2062
+ llvm::SaveAndRestore<ParsedTrivia> SavedTrailingTrivia (TrailingTrivia);
2063
+
2068
2064
// We're not in a place where an interpolation would be valid.
2069
2065
if (!CurLocalContext) {
2070
2066
// Return an error, but include an empty InterpolatedStringLiteralExpr
2071
2067
// so that parseDeclPoundDiagnostic() can figure out why this string
2072
2068
// literal was bad.
2073
2069
return makeParserErrorResult (
2074
- new (Context) InterpolatedStringLiteralExpr (Loc, 0 , 0 , nullptr ));
2070
+ new (Context) InterpolatedStringLiteralExpr (Loc, 0 , 0 , nullptr ));
2075
2071
}
2076
2072
2077
2073
unsigned LiteralCapacity = 0 ;
0 commit comments