Skip to content

Commit e09a341

Browse files
committed
Consume toke for string literal expr in a better way
Fix incorrect indent
1 parent b3a4ab6 commit e09a341

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,31 +2022,17 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20222022
// Add the open quote to the context; the quote should have the leading trivia
20232023
// of the entire string token and a void trailing trivia.
20242024
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);
20342025

20352026
// The simple case: just a single literal segment.
20362027
if (Segments.size() == 1 &&
2037-
Segments.front().Kind == Lexer::StringSegment::Literal) {
2028+
Segments.front().Kind == Lexer::StringSegment::Literal) {
20382029
{
2030+
consumeExtraToken(Tok);
2031+
consumeTokenWithoutFeedingReceiver();
2032+
20392033
SyntaxParsingContext SegmentsCtx(SyntaxContext,
20402034
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+
20502036
SyntaxParsingContext StrSegContext(SyntaxContext,
20512037
SyntaxKind::StringSegment);
20522038

@@ -2061,17 +2047,27 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20612047
// Add the close quote the context; the quote should have a void leading trivia
20622048
// and the trailing trivia of the entire string token.
20632049
SyntaxContext->addToken(CloseQuote, EmptyTrivia, EntireTrailingTrivia);
2064-
2065-
return makeParserResult(createStringLiteralExprFromSegment(Context, L, Segments.front(), Loc));
2066-
}
20672050

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+
20682064
// We're not in a place where an interpolation would be valid.
20692065
if (!CurLocalContext) {
20702066
// Return an error, but include an empty InterpolatedStringLiteralExpr
20712067
// so that parseDeclPoundDiagnostic() can figure out why this string
20722068
// literal was bad.
20732069
return makeParserErrorResult(
2074-
new (Context) InterpolatedStringLiteralExpr(Loc, 0, 0, nullptr));
2070+
new (Context) InterpolatedStringLiteralExpr(Loc, 0, 0, nullptr));
20752071
}
20762072

20772073
unsigned LiteralCapacity = 0;

0 commit comments

Comments
 (0)