Skip to content

Commit eda5657

Browse files
authored
Merge pull request #63368 from poya/bug/10440
[Parser] Handle REPL raw multi-line string literal input
2 parents d0164dd + 9f6dc70 commit eda5657

File tree

6 files changed

+18
-2
lines changed

6 files changed

+18
-2
lines changed

include/swift/Parse/Parser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,11 @@ class Parser {
745745
/// Check whether the current token starts with '...'.
746746
bool startsWithEllipsis(Token Tok);
747747

748+
/// Check whether the current token starts with a multi-line string delimiter.
749+
bool startsWithMultilineStringDelimiter(Token Tok) {
750+
return Tok.getText().ltrim('#').startswith("\"\"\"");
751+
}
752+
748753
/// Returns true if token is an identifier with the given value.
749754
bool isIdentifier(Token Tok, StringRef value) {
750755
return Tok.is(tok::identifier) && Tok.getText() == value;

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1806,7 +1806,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
18061806
// Eat an invalid token in an expression context. Error tokens are diagnosed
18071807
// by the lexer, so there is no reason to emit another diagnostic.
18081808
case tok::unknown:
1809-
if (Tok.getText().startswith("\"\"\"")) {
1809+
if (startsWithMultilineStringDelimiter(Tok)) {
18101810
// This was due to unterminated multi-line string.
18111811
IsInputIncomplete = true;
18121812
}

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ ParserStatus Parser::parseBraceItems(SmallVectorImpl<ASTNode> &Entries,
304304

305305
// Eat invalid tokens instead of allowing them to produce downstream errors.
306306
if (Tok.is(tok::unknown)) {
307-
if (Tok.getText().startswith("\"\"\"")) {
307+
if (startsWithMultilineStringDelimiter(Tok)) {
308308
// This was due to unterminated multi-line string.
309309
IsInputIncomplete = true;
310310
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#"""
2+
raw
3+
multiline
4+
string
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let s = ##"""
2+
"raw"
3+
multiline
4+
string
5+
##\(

test/IDE/test-input-complete/test_input.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string1.swift | %FileCheck %s -check-prefix=INCOMPLETE
3535
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string2.swift | %FileCheck %s -check-prefix=INCOMPLETE
3636
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string3.swift | %FileCheck %s -check-prefix=INCOMPLETE
37+
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string4.swift | %FileCheck %s -check-prefix=INCOMPLETE
38+
// RUN: %swift-ide-test -test-input-complete -source-filename %S/Inputs/multi_line_string5.swift | %FileCheck %s -check-prefix=INCOMPLETE
3739

3840
// INCOMPLETE: IS_INCOMPLETE
3941
// COMPLETE: IS_COMPLETE

0 commit comments

Comments
 (0)