Skip to content

Commit 032d865

Browse files
committed
Response to rintaro's 2nd review
1 parent 9691076 commit 032d865

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/Parse/Lexer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,8 +1411,9 @@ static const char *skipToEndOfInterpolatedExpression(const char *CurPtr,
14111411
case '"':
14121412
case '\'': {
14131413
if (!AllowNewline.back() && inStringLiteral()) {
1414-
if (OpenDelimiters.back() == CurPtr[-1] &&
1415-
delimiterMatches(CustomDelimiter.back(), CurPtr)) {
1414+
unsigned InnerDelimiter = CustomDelimiter.back();
1415+
if (OpenDelimiters.back() == CurPtr[-1] && (!InnerDelimiter ||
1416+
(delimiterMatches(InnerDelimiter, CurPtr) && *CurPtr != '#'))) {
14161417
// Closing single line string literal.
14171418
OpenDelimiters.pop_back();
14181419
AllowNewline.pop_back();
@@ -1800,7 +1801,8 @@ void Lexer::lexStringLiteral(unsigned DelimiterLength) {
18001801
}
18011802

18021803
// Is this the end of multiline/delimited string literal?
1803-
if (StringRef(CurPtr, BufferEnd - CurPtr).startswith(ExtraTermination)) {
1804+
if (StringRef(CurPtr, BufferEnd - CurPtr).startswith(ExtraTermination) &&
1805+
(!DelimiterLength || *(CurPtr + ExtraTermination.size()) != '#')) {
18041806
TokStart -= DelimiterLength;
18051807
CurPtr += ExtraTermination.size();
18061808
if (wasErroneous)

test/Parse/raw_string.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ _ = ##"""
4949
"""##
5050
// CHECK: "print(\"\"\"\n Five\n\n\nEpsilon\n \"\"\")"
5151

52+
_ = #" "##" "#
53+
// CHECK: " \"##\" "
54+
55+
_ = #" \#(#" "######" "#) "#
56+
// CHECK: " \"######\" "
57+
58+
_ = #" \#(##"###""###"##) "#
59+
// CHECK: "###\"\"###"
60+
5261
// ===---------- Single line --------===
5362

5463
_ = #""Zeta""#

test/Parse/raw_string_errors.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
#"\##("invalid")"#
4+
// expected-error@-1{{Too many # characters in delimited escape}}
5+
6+
####"invalid"###
7+
// expected-error@-1{{unterminated string literal}}
8+
9+
###"invalid"####
10+
// expected-error@-1{{unterminated string literal}}

0 commit comments

Comments
 (0)