Skip to content

Commit 9e67e73

Browse files
committed
[Parse] Ensure that the tokens formed for interpolation anchors have proper ranges from the input source
1 parent fc2cc02 commit 9e67e73

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,7 +1864,8 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
18641864
SyntaxKind::ExpressionSegment);
18651865

18661866
// Backslash is part of an expression segment.
1867-
Token BackSlash(tok::backslash, "\\");
1867+
Token BackSlash(tok::backslash,
1868+
CharSourceRange(Segment.Loc.getAdvancedLoc(-1), 1).str());
18681869
ExprContext.addToken(BackSlash, EmptyTrivia, EmptyTrivia);
18691870
// Create a temporary lexer that lexes from the body of the string.
18701871
LexerState BeginState =
@@ -2013,15 +2014,19 @@ ParserResult<Expr> Parser::parseExprStringLiteral() {
20132014

20142015
// We are now sure this is a string interpolation expression.
20152016
LocalContext.setCreateSyntax(SyntaxKind::StringInterpolationExpr);
2016-
StringRef Quote;
2017+
StringRef OpenQuoteStr, CloseQuoteStr;
20172018
tok QuoteKind;
2018-
std::tie(Quote, QuoteKind) = Tok.isMultilineString() ?
2019-
std::make_tuple("\"\"\"", tok::multiline_string_quote) :
2020-
std::make_tuple("\"", tok::string_quote);
2019+
std::tie(OpenQuoteStr, CloseQuoteStr, QuoteKind) = Tok.isMultilineString() ?
2020+
std::make_tuple(Tok.getRawText().take_front(3),
2021+
Tok.getRawText().take_back(3),
2022+
tok::multiline_string_quote) :
2023+
std::make_tuple(Tok.getRawText().take_front(1),
2024+
Tok.getRawText().take_back(1),
2025+
tok::string_quote);
20212026

20222027
// Make unknown tokens to represent the open and close quote.
2023-
Token OpenQuote(QuoteKind, Quote);
2024-
Token CloseQuote(QuoteKind, Quote);
2028+
Token OpenQuote(QuoteKind, OpenQuoteStr);
2029+
Token CloseQuote(QuoteKind, CloseQuoteStr);
20252030
Trivia EmptyTrivia;
20262031
Trivia EntireTrailingTrivia = TrailingTrivia;
20272032

0 commit comments

Comments
 (0)