@@ -2003,16 +2003,6 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2003
2003
SourceLoc Loc = Tok.getLoc ();
2004
2004
SourceLoc EndLoc = Loc.getAdvancedLoc (Tok.getLength ());
2005
2005
2006
- // The simple case: just a single literal segment.
2007
- if (Segments.size () == 1 &&
2008
- Segments.front ().Kind == Lexer::StringSegment::Literal) {
2009
- consumeToken ();
2010
- return makeParserResult (
2011
- createStringLiteralExprFromSegment (Context, L, Segments.front (), Loc));
2012
- }
2013
-
2014
- // We are now sure this is a string interpolation expression.
2015
- LocalContext.setCreateSyntax (SyntaxKind::StringInterpolationExpr);
2016
2006
StringRef OpenQuoteStr, CloseQuoteStr;
2017
2007
tok QuoteKind;
2018
2008
std::tie (OpenQuoteStr, CloseQuoteStr, QuoteKind) = Tok.isMultilineString () ?
@@ -2032,6 +2022,35 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2032
2022
// Add the open quote to the context; the quote should have the leading trivia
2033
2023
// of the entire string token and a void trailing trivia.
2034
2024
SyntaxContext->addToken (OpenQuote, LeadingTrivia, EmptyTrivia);
2025
+
2026
+ // The simple case: just a single literal segment.
2027
+ if (Segments.size () == 1 &&
2028
+ Segments.front ().Kind == Lexer::StringSegment::Literal) {
2029
+ {
2030
+ consumeExtraToken (Tok);
2031
+ consumeTokenWithoutFeedingReceiver ();
2032
+
2033
+ SyntaxParsingContext SegmentsCtx (SyntaxContext,
2034
+ SyntaxKind::StringLiteralSegments);
2035
+
2036
+ SyntaxParsingContext StrSegContext (SyntaxContext,
2037
+ SyntaxKind::StringSegment);
2038
+
2039
+ // Make an unknown token to encapsulate the entire string segment and add
2040
+ // such token to the context.
2041
+ auto Segment = Segments.front ();
2042
+ Token content (tok::string_segment,
2043
+ CharSourceRange (Segment.Loc , Segment.Length ).str ());
2044
+ SyntaxContext->addToken (content, EmptyTrivia, EmptyTrivia);
2045
+ }
2046
+
2047
+ // Add the close quote the context; the quote should have a void leading trivia
2048
+ // and the trailing trivia of the entire string token.
2049
+ SyntaxContext->addToken (CloseQuote, EmptyTrivia, EntireTrailingTrivia);
2050
+
2051
+ return makeParserResult (
2052
+ createStringLiteralExprFromSegment (Context, L, Segments.front (), Loc));
2053
+ }
2035
2054
2036
2055
// We don't expose the entire interpolated string as one token. Instead, we
2037
2056
// should expose the tokens in each segment.
@@ -2044,8 +2063,8 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2044
2063
2045
2064
// We're not in a place where an interpolation would be valid.
2046
2065
if (!CurLocalContext) {
2047
- // Return an error, but include an empty InterpolatedStringLiteralExpr
2048
- // so that parseDeclPoundDiagnostic() can figure out why this string
2066
+ // Return an error, but include an empty InterpolatedStringLiteralExpr
2067
+ // so that parseDeclPoundDiagnostic() can figure out why this string
2049
2068
// literal was bad.
2050
2069
return makeParserErrorResult (
2051
2070
new (Context) InterpolatedStringLiteralExpr (Loc, 0 , 0 , nullptr ));
@@ -2075,7 +2094,7 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
2075
2094
2076
2095
// Collect all string segments.
2077
2096
SyntaxParsingContext SegmentsCtx (SyntaxContext,
2078
- SyntaxKind::StringInterpolationSegments );
2097
+ SyntaxKind::StringLiteralSegments );
2079
2098
Status = parseStringSegments (Segments, EntireTok, InterpolationVar,
2080
2099
Stmts, LiteralCapacity, InterpolationCount);
2081
2100
0 commit comments