Skip to content

Commit 4209b72

Browse files
committed
Delimiter specific diagnostic
1 parent 6bd7cb8 commit 4209b72

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ ERROR(lex_invalid_u_escape,none,
138138
"\\u{...} escape sequence expects between 1 and 8 hex digits", ())
139139
ERROR(lex_invalid_u_escape_rbrace,none,
140140
"expected '}' in \\u{...} escape sequence", ())
141+
ERROR(lex_invalid_delimiter_escape,none,
142+
"Too many # characters in delimited escape", ())
141143

142144
ERROR(lex_invalid_unicode_scalar,none,
143145
"invalid unicode scalar", ())

lib/Parse/Lexer.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,18 @@ unsigned Lexer::lexCharacter(const char *&CurPtr, char StopQuote,
13031303
unsigned CharValue = 0;
13041304
// Escape processing. We already ate the "\".
13051305
switch (*CurPtr) {
1306-
case ' ': case '\t': case '\n': case '\r':
1307-
if (MultilineString && maybeConsumeNewlineEscape(CurPtr, 0))
1306+
case ' ': case '\t': case '\n': case '\r': case '#':
1307+
if (*CurPtr == '#') {
1308+
if (DelimiterLength) {
1309+
if (EmitDiagnostics)
1310+
diagnose(CurPtr, diag::lex_invalid_delimiter_escape)
1311+
.fixItRemoveChars(Lexer::getSourceLoc(CurPtr),
1312+
Lexer::getSourceLoc(CurPtr + 1));
1313+
CurPtr++;
1314+
return ~1U;
1315+
}
1316+
}
1317+
else if (MultilineString && maybeConsumeNewlineEscape(CurPtr, 0))
13081318
return '\n';
13091319
LLVM_FALLTHROUGH;
13101320
default: // Invalid escape.

0 commit comments

Comments
 (0)